Commit 954eeabaafec8212dc682baacc4da66d1a2a4b3f

Authored by Zambom
1 parent 20f42435

Adding basic api docs

amadeus/settings.py
@@ -49,6 +49,8 @@ INSTALLED_APPS = [ @@ -49,6 +49,8 @@ INSTALLED_APPS = [
49 'rolepermissions', 49 'rolepermissions',
50 'oauth2_provider', 50 'oauth2_provider',
51 'rest_framework', 51 'rest_framework',
  52 + 'rest_framework_swagger',
  53 + 'django_filters',
52 'django_bootstrap_breadcrumbs', 54 'django_bootstrap_breadcrumbs',
53 's3direct', 55 's3direct',
54 'django_summernote', 56 'django_summernote',
@@ -313,10 +315,14 @@ S3DIRECT_DESTINATIONS = { @@ -313,10 +315,14 @@ S3DIRECT_DESTINATIONS = {
313 #TELL the rest framework to use a different backend 315 #TELL the rest framework to use a different backend
314 REST_FRAMEWORK = { 316 REST_FRAMEWORK = {
315 'DEFAULT_AUTHENTICATION_CLASSES':( 317 'DEFAULT_AUTHENTICATION_CLASSES':(
316 - 'oauth2_provider.contrib.rest_framework.OAuth2Authentication',), 318 + 'oauth2_provider.contrib.rest_framework.OAuth2Authentication','rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly',),
317 'DEFAULT_PERMISSION_CLASSES':( 319 'DEFAULT_PERMISSION_CLASSES':(
318 'rest_framework.permissions.IsAuthenticated',), 320 'rest_framework.permissions.IsAuthenticated',),
319 - 'PAGE_SIZE': 10, #pagination purposes 321 + 'PAGE_SIZE': 10, #pagination purposes
  322 +}
  323 +
  324 +SWAGGER_SETTINGS = {
  325 + 'JSON_EDITOR': True,
320 } 326 }
321 327
322 OAUTH2_PROVIDER = { 328 OAUTH2_PROVIDER = {
amadeus/urls.py
@@ -18,6 +18,9 @@ from django.conf import settings @@ -18,6 +18,9 @@ from django.conf import settings
18 from django.conf.urls import include, url 18 from django.conf.urls import include, url
19 from django.conf.urls.static import static 19 from django.conf.urls.static import static
20 from django.contrib import admin 20 from django.contrib import admin
  21 +
  22 +from rest_framework.documentation import include_docs_urls
  23 +
21 from .views import index 24 from .views import index
22 25
23 26
@@ -48,6 +51,7 @@ urlpatterns = [ @@ -48,6 +51,7 @@ urlpatterns = [
48 url(r'^analytics/', include('analytics.urls', namespace='analytics')), 51 url(r'^analytics/', include('analytics.urls', namespace='analytics')),
49 url(r'^dashboards/', include('dashboards.urls', namespace='dashboards')), 52 url(r'^dashboards/', include('dashboards.urls', namespace='dashboards')),
50 url(r'^bulletin/', include('bulletin.urls', namespace='bulletin')), 53 url(r'^bulletin/', include('bulletin.urls', namespace='bulletin')),
  54 + url(r'^api-docs/', include_docs_urls(title = 'REST Api Documentation')),
51 #API 55 #API
52 url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')), 56 url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
53 #S3Direct 57 #S3Direct
1 from django.conf.urls import url, include 1 from django.conf.urls import url, include
2 2
3 # ========== API IMPORTS ============= # 3 # ========== API IMPORTS ============= #
4 -  
5 from rest_framework import routers 4 from rest_framework import routers
6 5
  6 +from rest_framework.schemas import get_schema_view
  7 +from rest_framework_swagger.renderers import SwaggerUIRenderer, OpenAPIRenderer
  8 +
7 from users.views import UserViewSet 9 from users.views import UserViewSet
8 from log.views import LogViewSet 10 from log.views import LogViewSet
9 from . import views 11 from . import views
10 12
  13 +schema_view = get_schema_view(title = 'REST API', renderer_classes = [OpenAPIRenderer, SwaggerUIRenderer])
  14 +
11 router = routers.DefaultRouter() 15 router = routers.DefaultRouter()
12 16
13 router.register(r'logs', LogViewSet) 17 router.register(r'logs', LogViewSet)
@@ -21,4 +25,5 @@ urlpatterns = [ @@ -21,4 +25,5 @@ urlpatterns = [
21 #API REST 25 #API REST
22 url(r'^', include(router.urls)), 26 url(r'^', include(router.urls)),
23 url(r'^token$', views.getToken), 27 url(r'^token$', views.getToken),
  28 + url(r'^docs/', schema_view, name="docs"),
24 ] 29 ]
25 \ No newline at end of file 30 \ No newline at end of file
@@ -84,7 +84,16 @@ def getToken(request): @@ -84,7 +84,16 @@ def getToken(request):
84 return HttpResponse(response) 84 return HttpResponse(response)
85 85
86 class LoginViewset(viewsets.ReadOnlyModelViewSet): 86 class LoginViewset(viewsets.ReadOnlyModelViewSet):
  87 + """
  88 + login:
  89 + Log a user in the system
  90 +
  91 + register_device:
  92 + Register a mobile device for the logged user to provide app notifications
  93 + """
  94 +
87 queryset = User.objects.all() 95 queryset = User.objects.all()
  96 + serializer_class = UserSerializer
88 permissions_classes = (IsAuthenticated,) 97 permissions_classes = (IsAuthenticated,)
89 98
90 @csrf_exempt 99 @csrf_exempt
@@ -149,8 +158,15 @@ class LoginViewset(viewsets.ReadOnlyModelViewSet): @@ -149,8 +158,15 @@ class LoginViewset(viewsets.ReadOnlyModelViewSet):
149 return HttpResponse(response) 158 return HttpResponse(response)
150 159
151 class SubjectViewset(viewsets.ReadOnlyModelViewSet): 160 class SubjectViewset(viewsets.ReadOnlyModelViewSet):
  161 + """
  162 + ---
  163 + get_subjects:
  164 + Get list of subjects of a user. Require user email as parameter
  165 + """
  166 +
152 queryset = Subject.objects.all() 167 queryset = Subject.objects.all()
153 - permissions_classes = (IsAuthenticated, ) 168 + serializer_class = SubjectSerializer
  169 + permissions_classes = (IsAuthenticated,)
154 170
155 @csrf_exempt 171 @csrf_exempt
156 @list_route(methods = ['POST'], permissions_classes = [IsAuthenticated]) 172 @list_route(methods = ['POST'], permissions_classes = [IsAuthenticated])
@@ -193,7 +209,13 @@ class SubjectViewset(viewsets.ReadOnlyModelViewSet): @@ -193,7 +209,13 @@ class SubjectViewset(viewsets.ReadOnlyModelViewSet):
193 return HttpResponse(response) 209 return HttpResponse(response)
194 210
195 class ParticipantsViewset(viewsets.ReadOnlyModelViewSet): 211 class ParticipantsViewset(viewsets.ReadOnlyModelViewSet):
  212 + """
  213 + get_participants:
  214 + Get all users that participates in some subject. Require the logged user email and the subject slug
  215 + """
  216 +
196 queryset = User.objects.all() 217 queryset = User.objects.all()
  218 + serializer_class = UserSerializer
197 permissions_classes = (IsAuthenticated, ) 219 permissions_classes = (IsAuthenticated, )
198 220
199 @csrf_exempt 221 @csrf_exempt
@@ -231,7 +253,16 @@ class ParticipantsViewset(viewsets.ReadOnlyModelViewSet): @@ -231,7 +253,16 @@ class ParticipantsViewset(viewsets.ReadOnlyModelViewSet):
231 return HttpResponse(response) 253 return HttpResponse(response)
232 254
233 class ChatViewset(viewsets.ModelViewSet): 255 class ChatViewset(viewsets.ModelViewSet):
  256 + """
  257 + get_messages:
  258 + Get messages of a conversation
  259 +
  260 + send_message:
  261 + Send a message in a conversation
  262 + """
  263 +
234 queryset = TalkMessages.objects.all() 264 queryset = TalkMessages.objects.all()
  265 + serializer_class = ChatSerializer
235 permissions_classes = (IsAuthenticated, ) 266 permissions_classes = (IsAuthenticated, )
236 267
237 @csrf_exempt 268 @csrf_exempt
requirements.txt
@@ -6,6 +6,9 @@ beautifulsoup4==4.5.1 @@ -6,6 +6,9 @@ beautifulsoup4==4.5.1
6 channels==1.0.3 6 channels==1.0.3
7 click==6.6 7 click==6.6
8 constantly==15.1.0 8 constantly==15.1.0
  9 +coreapi==2.3.1
  10 +coreapi-cli==1.0.6
  11 +coreschema==0.0.4
9 coverage==4.2 12 coverage==4.2
10 daphne==1.0.2 13 daphne==1.0.2
11 decorator==4.0.10 14 decorator==4.0.10
@@ -19,49 +22,95 @@ django-common-helpers==0.9.0 @@ -19,49 +22,95 @@ django-common-helpers==0.9.0
19 django-cron==0.5.0 22 django-cron==0.5.0
20 django-crontab==0.7.1 23 django-crontab==0.7.1
21 django-discover-runner==1.0 24 django-discover-runner==1.0
  25 +django-filter==1.0.4
22 django-floppyforms==1.7.0 26 django-floppyforms==1.7.0
23 django-modalview==0.1.5 27 django-modalview==0.1.5
24 django-oauth-toolkit==1.0.0 28 django-oauth-toolkit==1.0.0
  29 +django-oauth2-provider==0.2.6.1
  30 +django-rest-swagger==2.1.2
25 django-role-permissions==1.2.1 31 django-role-permissions==1.2.1
26 django-s3direct==0.4.2 32 django-s3direct==0.4.2
27 django-session-security==2.4.0 33 django-session-security==2.4.0
28 django-summernote==0.8.6 34 django-summernote==0.8.6
  35 +django-tracking2==0.3.3
  36 +django-unixdatetimefield==0.1.6
29 django-widget-tweaks==1.4.1 37 django-widget-tweaks==1.4.1
30 django-wysiwyg==0.8.0 38 django-wysiwyg==0.8.0
31 -djangorestframework==3.4.6 39 +djangoajax==2.3.6
  40 +djangorestframework==3.6.4
  41 +entrypoints==0.2.2
32 et-xmlfile==1.0.1 42 et-xmlfile==1.0.1
  43 +fcm-django==0.2.11
33 file-resubmit==0.1.0 44 file-resubmit==0.1.0
34 gunicorn==19.6.0 45 gunicorn==19.6.0
  46 +httplib2==0.9.2
35 incremental==16.10.1 47 incremental==16.10.1
  48 +ipykernel==4.3.1
  49 +ipython==4.2.1
  50 +ipython-genutils==0.1.0
  51 +ipywidgets==5.1.5
  52 +itsdangerous==0.24
  53 +itypes==1.1.0
36 jdcal==1.3 54 jdcal==1.3
37 Jinja2==2.8 55 Jinja2==2.8
  56 +jsonschema==2.5.1
  57 +jupyter==1.0.0
  58 +jupyter-client==4.3.0
  59 +jupyter-console==5.0.0
  60 +jupyter-core==4.1.0
38 lxml==3.7.3 61 lxml==3.7.3
  62 +Markdown==2.6.6
39 MarkupSafe==0.23 63 MarkupSafe==0.23
  64 +mistune==0.7.3
40 msgpack-python==0.4.8 65 msgpack-python==0.4.8
  66 +nbconvert==4.2.0
  67 +nbformat==4.0.1
  68 +notebook==4.2.1
41 numpy==1.12.1 69 numpy==1.12.1
  70 +oauth2==1.9.0.post1
  71 +oauth2-provider==0.0
42 oauthlib==2.0.1 72 oauthlib==2.0.1
  73 +openapi-codec==1.3.2
43 openpyxl==2.4.5 74 openpyxl==2.4.5
44 packaging==16.8 75 packaging==16.8
45 pandas==0.19.2 76 pandas==0.19.2
  77 +pexpect==4.2.0
  78 +pickleshare==0.7.2
46 Pillow==3.3.1 79 Pillow==3.3.1
  80 +prompt-toolkit==1.0.3
47 psycopg2==2.6.2 81 psycopg2==2.6.2
  82 +ptyprocess==0.5.1
48 pycpfcnpj==1.0.2 83 pycpfcnpj==1.0.2
  84 +pyfcm==1.3.1
  85 +Pygments==2.1.3
49 pyparsing==2.2.0 86 pyparsing==2.2.0
50 python-dateutil==2.6.0 87 python-dateutil==2.6.0
  88 +python-slugify==1.2.0
51 pytz==2016.10 89 pytz==2016.10
  90 +pyzmq==15.3.0
  91 +qtconsole==4.2.1
52 redis==2.10.5 92 redis==2.10.5
53 requests==2.13.0 93 requests==2.13.0
  94 +requests-toolbelt==0.8.0
  95 +shortuuid==0.4.3
  96 +simplegeneric==0.8.1
  97 +simplejson==3.11.1
54 six==1.10.0 98 six==1.10.0
55 slugify==0.0.1 99 slugify==0.0.1
  100 +terminado==0.6
  101 +tornado==4.3
  102 +traitlets==4.2.2
56 Twisted==16.6.0 103 Twisted==16.6.0
57 txaio==2.6.0 104 txaio==2.6.0
  105 +Unidecode==0.4.19
  106 +uritemplate==3.0.0
58 validators==0.11.0 107 validators==0.11.0
  108 +virtualenv==15.0.3
  109 +wcwidth==0.1.7
59 webencodings==0.5 110 webencodings==0.5
60 Werkzeug==0.11.11 111 Werkzeug==0.11.11
61 whitenoise==3.2.2 112 whitenoise==3.2.2
  113 +widgetsnbextension==1.2.3
62 xlrd==1.0.0 114 xlrd==1.0.0
63 xlwt==1.2.0 115 xlwt==1.2.0
64 zope.interface==4.3.3 116 zope.interface==4.3.3
65 -fcm-django==0.2.11  
66 -pyfcm==1.3.1  
67 -requests-toolbelt==0.8.0  
68 \ No newline at end of file 117 \ No newline at end of file