Oauth2 provider and initial api
This commit is contained in:
@@ -2,9 +2,10 @@ from django.conf import settings
|
||||
from django.conf.urls import url, include
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from models import Workout
|
||||
from models import Workout,Rower
|
||||
|
||||
from rest_framework import routers, serializers, viewsets
|
||||
from rest_framework import routers, serializers, viewsets,permissions
|
||||
from rest_framework.urlpatterns import format_suffix_patterns
|
||||
|
||||
from . import views
|
||||
from django.contrib.auth import views as auth_views
|
||||
@@ -13,45 +14,18 @@ from django.conf.urls import (
|
||||
handler400, handler403, handler404, handler500,
|
||||
)
|
||||
|
||||
# Serializers define the API representation.
|
||||
class UserSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ('url', 'username', 'email', 'is_staff')
|
||||
|
||||
class WorkoutSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Workout
|
||||
fields = (
|
||||
'name',
|
||||
'date',
|
||||
'workouttype',
|
||||
'boattype',
|
||||
'starttime',
|
||||
'startdatetime',
|
||||
'distance',
|
||||
'duration',
|
||||
'weightcategory',
|
||||
'weightvalue',
|
||||
'averagehr',
|
||||
'maxhr',
|
||||
'notes',
|
||||
'summary',
|
||||
)
|
||||
from rowers.permissions import IsOwnerOrNot
|
||||
from rowers.serializers import WorkoutSerializer
|
||||
|
||||
# ViewSets define the view behavior.
|
||||
class UserViewSet(viewsets.ModelViewSet):
|
||||
queryset = User.objects.all()
|
||||
serializer_class = UserSerializer
|
||||
|
||||
class WorkoutViewSet(viewsets.ModelViewSet):
|
||||
queryset = Workout.objects.all()
|
||||
queryset = Workout.objects.all().order_by("-date", "-starttime")
|
||||
serializer_class = WorkoutSerializer
|
||||
permission_classes = (IsOwnerOrNot,)
|
||||
|
||||
|
||||
# Routers provide an easy way of automatically determining the URL conf.
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'users', UserViewSet)
|
||||
router.register(r'workouts',WorkoutViewSet)
|
||||
router.register(r'api/workouts',WorkoutViewSet)
|
||||
|
||||
handler500 = 'views.error500_view'
|
||||
handler404 = 'views.error404_view'
|
||||
@@ -61,7 +35,7 @@ handler403 = 'views.error403_view'
|
||||
urlpatterns = [
|
||||
# url(r'^password_change/$',auth_views.password_change),
|
||||
# url(r'^password_change_done/$',auth_views.password_change_done),
|
||||
url(r'^oauth2/', include('provider.oauth2.urls', namespace = 'oauth2')),
|
||||
url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
|
||||
url(r'^', include(router.urls)),
|
||||
url(r'^api-docs$', views.schema_view),
|
||||
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
|
||||
@@ -190,3 +164,5 @@ if settings.DEBUG:
|
||||
url(r'^testreverse/$',views.test_reverse_view),
|
||||
url(r'^c2listug/$',views.c2listdebug_view),
|
||||
]
|
||||
|
||||
#urlpatterns = format_suffix_patterns(urlpatterns)
|
||||
|
||||
Reference in New Issue
Block a user