This repository has been archived by the owner on Oct 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
FoxMaSk
committed
Nov 11, 2017
1 parent
34d58c7
commit dc6c866
Showing
10 changed files
with
232 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,9 @@ | ||
# http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.{py,rst,ini}] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.py] | ||
line_length=120 | ||
known_first_party=django_th | ||
multi_line_output=3 | ||
default_section=THIRDPARTY | ||
|
||
[*.{html,css,scss,json,yml}] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[Makefile] | ||
indent_style = tab | ||
|
||
[nginx.conf] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[Dockerfile] | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from rest_framework import permissions | ||
|
||
|
||
class DjangoModelPermissions(permissions.BasePermission): | ||
|
||
perms_map = { | ||
'GET': [], | ||
'OPTIONS': [], | ||
'HEAD': [], | ||
'POST': ['orotangi.add_books', 'orotangi.add_notes'], | ||
'PUT': ['orotangi.change_books', 'orotangi.change_notes'], | ||
'PATCH': ['orotangi.change_books', 'orotangi.change_notes'], | ||
'DELETE': ['orotangi.delete_books', 'orotangi.delete_notes'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django_th.models import TriggerService, UserService | ||
from rest_framework import serializers | ||
from django.contrib.auth.models import User | ||
|
||
|
||
class UserSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = User | ||
fields = '__all__' | ||
|
||
|
||
class UserServiceSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = UserService | ||
fields = '__all__' | ||
|
||
|
||
class UserServiceDurationSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = UserService | ||
fields = ('duration', ) | ||
|
||
|
||
class TriggerServiceSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = TriggerService | ||
fields = '__all__' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.conf.urls import url, include | ||
|
||
from django_th.api.views import TriggerServiceViewSet, UserServiceViewSet | ||
from rest_framework.routers import DefaultRouter | ||
|
||
router = DefaultRouter() | ||
router.register(r'triggers', TriggerServiceViewSet) | ||
router.register(r'services', UserServiceViewSet) | ||
|
||
|
||
urlpatterns = [ | ||
url(r'^', include(router.urls)), | ||
url(r'^api-auth/', include('rest_framework.urls', | ||
namespace='rest_framework')) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from django_filters.rest_framework import DjangoFilterBackend | ||
|
||
from django_th.api.serializers import TriggerServiceSerializer, UserServiceSerializer, UserServiceDurationSerializer | ||
from django_th.api.permissions import DjangoModelPermissions | ||
from django_th.models import TriggerService, UserService | ||
|
||
from rest_framework import viewsets | ||
from rest_framework.pagination import PageNumberPagination | ||
|
||
|
||
class TriggerServiceResultsSetPagination(PageNumberPagination): | ||
page_size = 20 | ||
max_page_size = 50 | ||
|
||
|
||
class UserServiceResultsSetPagination(PageNumberPagination): | ||
page_size = 20 | ||
max_page_size = 50 | ||
|
||
|
||
class UserMixin(viewsets.GenericViewSet): | ||
|
||
def get_queryset(self): | ||
""" | ||
get the data of the current user | ||
:return: | ||
""" | ||
qs = super(UserMixin, self).get_queryset() | ||
return qs.filter(user=self.request.user) | ||
|
||
|
||
class TriggerServiceViewSet(UserMixin, viewsets.ModelViewSet): | ||
""" | ||
This viewset provides `list`, `create`, `retrieve`, `update` | ||
and `destroy` actions. | ||
""" | ||
queryset = TriggerService.objects.all() | ||
serializer_class = TriggerServiceSerializer | ||
pagination_class = TriggerServiceResultsSetPagination | ||
# filter the notes | ||
filter_backends = (DjangoFilterBackend,) | ||
permission_classes = (DjangoModelPermissions, ) | ||
|
||
def get_queryset(self): | ||
queryset = TriggerService.objects.all() | ||
|
||
return queryset | ||
|
||
|
||
class UserServiceViewSet(UserMixin, viewsets.ModelViewSet): | ||
""" | ||
This viewset provides `list`, `create`, `retrieve`, `update` | ||
and `destroy` actions. | ||
""" | ||
queryset = UserService.objects.all() | ||
serializer_class = UserServiceSerializer | ||
pagination_class = UserServiceResultsSetPagination | ||
# filter the notes | ||
filter_backends = (DjangoFilterBackend,) | ||
permission_classes = (DjangoModelPermissions, ) | ||
|
||
def get_queryset(self): | ||
queryset = UserService.objects.all() | ||
|
||
return queryset | ||
|
||
|
||
class UserServiceDurationViewSet(UserMixin, viewsets.ModelViewSet): | ||
""" | ||
This viewset provides `list`, `create`, `retrieve`, `update` | ||
and `destroy` actions. | ||
""" | ||
queryset = UserService.objects.all() | ||
serializer_class = UserServiceDurationSerializer | ||
pagination_class = UserServiceResultsSetPagination | ||
# filter the notes | ||
filter_backends = (DjangoFilterBackend,) | ||
permission_classes = (DjangoModelPermissions, ) | ||
|
||
def get_queryset(self): | ||
queryset = UserService.objects.all() | ||
|
||
return queryset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters