Merge pull request #469 from arachnys/add-interactive-api-docs

Add interactive api docs using djangorestframework 3.6
This commit is contained in:
Frank Hamand 2017-03-29 14:42:38 +01:00 committed by GitHub
commit 023f283f1c
6 changed files with 27 additions and 11 deletions

View File

@ -1,3 +1,8 @@
master
------
* Add interactive api docs (using djangorestframework 3.6) at /docs
Version 0.10.1
--------------

View File

@ -22,6 +22,9 @@ redis = "*"
requests = "*"
twilio = "*"
whitenoise = "*"
coreapi = "*"
Django = ">=1.10,<1.11"
django_polymorphic = "*"
django_compressor = "*"
Markdown = "*"
Pygments = "*"

View File

@ -12,7 +12,7 @@ logger = logging.getLogger(__name__)
router = routers.DefaultRouter()
def create_viewset(arg_model, arg_fields, arg_read_only_fields=(), no_create=False):
def create_viewset(arg_model, arg_fields, arg_read_only_fields=(), readonly=False):
arg_read_only_fields = ('id',) + arg_read_only_fields
for field in arg_read_only_fields:
if field not in arg_fields:
@ -25,14 +25,8 @@ def create_viewset(arg_model, arg_fields, arg_read_only_fields=(), no_create=Fal
read_only_fields = arg_read_only_fields
viewset_class = None
if no_create:
class NoCreateViewSet(mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
mixins.ListModelMixin,
viewsets.GenericViewSet):
pass
viewset_class = NoCreateViewSet
if readonly:
viewset_class = viewsets.ReadOnlyModelViewSet
else:
viewset_class = viewsets.ModelViewSet
@ -82,7 +76,7 @@ status_check_fields = (
router.register(r'status_checks', create_viewset(
arg_model=models.StatusCheck,
arg_fields=status_check_fields,
no_create=True,
readonly=True,
))
router.register(r'icmp_checks', create_viewset(
@ -161,5 +155,6 @@ router.register(r'alertplugins', create_viewset(
arg_model=alert.AlertPlugin,
arg_fields=(
'title',
)
),
readonly=True
))

View File

@ -92,6 +92,9 @@ STATICFILES_FINDERS = (
'compressor.finders.CompressorFinder',
)
if os.environ.get('WWW_SCHEME') == 'https':
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Make this unique, and don't share it with anybody.
SECRET_KEY = os.environ.get(
'DJANGO_SECRET_KEY', '2FL6ORhHwr5eX34pP9mMugnIOd3jzVuT45f7w430Mt5PnEwbcJgma0q8zUXNZ68A')

View File

@ -21,6 +21,7 @@ from cabot.cabotapp.views import (InstanceListView, InstanceDetailView,
from cabot.cabotapp.utils import cabot_needs_setup
from cabot import rest_urls
from rest_framework.documentation import include_docs_urls
from django.contrib import admin
from django.views.generic.base import RedirectView
@ -142,6 +143,7 @@ urlpatterns = [
# Comment below line to disable browsable rest api
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^api/', include(rest_urls.router.urls)),
url(r'^docs/', include_docs_urls(title="Cabot API", description="An API to create and view Cabot checks and services."))
]
def append_plugin_urls():

View File

@ -3,6 +3,8 @@ anyjson==0.3.3
appdirs==1.4.3
billiard==3.5.0.2
celery==4.0.2
coreapi==2.3.0
coreschema==0.0.4
dj-database-url==0.4.2
Django==1.10.6
django-appconf==1.0.2
@ -18,9 +20,14 @@ greenlet==0.4.12
gunicorn==19.7.1
httplib2==0.10.3
icalendar==3.11.3
itypes==1.1.0
Jinja2==2.9.5
kombu==4.0.2
Markdown==2.6.8
MarkupSafe==1.0
packaging==16.8
psycopg2==2.7.1
Pygments==2.2.0
pyldap==2.4.28
pyparsing==2.2.0
PySocks==1.6.7
@ -32,5 +39,6 @@ requests==2.13.0
rjsmin==1.0.12
six==1.10.0
twilio==5.7.0
uritemplate==3.0.0
vine==1.1.3
whitenoise==3.3.0