Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add a REST API using tastypie
Roland Geiderc15b04c79d86
diff --git a/wger/exercises/api/__init__.py b/wger/exercises/api/__init__.pynew file mode 100644index 000000000..e69de29bbdiff --git a/wger/exercises/api/resources.py b/wger/exercises/api/resources.pynew file mode 100644index 000000000..76c9ea1ca--- /dev/null+++ b/wger/exercises/api/resources.py@@ -0,0 +1,56 @@+# -*- 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 import fields+from tastypie.resources import ModelResource++from wger.exercises.models import Exercise+from wger.exercises.models import ExerciseCategory+from wger.exercises.models import ExerciseComment+from wger.exercises.models import Muscle+from wger.exercises.models import Language+++class ExerciseResource(ModelResource):+ category = fields.ToOneField('wger.exercises.api.resources.ExerciseCategoryResource', 'category')+ muscles = fields.ToManyField('wger.exercises.api.resources.MuscleResource', 'muscles')+ language = fields.ToOneField('wger.exercises.api.resources.LanguageResource', 'language')++ class Meta:+ queryset = Exercise.objects.all()+++class ExerciseCategoryResource(ModelResource):++ class Meta:+ queryset = ExerciseCategory.objects.all()+++class ExerciseCommentResource(ModelResource):+ exercise = fields.ToOneField('wger.exercises.api.resources.ExerciseResource', 'exercise')++ class Meta:+ queryset = ExerciseComment.objects.all()+++class MuscleResource(ModelResource):+ class Meta:+ queryset = Muscle.objects.all()+++class LanguageResource(ModelResource):+ class Meta:+ queryset = Language.objects.all()\ No newline at end of filediff --git a/wger/nutrition/api/__init__.py b/wger/nutrition/api/__init__.pynew file mode 100644index 000000000..e69de29bbdiff --git a/wger/nutrition/api/resources.py b/wger/nutrition/api/resources.pynew file mode 100644index 000000000..5a99f3d6f--- /dev/null+++ b/wger/nutrition/api/resources.py@@ -0,0 +1,30 @@+# -*- 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.resources import ModelResource+from wger.nutrition.models import Ingredient+from wger.nutrition.models import WeightUnit+++class IngredientResource(ModelResource):+ class Meta:+ queryset = Ingredient.objects.all()+++class WeightUnitResource(ModelResource):+ class Meta:+ queryset = WeightUnit.objects.all()\ No newline at end of filediff --git a/wger/urls.py b/wger/urls.pyindex b9dfba67f..88e58dd11 100644--- a/wger/urls.py+++ b/wger/urls.py@@ -1,13 +1,38 @@from django.conf.urls import include, urlfrom django.conf.urls.i18n import i18n_patternsfrom django.conf.urls.i18n import patterns-from django.views.generic import TemplateViewfrom wger.exercises.sitemap import ExercisesSitemapfrom wger.nutrition.sitemap import NutritionSitemapfrom wger.utils.generic_views import TextTemplateViewfrom wger.utils.generic_views import WebappManifestView+from tastypie.api import Api++from wger.exercises.api.resources import ExerciseResource+from wger.exercises.api.resources import ExerciseCategoryResource+from wger.exercises.api.resources import ExerciseCommentResource+from wger.exercises.api.resources import MuscleResource+from wger.exercises.api.resources import LanguageResource++from wger.nutrition.api.resources import IngredientResource+from wger.nutrition.api.resources import WeightUnitResource++# REST API+v1_api = Api(api_name='v1')++# Exercises app+v1_api.register(ExerciseCategoryResource())+v1_api.register(ExerciseCommentResource())+v1_api.register(ExerciseResource())+v1_api.register(MuscleResource())+v1_api.register(LanguageResource())++# Nutrition app+v1_api.register(IngredientResource())+v1_api.register(WeightUnitResource())++from django.contrib import adminadmin.autodiscover()@@ -37,4 +62,5 @@ urlpatterns = urlpatterns + patterns('',url(r'^manifest\.webapp$',WebappManifestView.as_view(template_name="manifest.webapp"),),+ (r'^api/', include(v1_api.urls)),)