Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Remove tastypie and associated files

Roland53ce1052a9f5
diff --git a/requirements.txt b/requirements.txt
index b739a5fe3..3f7f9087a 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -38,7 +38,6 @@ sphinx
# REST API
django-cors-headers>=3.0
django-filter==2.1.0
-django-tastypie~=0.14
djangorestframework~=3.11
diff --git a/wger/core/api/resources.py b/wger/core/api/resources.py
deleted file mode 100644
index 3553121f1..000000000
--- a/wger/core/api/resources.py
+++ /dev/null
@@ -1,81 +0,0 @@
-# -*- 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
-
-# Third Party
-from tastypie.authentication import ApiKeyAuthentication
-from tastypie.constants import ALL
-from tastypie.resources import ModelResource
-
-# wger
-from wger.core.models import (
- DaysOfWeek,
- Language,
- License,
- UserProfile
-)
-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}
-
-
-class DaysOfWeekResource(ModelResource):
- '''
- Resource for days of the week
- '''
-
- class Meta:
- queryset = DaysOfWeek.objects.all()
- filtering = {'id': ALL,
- 'day_of_week': ALL}
-
-
-class LicenseResource(ModelResource):
- '''
- Resource for licenses
- '''
- class Meta:
- queryset = License.objects.all()
- filtering = {'id': ALL,
- "full_name": ALL,
- "short_name": ALL,
- "url": ALL}
diff --git a/wger/exercises/api/resources.py b/wger/exercises/api/resources.py
deleted file mode 100644
index 27e41283c..000000000
--- a/wger/exercises/api/resources.py
+++ /dev/null
@@ -1,132 +0,0 @@
-# -*- 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
-
-# Third Party
-from easy_thumbnails.alias import aliases
-from easy_thumbnails.files import get_thumbnailer
-from tastypie import fields
-from tastypie.constants import (
- ALL,
- ALL_WITH_RELATIONS
-)
-from tastypie.resources import ModelResource
-
-# wger
-from wger.core.api.resources import (
- LanguageResource,
- LicenseResource
-)
-from wger.exercises.models import (
- Equipment,
- Exercise,
- ExerciseCategory,
- ExerciseComment,
- ExerciseImage,
- Muscle
-)
-
-
-class ExerciseResource(ModelResource):
- category = fields.ToOneField('wger.exercises.api.resources.ExerciseCategoryResource',
- 'category')
- muscles = fields.ToManyField('wger.exercises.api.resources.MuscleResource', 'muscles')
- muscles_secondary = fields.ToManyField('wger.exercises.api.resources.MuscleResource',
- 'muscles_secondary')
- comments = fields.ToManyField('wger.exercises.api.resources.ExerciseCommentResource',
- 'exercisecomment_set')
- images = fields.ToManyField('wger.exercises.api.resources.ExerciseImageResource',
- 'exerciseimage_set')
- equipment = fields.ToManyField('wger.exercises.api.resources.EquipmentResource',
- 'equipment')
- language = fields.ToOneField(LanguageResource, 'language')
- license = fields.ToOneField(LicenseResource, 'license')
-
- creation_date = fields.DateField(attribute='creation_date', null=True)
-
- class Meta:
- queryset = Exercise.objects.all()
- filtering = {'id': ALL,
- "uuid": ALL,
- "category": ALL_WITH_RELATIONS,
- "creation_date": ALL,
- "description": ALL,
- "images": ALL_WITH_RELATIONS,
- "language": ALL_WITH_RELATIONS,
- "muscles": ALL_WITH_RELATIONS,
- "status": ALL,
- "name": ALL,
- "license": ALL,
- "license_author": ALL}
-
-
-class EquipmentResource(ModelResource):
-
- class Meta:
- queryset = Equipment.objects.all()
- filtering = {'id': ALL,
- "name": ALL}
-
-
-class ExerciseCategoryResource(ModelResource):
-
- class Meta:
- queryset = ExerciseCategory.objects.all()
- filtering = {'id': ALL,
- "name": ALL}
-
-
-class ExerciseImageResource(ModelResource):
- exercise = fields.ToOneField('wger.exercises.api.resources.ExerciseResource', 'exercise')
- license = fields.ToOneField(LicenseResource, 'license')
-
- class Meta:
- queryset = ExerciseImage.objects.all()
- filtering = {'id': ALL,
- "image": ALL,
- "is_main": ALL,
- "license": ALL,
- "license_author": ALL}
-
- def dehydrate(self, bundle):
- '''
- Also send the URLs for the thumbnailed pictures
- '''
- thumbnails = {}
- for alias in aliases.all():
- t = get_thumbnailer(bundle.obj.image)
- thumbnails[alias] = {'url': t.get_thumbnail(aliases.get(alias)).url,
- 'settings': aliases.get(alias)}
-
- bundle.data['thumbnails'] = thumbnails
- return bundle
-
-
-class ExerciseCommentResource(ModelResource):
- exercise = fields.ToOneField('wger.exercises.api.resources.ExerciseResource', 'exercise')
-
- class Meta:
- queryset = ExerciseComment.objects.all()
- filtering = {'id': ALL,
- "comment": ALL,
- "exercise": ALL_WITH_RELATIONS}
-
-
-class MuscleResource(ModelResource):
- class Meta:
- queryset = Muscle.objects.all()
- filtering = {'id': ALL,
- "name": ALL,
- "is_front": ALL}
diff --git a/wger/manager/api/resources.py b/wger/manager/api/resources.py
deleted file mode 100644
index d3336a9f0..000000000
--- a/wger/manager/api/resources.py
+++ /dev/null
@@ -1,232 +0,0 @@
-# -*- 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
-
-# Third Party
-from tastypie import fields
-from tastypie.authentication import (
- ApiKeyAuthentication,
- MultiAuthentication,
- SessionAuthentication
-)
-from tastypie.constants import (
- ALL,
- ALL_WITH_RELATIONS
-)
-from tastypie.resources import ModelResource
-
-# wger
-from wger.core.api.resources import DaysOfWeekResource
-from wger.exercises.api.resources import ExerciseResource
-from wger.manager.models import (
- Day,
- Schedule,
- ScheduleStep,
- Set,
- Setting,
- Workout,
- WorkoutLog,
- WorkoutSession
-)
-from wger.utils.resources import UserObjectsOnlyAuthorization
-
-
-class WorkoutResource(ModelResource):
- '''
- Resource for workouts
- '''
-
- days = fields.ToManyField('wger.manager.api.resources.DayResource', 'day_set')
-
- def authorized_read_list(self, object_list, bundle):
- '''
- Filter to own objects
- '''
- return object_list.filter(user=bundle.request.user)
-
- class Meta:
- queryset = Workout.objects.all()
- authentication = ApiKeyAuthentication()
- authorization = UserObjectsOnlyAuthorization()
- filtering = {'id': ALL,
- "comment": ALL,
- "creation_date": ALL}
-
-
-class WorkoutSessionResource(ModelResource):
- '''
- Resource for workout sessions
- '''
-
- workout = fields.ToOneField('wger.manager.api.resources.WorkoutResource', 'workout')
-
- def authorized_read_list(self, object_list, bundle):
- '''
- Filter to own objects
- '''
- return object_list.filter(user=bundle.request.user)
-
- class Meta:
- queryset = WorkoutSession.objects.all()
- authentication = MultiAuthentication(SessionAuthentication(), ApiKeyAuthentication())
- authorization = UserObjectsOnlyAuthorization()
- filtering = {'id': ALL,
- "date": ALL,
- "time_start": ALL,
- "time_end": ALL}
-
-
-class ScheduleStepResource(ModelResource):
- '''
- Resource for schedule steps
- '''
-
- workout = fields.ToOneField(WorkoutResource, 'workout')
- schedule = fields.ToOneField('wger.manager.api.resources.ScheduleResource', 'schedule')
-
- def authorized_read_list(self, object_list, bundle):
- '''
- Filter to own objects
- '''
- return object_list.filter(schedule__user=bundle.request.user)
-
- class Meta:
- queryset = ScheduleStep.objects.all()
- authentication = ApiKeyAuthentication()
- authorization = UserObjectsOnlyAuthorization()
- filtering = {'id': ALL,
- 'schedule': ALL_WITH_RELATIONS,
- 'workout': ALL_WITH_RELATIONS}
-
-
-class ScheduleResource(ModelResource):
- '''
- Resource for schedules
- '''
-
- steps = fields.ToManyField(ScheduleStepResource, 'schedulestep_set')
-
- def authorized_read_list(self, object_list, bundle):
- '''
- Filter to own objects
- '''
- return object_list.filter(user=bundle.request.user)
-
- class Meta:
- queryset = Schedule.objects.all()
- authentication = ApiKeyAuthentication()
- authorization = UserObjectsOnlyAuthorization()
- filtering = {'id': ALL,
- 'is_active': ALL,
- 'is_loop': ALL,
- 'name': ALL}
-
-
-class DayResource(ModelResource):
- '''
- Resource for training days
- '''
-
- workout = fields.ToOneField(WorkoutResource, 'training')
- days_of_week = fields.ToManyField(DaysOfWeekResource, 'day')
-
- def authorized_read_list(self, object_list, bundle):
- '''
- Filter to own objects
- '''
- return object_list.filter(training__user=bundle.request.user)
-
- class Meta:
- queryset = Day.objects.all()
- authentication = ApiKeyAuthentication()
- authorization = UserObjectsOnlyAuthorization()
- filtering = {'id': ALL,
- 'description': ALL,
- 'workout': ALL_WITH_RELATIONS}
-
-
-class SetResource(ModelResource):
- '''
- Resource for training sets
- '''
-
- day = fields.ToOneField(DayResource, 'exerciseday')
- exercises = fields.ToManyField(ExerciseResource, 'exercises')
-
- def authorized_read_list(self, object_list, bundle):
- '''
- Filter to own objects
- '''
- return object_list.filter(exerciseday__training__user=bundle.request.user)
-
- class Meta:
- queryset = Set.objects.all()
- authentication = ApiKeyAuthentication()
- authorization = UserObjectsOnlyAuthorization()
- filtering = {'id': ALL,
- 'day': ALL_WITH_RELATIONS,
- 'order': ALL,
- 'sets': ALL}
-
-
-class SettingResource(ModelResource):
- '''
- Resource for training settings
- '''
-
- set = fields.ToOneField(SetResource, 'set')
- exercise = fields.ToOneField(ExerciseResource, 'exercise')
-
- def authorized_read_list(self, object_list, bundle):
- '''
- Filter to own objects
- '''
- return object_list.filter(set__exerciseday__training__user=bundle.request.user)
-
- class Meta:
- queryset = Setting.objects.all()
- authentication = ApiKeyAuthentication()
- authorization = UserObjectsOnlyAuthorization()
- filtering = {'id': ALL,
- 'exercise': ALL_WITH_RELATIONS,
- 'order': ALL,
- 'reps': ALL,
- 'set': ALL_WITH_RELATIONS}
-
-
-class WorkoutLogResource(ModelResource):
- '''
- Resource for a workout log
- '''
-
- exercise = fields.ToOneField(ExerciseResource, 'exercise')
- workout = fields.ToOneField(WorkoutResource, 'workout')
-
- def authorized_read_list(self, object_list, bundle):
- '''
- Filter to own objects
- '''
- return object_list.filter(user=bundle.request.user)
-
- class Meta:
- queryset = WorkoutLog.objects.all()
- authentication = ApiKeyAuthentication()
- authorization = UserObjectsOnlyAuthorization()
- filtering = {'id': ALL,
- 'date': ALL,
- 'exercise': ALL_WITH_RELATIONS,
- 'reps': ALL,
- 'weight': ALL,
- 'workout': ALL_WITH_RELATIONS}
diff --git a/wger/nutrition/api/resources.py b/wger/nutrition/api/resources.py
deleted file mode 100644
index 21af0326a..000000000
--- a/wger/nutrition/api/resources.py
+++ /dev/null
@@ -1,180 +0,0 @@
-# -*- 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
-
-# Third Party
-from tastypie import fields
-from tastypie.authentication import ApiKeyAuthentication
-from tastypie.constants import (
- ALL,
- ALL_WITH_RELATIONS
-)
-from tastypie.resources import ModelResource
-
-# wger
-from wger.core.api.resources import (
- LanguageResource,
- LicenseResource
-)
-from wger.nutrition.models import (
- Ingredient,
- IngredientWeightUnit,
- Meal,
- MealItem,
- NutritionPlan,
- WeightUnit
-)
-from wger.utils.resources import UserObjectsOnlyAuthorization
-
-
-class IngredientResource(ModelResource):
-
- language = fields.ToOneField(LanguageResource, 'language')
- license = fields.ToOneField(LicenseResource, 'license')
-
- class Meta:
- queryset = Ingredient.objects.all()
- filtering = {'id': ALL,
- 'carbohydrates': ALL,
- 'carbohydrates_sugar': ALL,
- 'creation_date': ALL,
- 'energy': ALL,
- 'fat': ALL,
- 'fat_saturated': ALL,
- 'fibres': ALL,
- 'name': ALL,
- 'protein': ALL,
- 'sodium': ALL,
- 'status': ALL,
- 'update_date': ALL,
- 'language': ALL,
- 'license': ALL,
- 'license_author': ALL}
-
-
-class WeightUnitResource(ModelResource):
- class Meta:
- queryset = WeightUnit.objects.all()
- filtering = {'id': ALL,
- 'name': ALL}
-
-
-class IngredientToWeightUnit(ModelResource):
-
- ingredient = fields.ToOneField(IngredientResource, 'ingredient')
- unit = fields.ToOneField(WeightUnitResource, 'unit')
-
- class Meta:
- queryset = IngredientWeightUnit.objects.all()
- filtering = {'id': ALL,
- 'amount': ALL,
- 'gram': ALL,
- 'ingredient': ALL_WITH_RELATIONS,
- 'unit': ALL_WITH_RELATIONS}
-
-
-class NutritionPlanResource(ModelResource):
- '''
- Resource for nutritional plans
- '''
-
- meals = fields.ToManyField('wger.nutrition.api.resources.MealResource', 'meal_set')
-
- def authorized_read_list(self, object_list, bundle):
- '''
- Filter to own objects
- '''
- return object_list.filter(user=bundle.request.user)
-
- def dehydrate(self, bundle):
- '''
- Also send the nutritional values
- '''
- bundle.data['nutritional_values'] = bundle.obj.get_nutritional_values()
- return bundle
-
- class Meta:
- queryset = NutritionPlan.objects.all()
- authentication = ApiKeyAuthentication()
- authorization = UserObjectsOnlyAuthorization()
- filtering = {'id': ALL,
- 'creation_date': ALL,
- 'description': ALL,
- 'has_goal_calories': ALL}
-
-
-class MealResource(ModelResource):
- '''
- Resource for meals
- '''
-
- plan = fields.ToOneField(NutritionPlanResource, 'plan')
- meal_items = fields.ToManyField('wger.nutrition.api.resources.MealItemResource', 'mealitem_set')
-
- def authorized_read_list(self, object_list, bundle):
- '''
- Filter to own objects
- '''
- return object_list.filter(plan__user=bundle.request.user)
-
- def dehydrate(self, bundle):
- '''
- Also send the nutritional values
- '''
- bundle.data['nutritional_values'] = bundle.obj.get_nutritional_values()
- return bundle
-
- class Meta:
- queryset = Meal.objects.all()
- authentication = ApiKeyAuthentication()
- authorization = UserObjectsOnlyAuthorization()
- filtering = {'id': ALL,
- 'order': ALL,
- 'plan': ALL_WITH_RELATIONS,
- 'time': ALL}
-
-
-class MealItemResource(ModelResource):
- '''
- Resource for meal items
- '''
-
- meal = fields.ToOneField(MealResource, 'meal')
- ingredient = fields.ToOneField(IngredientResource, 'ingredient')
- weight_unit = fields.ToOneField(WeightUnitResource, 'weight_unit', null=True)
-
- def authorized_read_list(self, object_list, bundle):
- '''
- Filter to own objects
- '''
- return object_list.filter(meal__plan__user=bundle.request.user)
-
- def dehydrate(self, bundle):
- '''
- Also send the nutritional values
- '''
- bundle.data['nutritional_values'] = bundle.obj.get_nutritional_values()
- return bundle
-
- class Meta:
- queryset = MealItem.objects.all()
- authentication = ApiKeyAuthentication()
- authorization = UserObjectsOnlyAuthorization()
- filtering = {'id': ALL,
- 'amount': ALL,
- 'ingredient': ALL_WITH_RELATIONS,
- 'meal': ALL_WITH_RELATIONS,
- 'order': ALL,
- 'weight_unit': ALL_WITH_RELATIONS}
diff --git a/wger/settings_global.py b/wger/settings_global.py
index b0a604cbb..7de482fc5 100644
--- a/wger/settings_global.py
+++ b/wger/settings_global.py
@@ -78,7 +78,6 @@ INSTALLED_APPS = (
'crispy_forms',
# REST-API
- 'tastypie',
'rest_framework',
'rest_framework.authtoken',
'django_filters',
diff --git a/wger/software/templates/api.html b/wger/software/templates/api.html
index 2839b6fcc..b8db6c9a2 100644
--- a/wger/software/templates/api.html
+++ b/wger/software/templates/api.html
@@ -376,21 +376,6 @@ curl -H "Authorization: Token 123456..." \
>>> pprint(json.loads(r.content))
</pre>
-
-<h3>/api/v1</h3>
-<div class="panel panel-warning">
- <div class="panel-heading">
- <h3 class="panel-title">Deprecation warning</h3>
- </div>
- <div class="panel-body">
- The first API supported only read operations. Due to different reasons
- it is being deprecated and should not be used anymore, it will be
- deactivated on June 2015.
- </div>
-</div>
-<p>
-</p>
-
{% endblock %}
diff --git a/wger/urls.py b/wger/urls.py
index 4667b5a83..a430b8fee 100644
--- a/wger/urls.py
+++ b/wger/urls.py
@@ -28,24 +28,19 @@ from django.contrib.sitemaps.views import sitemap
# Third Party
from rest_framework import routers
-from tastypie.api import Api
# wger
from wger.core.api import (
- resources as core_api,
views as core_api_views
)
from wger.exercises.api import (
- resources as exercises_api,
views as exercises_api_views
)
from wger.exercises.sitemap import ExercisesSitemap
from wger.manager.api import (
- resources as manager_api,
views as manager_api_views
)
from wger.nutrition.api import (
- resources as nutrition_api,
views as nutrition_api_views
)
from wger.nutrition.sitemap import NutritionSitemap
@@ -54,7 +49,6 @@ from wger.utils.generic_views import (
WebappManifestView
)
from wger.weight.api import (
- resources as weight_api,
views as weight_api_views
)
@@ -65,44 +59,12 @@ from wger.weight.api import (
#
# REST API
#
-
-# /api/v1 - tastypie - deprecated
-v1_api = Api(api_name='v1')
-
-v1_api.register(exercises_api.ExerciseCategoryResource())
-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.EquipmentResource())
-
-v1_api.register(nutrition_api.IngredientResource())
-v1_api.register(nutrition_api.WeightUnitResource())
-v1_api.register(nutrition_api.NutritionPlanResource())
-v1_api.register(nutrition_api.MealResource())
-v1_api.register(nutrition_api.MealItemResource())
-v1_api.register(nutrition_api.IngredientToWeightUnit())
-
-v1_api.register(manager_api.WorkoutResource())
-v1_api.register(manager_api.ScheduleResource())
-v1_api.register(manager_api.ScheduleStepResource())
-v1_api.register(manager_api.DayResource())
-v1_api.register(manager_api.SetResource())
-v1_api.register(manager_api.SettingResource())
-v1_api.register(manager_api.WorkoutLogResource())
-v1_api.register(manager_api.WorkoutSessionResource())
-
-v1_api.register(weight_api.WeightEntryResource())
-
-v1_api.register(core_api.LanguageResource())
-v1_api.register(core_api.DaysOfWeekResource())
-v1_api.register(core_api.UserProfileResource())
-v1_api.register(core_api.LicenseResource())
-
-
-# /api/v2 - django rest framework
router = routers.DefaultRouter()
+#
+# Application
+#
+
# Manager app
router.register(r'workout', manager_api_views.WorkoutViewSet, basename='workout')
router.register(r'workoutsession', manager_api_views.WorkoutSessionViewSet, basename='workoutsession')
@@ -179,7 +141,6 @@ urlpatterns += [
url(r'^amazon-manifest\.webapp$', WebappManifestView.as_view(template_name="amazon-manifest.webapp")),
# API
- url(r'^api/', include(v1_api.urls)),
url(r'^api/v2/exercise/search/$',
exercises_api_views.search,
name='exercise-search'),
diff --git a/wger/utils/resources.py b/wger/utils/resources.py
deleted file mode 100644
index 607677ae9..000000000
--- a/wger/utils/resources.py
+++ /dev/null
@@ -1,40 +0,0 @@
-# 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
-
-# Standard Library
-import logging
-
-# Third Party
-from tastypie.authorization import ReadOnlyAuthorization
-
-
-logger = logging.getLogger(__name__)
-
-
-class UserObjectsOnlyAuthorization(ReadOnlyAuthorization):
- '''
- Custom authorization class to limit the user's access to his own objects
- '''
-
- def read_detail(self, object_list, bundle):
-
- # For models such as userprofile where we don't have an owner function
- if hasattr(bundle.obj, 'user'):
- return bundle.obj.user == bundle.request.user
-
- try:
- return bundle.obj.get_owner_object().user == bundle.request.user
- # Objects without owner information can be accessed
- except AttributeError:
- return True
diff --git a/wger/weight/api/resources.py b/wger/weight/api/resources.py
deleted file mode 100644
index 836c3cea6..000000000
--- a/wger/weight/api/resources.py
+++ /dev/null
@@ -1,44 +0,0 @@
-# -*- 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
-
-# Third Party
-from tastypie.authentication import ApiKeyAuthentication
-from tastypie.constants import ALL
-from tastypie.resources import ModelResource
-
-# wger
-from wger.utils.resources import UserObjectsOnlyAuthorization
-from wger.weight.models import WeightEntry
-
-
-class WeightEntryResource(ModelResource):
- '''
- Resource for weight entries
- '''
-
- def authorized_read_list(self, object_list, bundle):
- '''
- Filter to own objects
- '''
- return object_list.filter(user=bundle.request.user)
-
- class Meta:
- queryset = WeightEntry.objects.all()
- authentication = ApiKeyAuthentication()
- authorization = UserObjectsOnlyAuthorization()
- filtering = {'id': ALL,
- 'date': ALL,
- 'weight': ALL}