diff --git a/amadeus/settings.py b/amadeus/settings.py index 34a8d41..79b6148 100644 --- a/amadeus/settings.py +++ b/amadeus/settings.py @@ -49,6 +49,8 @@ INSTALLED_APPS = [ 'rolepermissions', 'oauth2_provider', 'rest_framework', + 'rest_framework_swagger', + 'django_filters', 'django_bootstrap_breadcrumbs', 's3direct', 'django_summernote', @@ -313,10 +315,14 @@ S3DIRECT_DESTINATIONS = { #TELL the rest framework to use a different backend REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES':( - 'oauth2_provider.contrib.rest_framework.OAuth2Authentication',), + 'oauth2_provider.contrib.rest_framework.OAuth2Authentication','rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly',), 'DEFAULT_PERMISSION_CLASSES':( 'rest_framework.permissions.IsAuthenticated',), - 'PAGE_SIZE': 10, #pagination purposes + 'PAGE_SIZE': 10, #pagination purposes +} + +SWAGGER_SETTINGS = { + 'JSON_EDITOR': True, } OAUTH2_PROVIDER = { diff --git a/amadeus/urls.py b/amadeus/urls.py index 3f37a57..13b9e2f 100644 --- a/amadeus/urls.py +++ b/amadeus/urls.py @@ -18,6 +18,9 @@ from django.conf import settings from django.conf.urls import include, url from django.conf.urls.static import static from django.contrib import admin + +from rest_framework.documentation import include_docs_urls + from .views import index @@ -48,6 +51,7 @@ urlpatterns = [ url(r'^analytics/', include('analytics.urls', namespace='analytics')), url(r'^dashboards/', include('dashboards.urls', namespace='dashboards')), url(r'^bulletin/', include('bulletin.urls', namespace='bulletin')), + url(r'^api-docs/', include_docs_urls(title = 'REST Api Documentation')), #API url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')), #S3Direct diff --git a/api/urls.py b/api/urls.py index 40d57ad..af92cc0 100644 --- a/api/urls.py +++ b/api/urls.py @@ -1,13 +1,17 @@ from django.conf.urls import url, include # ========== API IMPORTS ============= # - from rest_framework import routers +from rest_framework.schemas import get_schema_view +from rest_framework_swagger.renderers import SwaggerUIRenderer, OpenAPIRenderer + from users.views import UserViewSet from log.views import LogViewSet from . import views +schema_view = get_schema_view(title = 'REST API', renderer_classes = [OpenAPIRenderer, SwaggerUIRenderer]) + router = routers.DefaultRouter() router.register(r'logs', LogViewSet) @@ -21,4 +25,5 @@ urlpatterns = [ #API REST url(r'^', include(router.urls)), url(r'^token$', views.getToken), + url(r'^docs/', schema_view, name="docs"), ] \ No newline at end of file diff --git a/api/views.py b/api/views.py index a9820a1..7f9683e 100644 --- a/api/views.py +++ b/api/views.py @@ -84,7 +84,16 @@ def getToken(request): return HttpResponse(response) class LoginViewset(viewsets.ReadOnlyModelViewSet): + """ + login: + Log a user in the system + + register_device: + Register a mobile device for the logged user to provide app notifications + """ + queryset = User.objects.all() + serializer_class = UserSerializer permissions_classes = (IsAuthenticated,) @csrf_exempt @@ -149,8 +158,15 @@ class LoginViewset(viewsets.ReadOnlyModelViewSet): return HttpResponse(response) class SubjectViewset(viewsets.ReadOnlyModelViewSet): + """ + --- + get_subjects: + Get list of subjects of a user. Require user email as parameter + """ + queryset = Subject.objects.all() - permissions_classes = (IsAuthenticated, ) + serializer_class = SubjectSerializer + permissions_classes = (IsAuthenticated,) @csrf_exempt @list_route(methods = ['POST'], permissions_classes = [IsAuthenticated]) @@ -193,7 +209,13 @@ class SubjectViewset(viewsets.ReadOnlyModelViewSet): return HttpResponse(response) class ParticipantsViewset(viewsets.ReadOnlyModelViewSet): + """ + get_participants: + Get all users that participates in some subject. Require the logged user email and the subject slug + """ + queryset = User.objects.all() + serializer_class = UserSerializer permissions_classes = (IsAuthenticated, ) @csrf_exempt @@ -231,7 +253,16 @@ class ParticipantsViewset(viewsets.ReadOnlyModelViewSet): return HttpResponse(response) class ChatViewset(viewsets.ModelViewSet): + """ + get_messages: + Get messages of a conversation + + send_message: + Send a message in a conversation + """ + queryset = TalkMessages.objects.all() + serializer_class = ChatSerializer permissions_classes = (IsAuthenticated, ) @csrf_exempt diff --git a/requirements.txt b/requirements.txt index 80ed501..bf31793 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,9 @@ beautifulsoup4==4.5.1 channels==1.0.3 click==6.6 constantly==15.1.0 +coreapi==2.3.1 +coreapi-cli==1.0.6 +coreschema==0.0.4 coverage==4.2 daphne==1.0.2 decorator==4.0.10 @@ -19,49 +22,95 @@ django-common-helpers==0.9.0 django-cron==0.5.0 django-crontab==0.7.1 django-discover-runner==1.0 +django-filter==1.0.4 django-floppyforms==1.7.0 django-modalview==0.1.5 django-oauth-toolkit==1.0.0 +django-oauth2-provider==0.2.6.1 +django-rest-swagger==2.1.2 django-role-permissions==1.2.1 django-s3direct==0.4.2 django-session-security==2.4.0 django-summernote==0.8.6 +django-tracking2==0.3.3 +django-unixdatetimefield==0.1.6 django-widget-tweaks==1.4.1 django-wysiwyg==0.8.0 -djangorestframework==3.4.6 +djangoajax==2.3.6 +djangorestframework==3.6.4 +entrypoints==0.2.2 et-xmlfile==1.0.1 +fcm-django==0.2.11 file-resubmit==0.1.0 gunicorn==19.6.0 +httplib2==0.9.2 incremental==16.10.1 +ipykernel==4.3.1 +ipython==4.2.1 +ipython-genutils==0.1.0 +ipywidgets==5.1.5 +itsdangerous==0.24 +itypes==1.1.0 jdcal==1.3 Jinja2==2.8 +jsonschema==2.5.1 +jupyter==1.0.0 +jupyter-client==4.3.0 +jupyter-console==5.0.0 +jupyter-core==4.1.0 lxml==3.7.3 +Markdown==2.6.6 MarkupSafe==0.23 +mistune==0.7.3 msgpack-python==0.4.8 +nbconvert==4.2.0 +nbformat==4.0.1 +notebook==4.2.1 numpy==1.12.1 +oauth2==1.9.0.post1 +oauth2-provider==0.0 oauthlib==2.0.1 +openapi-codec==1.3.2 openpyxl==2.4.5 packaging==16.8 pandas==0.19.2 +pexpect==4.2.0 +pickleshare==0.7.2 Pillow==3.3.1 +prompt-toolkit==1.0.3 psycopg2==2.6.2 +ptyprocess==0.5.1 pycpfcnpj==1.0.2 +pyfcm==1.3.1 +Pygments==2.1.3 pyparsing==2.2.0 python-dateutil==2.6.0 +python-slugify==1.2.0 pytz==2016.10 +pyzmq==15.3.0 +qtconsole==4.2.1 redis==2.10.5 requests==2.13.0 +requests-toolbelt==0.8.0 +shortuuid==0.4.3 +simplegeneric==0.8.1 +simplejson==3.11.1 six==1.10.0 slugify==0.0.1 +terminado==0.6 +tornado==4.3 +traitlets==4.2.2 Twisted==16.6.0 txaio==2.6.0 +Unidecode==0.4.19 +uritemplate==3.0.0 validators==0.11.0 +virtualenv==15.0.3 +wcwidth==0.1.7 webencodings==0.5 Werkzeug==0.11.11 whitenoise==3.2.2 +widgetsnbextension==1.2.3 xlrd==1.0.0 xlwt==1.2.0 zope.interface==4.3.3 -fcm-django==0.2.11 -pyfcm==1.3.1 -requests-toolbelt==0.8.0 \ No newline at end of file -- libgit2 0.21.2