diff --git a/.gitignore b/.gitignore index b33aefe..c59776c 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ # database -*.sqlite3 \ No newline at end of file +*.sqlite3 +*.png \ No newline at end of file diff --git a/migrate.sh b/migrate.sh index a7bb1ff..fef8589 100755 --- a/migrate.sh +++ b/migrate.sh @@ -1,2 +1,3 @@ python manage.py makemigrations -python manage.py migrate \ No newline at end of file +python manage.py migrate +python manage.py graph_models -a -g -o class_diagram.png \ No newline at end of file diff --git a/packages.sh b/packages.sh index 294749a..d0e3d00 100755 --- a/packages.sh +++ b/packages.sh @@ -1,7 +1,15 @@ pip install django + pip install djangorestframework pip install django-filter pip install django-rest-enumfield pip install drf_yasg + pip install pyjwt pip install markdown + +pip install django_extensions +pip install pydotplus + +# for runing generate UML: +# apt-get install graphviz \ No newline at end of file diff --git a/portfolio/__pycache__/settings.cpython-36.pyc b/portfolio/__pycache__/settings.cpython-36.pyc old mode 100755 new mode 100644 index fba4b10..622a8bf Binary files a/portfolio/__pycache__/settings.cpython-36.pyc and b/portfolio/__pycache__/settings.cpython-36.pyc differ diff --git a/portfolio/__pycache__/urls.cpython-36.pyc b/portfolio/__pycache__/urls.cpython-36.pyc index e4fa03c..481cba0 100644 Binary files a/portfolio/__pycache__/urls.cpython-36.pyc and b/portfolio/__pycache__/urls.cpython-36.pyc differ diff --git a/portfolio/account/__pycache__/views.cpython-36.pyc b/portfolio/account/__pycache__/views.cpython-36.pyc old mode 100755 new mode 100644 index 59c1b79..9337421 Binary files a/portfolio/account/__pycache__/views.cpython-36.pyc and b/portfolio/account/__pycache__/views.cpython-36.pyc differ diff --git a/portfolio/account/views.py b/portfolio/account/views.py index f7f7501..9408e87 100755 --- a/portfolio/account/views.py +++ b/portfolio/account/views.py @@ -59,7 +59,7 @@ class AccountAuth(ObtainAuthToken): serializer_class = AccountAuthSerializer @swagger_auto_schema( - responses={ 200: '{ Token: Authorize }' }, + responses={ 200: '{ Token: "Token", user: { AccountGet } }' }, request_body=AccountAuthSerializer ) def post(self, request, *args, **kwargs): diff --git a/portfolio/comment/__pycache__/serializers.cpython-36.pyc b/portfolio/comment/__pycache__/serializers.cpython-36.pyc new file mode 100644 index 0000000..bb917c5 Binary files /dev/null and b/portfolio/comment/__pycache__/serializers.cpython-36.pyc differ diff --git a/portfolio/comment/__pycache__/views.cpython-36.pyc b/portfolio/comment/__pycache__/views.cpython-36.pyc new file mode 100644 index 0000000..38c0b02 Binary files /dev/null and b/portfolio/comment/__pycache__/views.cpython-36.pyc differ diff --git a/portfolio/comment/serializers.py b/portfolio/comment/serializers.py new file mode 100644 index 0000000..54f54c0 --- /dev/null +++ b/portfolio/comment/serializers.py @@ -0,0 +1,21 @@ +from rest_framework import serializers + +from .models import UserComment, GuestComment + +class UserCommentSerializer(serializers.ModelSerializer): + id = serializers.IntegerField(read_only=True) + user_id = serializers.IntegerField() + text = serializers.CharField() + + class Meta: + model = UserComment + fields = [ 'id', 'user_id', 'text'] + +class GuestCommentSerializer(serializers.ModelSerializer): + id = serializers.IntegerField(read_only=True) + guest_id = serializers.IntegerField() + text = serializers.CharField() + + class Meta: + model = GuestComment + fields = [ 'id', 'guest_id', 'text'] \ No newline at end of file diff --git a/portfolio/comment/views.py b/portfolio/comment/views.py index 91ea44a..2fd0900 100755 --- a/portfolio/comment/views.py +++ b/portfolio/comment/views.py @@ -1,3 +1,42 @@ from django.shortcuts import render -# Create your views here. +from rest_framework import viewsets, mixins +from rest_framework import permissions + +from .models import UserComment, GuestComment +from .serializers import UserCommentSerializer, GuestCommentSerializer + + +class AnonAndUserPermissions(permissions.BasePermission): + """ + Anonymous user always can create && User can modify self records only + + this is override of permissions in settings + """ + def has_object_permission(self, request, view, obj): + if request.method == 'POST': + return True + return "AnonymousUser" != str(request.user) + + +class UserCommentViewSet( + mixins.ListModelMixin, + mixins.CreateModelMixin, + mixins.DestroyModelMixin, + viewsets.GenericViewSet +): + + queryset = UserComment.objects.all() + serializer_class = UserCommentSerializer + + +class GuestCommentViewSet( + mixins.ListModelMixin, + mixins.CreateModelMixin, + mixins.DestroyModelMixin, + viewsets.GenericViewSet +): + + queryset = GuestComment.objects.all() + serializer_class = GuestCommentSerializer + permission_classes = (AnonAndUserPermissions, ) diff --git a/portfolio/settings.py b/portfolio/settings.py index a8c8663..1ec5195 100755 --- a/portfolio/settings.py +++ b/portfolio/settings.py @@ -37,6 +37,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'django_extensions', 'rest_framework', 'drf_yasg', 'rest_framework.authtoken', @@ -141,6 +142,8 @@ USE_TZ = True STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static') +# Swagger documentation options + SWAGGER_SETTINGS = { 'JSON_EDITOR': True, 'SECURITY_DEFINITIONS': { @@ -151,3 +154,10 @@ SWAGGER_SETTINGS = { } } } + +# UML options + +# GRAPH_MODELS = { +# 'all_applications': True, +# 'group_models': True, +# } \ No newline at end of file diff --git a/portfolio/urls.py b/portfolio/urls.py index 3364a9a..a72d08c 100755 --- a/portfolio/urls.py +++ b/portfolio/urls.py @@ -25,6 +25,7 @@ from portfolio import settings from .account.views import GuestViewSet, AccountViewSet, AccountAuth from .album.views import AlbumViewSet, TrackViewSet, TrackRowViewSet from .rating.views import TrackRatingViewSet, AlbumRatingViewSet, CommentRatingViewSet +from .comment.views import UserCommentViewSet, GuestCommentViewSet schema_view = get_schema_view( openapi.Info( @@ -51,6 +52,9 @@ router.register(r'track/(?P\w+)/rating', TrackRatingViewSet, basename= router.register(r'album/(?P\w+)/rating', AlbumRatingViewSet, basename='album rating') router.register(r'comment/(?P\w+)/rating', CommentRatingViewSet, basename='comment rating') +router.register(r'comment/user', UserCommentViewSet, basename='user-comment') +router.register(r'comment/guest', GuestCommentViewSet, basename='guest-comment') + urlpatterns = [ path('admin/', admin.site.urls), path('', include(router.urls)),