Commit be7810aad94925b3229db6ffa70e1b2c6e759c59
1 parent
8fa22f31e3
Exists in
master
working on adding a class to a user
Showing 4 changed files with 18 additions and 12 deletions Side-by-side Diff
flashcards/models.py
View file @
be7810a
flashcards/views.py
View file @
be7810a
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | from flashcards.serializers import SectionSerializer, UserUpdateSerializer, RegistrationSerializer, UserSerializer, \ |
4 | 4 | PasswordResetSerializer, PasswordResetRequestSerializer, EmailPasswordSerializer |
5 | 5 | from rest_framework.permissions import IsAuthenticated |
6 | -from rest_framework.viewsets import ReadOnlyModelViewSet | |
6 | +from rest_framework.viewsets import ReadOnlyModelViewSet, ModelViewSet | |
7 | 7 | from django.core.mail import send_mail |
8 | 8 | from django.contrib.auth import authenticate, login, logout |
9 | 9 | from django.contrib.auth.tokens import default_token_generator |
10 | 10 | |
11 | 11 | |
... | ... | @@ -12,19 +12,20 @@ |
12 | 12 | from rest_framework.response import Response |
13 | 13 | from rest_framework.exceptions import AuthenticationFailed, NotAuthenticated, ValidationError |
14 | 14 | from simple_email_confirmation import EmailAddress |
15 | +from rest_framework import filters | |
15 | 16 | |
16 | - | |
17 | 17 | class SectionViewSet(ReadOnlyModelViewSet): |
18 | 18 | queryset = Section.objects.all() |
19 | 19 | serializer_class = SectionSerializer |
20 | 20 | pagination_class = StandardResultsSetPagination |
21 | 21 | |
22 | 22 | class UserSectionViewSet(ModelViewSet): |
23 | - def list(self, request, format=None): | |
24 | - queryset = User.sections.all() | |
25 | - serializer_class = SectionSerializer | |
26 | - return Response(serializer.data) | |
27 | - def get_queryset( | |
23 | + serializer_class = SectionSerializer | |
24 | + permission_classes = [IsAuthenticated] | |
25 | + def get_queryset(self): | |
26 | + return self.request.user.sections.all() | |
27 | + | |
28 | + def paginate_queryset(self, queryset): return None | |
28 | 29 | |
29 | 30 | class UserDetail(APIView): |
30 | 31 | def patch(self, request, format=None): |
flashy/settings.py
View file @
be7810a
... | ... | @@ -10,7 +10,9 @@ |
10 | 10 | ALLOWED_HOSTS = ['127.0.0.1', 'flashy.cards'] |
11 | 11 | |
12 | 12 | AUTH_USER_MODEL = 'flashcards.User' |
13 | - | |
13 | +REST_FRAMEWORK = { | |
14 | + 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination' | |
15 | +} | |
14 | 16 | INSTALLED_APPS = ( |
15 | 17 | 'simple_email_confirmation', |
16 | 18 | 'flashcards', |
flashy/urls.py
View file @
be7810a
1 | 1 | from django.conf.urls import include, url |
2 | 2 | from django.contrib import admin |
3 | -from flashcards.views import SectionViewSet, UserDetail, UserLogin, UserLogout, PasswordReset | |
3 | +from flashcards.views import SectionViewSet, UserDetail, UserLogin, UserLogout, PasswordReset, UserSectionViewSet | |
4 | 4 | from rest_framework.routers import DefaultRouter |
5 | 5 | from flashcards.api import * |
6 | 6 | |
7 | 7 | router = DefaultRouter() |
8 | 8 | router.register(r'sections', SectionViewSet) |
9 | 9 | |
10 | +router.register(r'users/me/sections', UserSectionViewSet, base_name = 'usersection') | |
11 | + | |
10 | 12 | urlpatterns = [ |
11 | 13 | url(r'^api/docs/', include('rest_framework_swagger.urls')), |
12 | 14 | url(r'^api/users/me$', UserDetail.as_view()), |
... | ... | @@ -16,7 +18,8 @@ |
16 | 18 | url(r'^api/', include(router.urls)), |
17 | 19 | url(r'^admin/doc/', include('django.contrib.admindocs.urls')), |
18 | 20 | url(r'^admin/', include(admin.site.urls)), |
19 | - url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) | |
21 | + url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework' | |
22 | +)) | |
20 | 23 | ] |
21 | 24 | |
22 | 25 | urlpatterns += (url(r'^admin/django-ses/', include('django_ses.urls')),) |