From 9da2611fbb0937fbe86149ed21afe174c6062920 Mon Sep 17 00:00:00 2001 From: TBS093A Date: Fri, 24 Jul 2020 11:15:06 +0200 Subject: [PATCH] upgrade comments && add UML generator && modified shell files && fix urls --- .gitignore | 3 +- migrate.sh | 3 +- packages.sh | 8 ++++ portfolio/__pycache__/settings.cpython-36.pyc | Bin 2808 -> 2825 bytes portfolio/__pycache__/urls.cpython-36.pyc | Bin 2417 -> 2597 bytes .../account/__pycache__/views.cpython-36.pyc | Bin 3661 -> 3675 bytes portfolio/account/views.py | 2 +- .../__pycache__/serializers.cpython-36.pyc | Bin 0 -> 1202 bytes .../comment/__pycache__/views.cpython-36.pyc | Bin 0 -> 1602 bytes portfolio/comment/serializers.py | 21 +++++++++ portfolio/comment/views.py | 41 +++++++++++++++++- portfolio/settings.py | 10 +++++ portfolio/urls.py | 4 ++ 13 files changed, 88 insertions(+), 4 deletions(-) mode change 100755 => 100644 portfolio/__pycache__/settings.cpython-36.pyc mode change 100755 => 100644 portfolio/account/__pycache__/views.cpython-36.pyc create mode 100644 portfolio/comment/__pycache__/serializers.cpython-36.pyc create mode 100644 portfolio/comment/__pycache__/views.cpython-36.pyc create mode 100644 portfolio/comment/serializers.py 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 fba4b10cda25e62c019a9c060bd95b9f5eb15ba7..622a8bf01406d55f96e50b52b0649c2005417183 GIT binary patch delta 306 zcmYk0Jx{`56ovb~6x3Fr<)c9T#QFh(6s#X{GjVWmbh{xTnA5zriDf8*n*$T0=~{Pp zev7}r!N1_>D}(W#JSTU!Ip=;?=a%E;^IGT49(@>!@~QkAUGCSCc=gq}dqGj?q``oR z63VEc3QMezj+$Voqair#l+!vkD348{K*biev4dSSg&HvIrK(_5fI~&>$^%9wT4>A57LJ$RS$a2MLZzD$PN<9?RiIK;Vo7Rnss0z#pK)r)+5t}C;SA?# zMh0BSr)=F+AL9O%H%_|RkVVN{ PYbNj7?OK*|&VKa+7BfiH delta 292 zcmYk0J5R$v5QKf_!-xYDC$XIe&tM>gmjeMBgai^uAWFIwLKI^i4j30eK}C^@GIB%V zf02@(gJ`KKIZ_~Y^o_Py&FriH?FAj%mi@D@s{_X{K8$}O^?s;%u=>IIi;^T!fP*4R zD8q%PMrjGTFjK75{}lXj16)j$kX_m3O1?w7Zmn5)pTteTi8YiJGrR? zcJ)(r@C&20H)yjFJ~%Z$E%!RSNs}l{qa-{|Z=aIr{_#26mzV4=dy|dqU7n1YoOAZ8 EA5-&0iC zORJQA6I)9w!NS7ANlakDU3TXGoB7Xfv7g~*BfqX`!6QdGehEs_yCkdt>1{ggpU3=D z9|E9VtT-7v<7DkDlQ4*Wo`Vp~Lx@x!bXag1sRD!{;xaH?FGNw}#WMymSFuZ|^725k zD_G%Gh+`DukZ={cY0OD9ASrMP6OaXg@~*(T~S$xqMuqJGW`O(A(puS delta 430 zcmZvYyGjF55Qfj}ZY~>kV~m@ajk)jUssX{y%F^C$3$geo;sKlZ06`WjSy1u_;uECx z0YrQP3mbdEC(uzW7I6-9&i~EjFwDL8Q4aQ8w{SB1Jbtp3dQ&MARtMr2&$q$df(xA2 zZMZ1H71hBSN(qVTVjbm#u#sfov8#JCLM1VyfE^viD(Z7z4^ZU_s@P0SQa@Z{549Bg zT!WwDI{T=nc(KKGG*W>kH_%FPo15sQxXUf{e%V66h92rsY_NrpGcv*`CZR0)T-D=P z#m1=_O}MPLZ)pA~Rew5m|7(%50S9^qLl8!ZA)i>$1mhz$o~%OS+FZS4&S`m>+o$R3 wA!pO_HGh?z%1-Cg<(aMhLy;Carb6bYfn3tF9`fagziH)4wnZ)DuGxBp&^-Ge94J?fl^#h9Xvr>~wiYGHNi){YL x^qN&&qgo*(KRY$gN%SO)aOd_fJ8Tq-X`uVB3`Y!p|rManjC6$}cF>$a7i&QIw Zu@^3IG|17q0*S 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 0000000000000000000000000000000000000000..bb917c5ce24cf569d1ef6948a40108bf4c534a0e GIT binary patch literal 1202 zcmbtUO>Wab6rQoi_SkXSQfL?D1liO`m5?eSR8d65q7hPItf)az|zmb2qI`s z3K~;NgeC0UD(u)USj;FnBZ3L%6A_N2Q)g+%E+DS(0P$9cC-?;!__q*=45;a8sj@WB zZluz;6fw*6-T-)77KNNuCOlh6U9Ij$_|~t>2ImBpehfyEmHZ&(hIVl+NdQHcG3k zoUKn<-l!oWY7uofzcvip2q3G*f;eSV?SeBL1geL%glPI`KuyGiFK3mUNc92>Rvd93 zasTu(U4a;^jt8C!n^_Y@@kjy)`Ig;XbT?;zi+;4ITUFJwWqkBKF`BtYDJ} zM27=zwiGrnR-oedrMha!cWbrkTDl5bFx%&--}Pi`A{7Sd>dEjY&ByQ*{}39b5L!Fd GuKyE{fe2jy literal 0 HcmV?d00001 diff --git a/portfolio/comment/__pycache__/views.cpython-36.pyc b/portfolio/comment/__pycache__/views.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..38c0b022599953e83a5daa157ec2796f1eb166a9 GIT binary patch literal 1602 zcmZux&5qMZ5O&*6>^MJ!ftiKX{+J6=Bs4+dgtS@>%t~`vhLOVV!IzeCcZf5#J5)Q& zX0*4=Q}717QeQc7;Q=^pRVNTHN@uF3x~hMw>igPH`u%AAIpUS?I3JzH2+%%3(eF_S zN3g;vS;83EZsC?*;+1~l+qsAHR?|{fW^I*L45V5>8cF%BnWKv!&Gac80;jMsOk_ zPmBCof;nm~+xas};_GnHI6=|(P)R3Y!bx1g5>L3oyKxd<_?URh96hU4^{f(f)5R{m z>zgRXLBUn2mO5TyJWh+Nbfx1gt>O%1TFdz1!r?K63JP0ctL@T8|eB>ZvMnwX>e5+2uH0EQ&l!YXo{1X;|3? z@3G~`@nU5TXQ}3RA)d;24H;6kZB!16n9r^s?Z@hP@8)v^H{`rZOUb#3I7fJv1=&5$ z-!9W)8wofUD&rh}zasIsNwh8CPV@17tDyUR1tFdWKa=`})UTwd zi4c>bmYRbd(wh?G{vsaWViHS*5Q{(rXnsDrYldQ;R&Ug?o*@;pWvzi8z8L@#nNI=1 zzfy1s^mc&YgBFF`$OTzw+h(9lO?TH$Z5wQpHG}7=mb=fwChx(YxvpQ(2`}i&W`?Ks zThQ>_{sXTEwQ9HqXR<=XvTesK4z`MYxS8-b%n;f7I}uA$2Yc?2kqo_q9(90zn_iIh EAM{M3YXATM literal 0 HcmV?d00001 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)),