Self hosted FLOSS fitness/workout, nutrition and weight tracker
Move REST API resources to core app
Roland Geider7538af1914df
diff --git a/wger/core/api/__init__.py b/wger/core/api/__init__.pynew file mode 100644index 000000000..6682a6736--- /dev/null+++ b/wger/core/api/__init__.py@@ -0,0 +1 @@+__author__ = 'ogre'diff --git a/wger/core/api/resources.py b/wger/core/api/resources.pynew file mode 100644index 000000000..6c66845d6--- /dev/null+++ b/wger/core/api/resources.py@@ -0,0 +1,51 @@+# -*- coding: utf-8 -*-++# This file is part of wger Workout Manager.+#+# wger Workout Manager is free software: you can redistribute it and/or modify+# it under the terms of the GNU Affero General Public License as published by+# the Free Software Foundation, either version 3 of the License, or+# (at your option) any later version.+#+# wger Workout Manager is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU Affero General Public License++from tastypie.authentication import ApiKeyAuthentication+from tastypie.constants import ALL+from tastypie.resources import ModelResource++from wger.core.models import UserProfile, Language+from wger.utils.resources import UserObjectsOnlyAuthorization+++class UserProfileResource(ModelResource):+ '''+ Resource for user profiles+ '''++ def authorized_read_list(self, object_list, bundle):+ '''+ Filter to own objects+ '''+ return object_list.filter(user=bundle.request.user)++ class Meta:+ excludes = ('is_temporary', )+ queryset = UserProfile.objects.all()+ authentication = ApiKeyAuthentication()+ authorization = UserObjectsOnlyAuthorization()+++class LanguageResource(ModelResource):+ '''+ Resource for languages+ '''+ class Meta:+ queryset = Language.objects.all()+ filtering = {'id': ALL,+ "full_name": ALL,+ "short_name": ALL}diff --git a/wger/exercises/api/resources.py b/wger/exercises/api/resources.pyindex 2d2ab7f01..d7b780c17 100644--- a/wger/exercises/api/resources.py+++ b/wger/exercises/api/resources.py@@ -17,10 +17,8 @@from tastypie import fieldsfrom tastypie.resources import ModelResourcefrom tastypie.constants import ALL, ALL_WITH_RELATIONS-from easy_thumbnails.alias import aliasesfrom easy_thumbnails.files import get_thumbnailer-from wger.core.models import Languagefrom wger.exercises.models import Exercisefrom wger.exercises.models import ExerciseCategory@@ -115,11 +113,3 @@ class MuscleResource(ModelResource):filtering = {'id': ALL,"name": ALL,"is_front": ALL}---class LanguageResource(ModelResource):- class Meta:- queryset = Language.objects.all()- filtering = {'id': ALL,- "full_name": ALL,- "short_name": ALL}diff --git a/wger/manager/api/resources.py b/wger/manager/api/resources.pyindex c55435b27..faf52983d 100644--- a/wger/manager/api/resources.py+++ b/wger/manager/api/resources.py@@ -20,11 +20,9 @@ from tastypie.authentication import MultiAuthenticationfrom tastypie.authentication import SessionAuthenticationfrom tastypie.resources import ModelResourcefrom tastypie.constants import ALL, ALL_WITH_RELATIONS-from wger.core.models import UserProfilefrom wger.exercises.api.resources import ExerciseResourcefrom wger.utils.resources import UserObjectsOnlyAuthorization-from wger.manager.models import WorkoutSessionfrom wger.manager.models import Workoutfrom wger.manager.models import Schedule@@ -36,30 +34,6 @@ from wger.manager.models import Settingfrom wger.manager.models import WorkoutLog-#-# User related resources-#-class UserProfileResource(ModelResource):- '''- Resource for user profiles- '''-- def authorized_read_list(self, object_list, bundle):- '''- Filter to own objects- '''- return object_list.filter(user=bundle.request.user)-- class Meta:- excludes = ('is_temporary', )- queryset = UserProfile.objects.all()- authentication = ApiKeyAuthentication()- authorization = UserObjectsOnlyAuthorization()---#-# Workout related resources-#class WorkoutResource(ModelResource):'''Resource for workoutsdiff --git a/wger/urls.py b/wger/urls.pyindex 0829e6b41..2287ece08 100644--- a/wger/urls.py+++ b/wger/urls.py@@ -1,6 +1,7 @@from django.conf.urls import include, urlfrom django.conf.urls.i18n import i18n_patternsfrom django.conf.urls.i18n import patterns+from wger.core.api.resources import UserProfileResource, LanguageResourcefrom wger.exercises.sitemap import ExercisesSitemapfrom wger.nutrition.sitemap import NutritionSitemap@@ -24,7 +25,7 @@ v1_api.register(exercises_api.ExerciseCommentResource())v1_api.register(exercises_api.ExerciseImageResource())v1_api.register(exercises_api.ExerciseResource())v1_api.register(exercises_api.MuscleResource())-v1_api.register(exercises_api.LanguageResource())+v1_api.register(LanguageResource())v1_api.register(exercises_api.EquipmentResource())# Nutrition app@@ -36,7 +37,7 @@ v1_api.register(nutrition_api.MealItemResource())v1_api.register(nutrition_api.IngredientToWeightUnit())# Manager app-v1_api.register(manager_api.UserProfileResource())+v1_api.register(UserProfileResource())v1_api.register(manager_api.WorkoutResource())v1_api.register(manager_api.ScheduleResource())v1_api.register(manager_api.ScheduleStepResource())