def test_settings_module(self):

        settings = DRFSettings()

        self.assertEqual(settings.get_setting("HIDE_DOCS"), False)
        self.assertEqual(settings.get_setting("HIDE_LIVE_ENDPOINTS"), False)
        self.assertEqual(settings.get_setting("HIDE_HIDDEN_FIELDS"), False)
        self.assertEqual(settings.get_setting("TEST"), None)
示例#2
0
    def get_context_data(self, **kwargs):
        settings = DRFSettings().settings
        if settings["HIDE_DOCS"]:
            raise Http404(
                "Django Rest Framework Docs are hidden. Check your settings.")

        context = super(PartnerDocsView, self).get_context_data(**kwargs)
        docs = ApiDocumentation(drf_router=self.drf_router)
        endpoints = docs.get_endpoints()
        allowedEnPoint = settings["ALLOWED_ENDPOINTS"]
        if allowedEnPoint:
            #Filtrage
            print("==== FILTRAGE =====")
            newEndpoints = []
            for endpoint in endpoints:
                path = endpoint.path
                for allowed in allowedEnPoint:
                    if path == allowed:
                        newEndpoints.append(endpoint)
                        print("Autorise endpoint %s" % path)
                        break
            endpoints = newEndpoints
        query = self.request.GET.get("search", "")
        if query and endpoints:
            endpoints = [
                endpoint for endpoint in endpoints if query in endpoint.path
            ]

        context['query'] = query
        context['endpoints'] = endpoints
        return context
示例#3
0
    def get_context_data(self, **kwargs):
        settings = DRFSettings().settings
        if settings["HIDE_DOCS"]:
            raise Http404("Django Rest Framework Docs are hidden. Check your settings.")

        context = super(DRFDocsView, self).get_context_data(**kwargs)
        docs = ApiDocumentation()
        endpoints = docs.get_endpoints()

        query = self.request.GET.get("search", "")
        if query and endpoints:
            endpoints = [endpoint for endpoint in endpoints if query in endpoint.path]

        context['query'] = query
        context['endpoints'] = endpoints
        return context
示例#4
0
    def test_settings_module(self):

        settings = DRFSettings()

        self.assertEqual(settings.get_setting("HIDE_DOCS"), False)
        self.assertEqual(settings.get_setting("TEST"), None)
示例#5
0
from django.conf.urls import url

from rest_framework_docs.settings import DRFSettings
from rest_framework_docs.views import DRFDocsView


settings = DRFSettings().settings
if settings["LOGIN_REQUIRED"]:
    from django.contrib.auth.decorators import login_required
    docs_view = login_required(DRFDocsView.as_view())
else:
    docs_view = DRFDocsView.as_view()

urlpatterns = [
    # Url to view the API Docs
    url(r'^$', docs_view, name='drfdocs'),
    # Url to view the API Docs with a specific namespace or app_name
    url(r'^(?P<filter_param>[\w-]+)/$', docs_view, name='drfdocs-filter'),
]
    def test_settings_module(self):

        settings = DRFSettings()

        self.assertEqual(settings.get_setting("HIDE_DOCS"), False)
        self.assertEqual(settings.get_setting("TEST"), None)