Private
Public Access
1
0

Initial playing around

This commit is contained in:
Sander Roosendaal
2016-11-19 10:44:59 +01:00
parent 8f6dc13d9f
commit c6726245c2
3 changed files with 64 additions and 1 deletions

View File

@@ -1,5 +1,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 rest_framework import routers, serializers, viewsets
from . import views
from django.contrib.auth import views as auth_views
@@ -8,6 +13,46 @@ 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',
)
# ViewSets define the view behavior.
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
class WorkoutViewSet(viewsets.ModelViewSet):
queryset = Workout.objects.all()
serializer_class = WorkoutSerializer
# Routers provide an easy way of automatically determining the URL conf.
router = routers.DefaultRouter()
router.register(r'users', UserViewSet)
router.register(r'workouts',WorkoutViewSet)
handler500 = 'views.error500_view'
handler404 = 'views.error404_view'
handler400 = 'views.error400_view'
@@ -16,6 +61,8 @@ 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'^', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^testbokeh$',views.testbokeh),
url(r'^500/$', TemplateView.as_view(template_name='500.html'),name='500'),
url(r'^404/$', TemplateView.as_view(template_name='404.html'),name='404'),

View File

@@ -47,6 +47,9 @@ INSTALLED_APPS = [
'translation_manager',
'debug_toolbar',
'django_mailbox',
'rest_framework',
'provider',
'provider.oauth2',
]
MIDDLEWARE_CLASSES = [
@@ -230,5 +233,17 @@ EMAIL_USE_TLS = True
FORECAST_IO_KEY = "bc8196fbd89f11375c7dfc8aa6323c72"
GMAPIKEY = "AIzaSyAgu1w9QSthaGPMLp8y9JedPoMc9sfEgJ8"
# test
# REST Framework
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
],
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.OAuth2Authentication',
),
}

View File

@@ -26,6 +26,7 @@ from rowers import views as rowersviews
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
# url('^', include('django.contrib.auth.urls')),
url(r'^$',rootview),
url(r'^version/$',version),