urls.tpl 2.5 KB
Newer Older
1 2 3
{% autoescape off %}
# WARNING
# THIS FILE HAS BEEN AUTOMATICALLY GENERATED
Florent Chehab's avatar
Florent Chehab committed
4
# WITH /backend/generate/generate_backend_files.py
5 6 7 8 9 10
# MODIFY THE FILE ABOVE IF YOUR NOT SATISFIED 
# THIS WARNING DOESN'T APPLY TO .tpl FILES...

from django.conf.urls import url, include
from django.conf import settings
from rest_framework import routers
11 12
from django.urls import path
from . import views
13

14 15 16 17
ALL_MODELS = []
ALL_VIEWSETS = []
{% for model in data %}
    {% if not model.requires_testing %}
18
from backend.models.{{model.import_location}} import {{model.viewset}}
19 20 21 22 23 24 25
ALL_VIEWSETS.append({{model.viewset}})
        {% if model.model is not None and not model.ignore_in_admin%}
from backend.models.{{model.import_location}} import {{model.model}}
ALL_MODELS.append({{model.model}})
        {% endif %}
    {% endif %}
{% endfor %}
26 27 28 29 30 31 32 33 34 35

from rest_framework.documentation import include_docs_urls

urlpatterns = [
    url(r'^api-docs/', include_docs_urls(title='Outgoing API'))
]

router = routers.DefaultRouter()

if settings.TESTING:
36
    {% for model in data %}{% if model.requires_testing %}
37
    from backend.models.{{model.import_location}} import {{model.viewset}}
38 39 40 41 42
    ALL_VIEWSETS.append({{model.viewset}})
    {% if model.model is not None %}
    from backend.models.{{model.import_location}} import {{model.model}}
    ALL_MODELS.append({{model.model}})
    {% endif %}
43 44 45 46 47 48
    router.register(
        r'{{model.api_end_point}}{% if 'api_attr' in model %}/{{model.api_attr}}{% endif %}', 
        {{model.viewset}}{%if 'api_name' in model%},"{{model.api_name}}"{% endif %}
    ){% endif %}{% endfor %}


49
{% for model in data %}{% if not model.requires_testing %}
50 51 52 53 54 55
router.register(
    r'{{model.api_end_point}}{% if 'api_attr' in model %}/{{model.api_attr}}{% endif %}', 
    {{model.viewset}}{%if 'api_name' in model%},"{{model.api_name}}"{% endif %}
){% endif %}{% endfor %}

urlpatterns += [url(r'^api/', include(router.urls))]
56
urlpatterns.append(path('api/serverModerationStatus/', views.app_moderation_status))
57 58

for model in ALL_MODELS:
59 60 61 62
    for key in model.model_config:
        val = model.model_config[key]
        if val is None:
            raise Exception("You forgot to set the {} config variable in the model {}".format(key, str(model)))
63 64 65 66 67 68 69

from backend.permissions import DEFAULT_VIEWSET_PERMISSIONS
for viewset in ALL_VIEWSETS:
    for p in DEFAULT_VIEWSET_PERMISSIONS:
        v_p = viewset.permission_classes
        if p not in v_p:
            raise Exception("Permission_classes are not defined correctly in the viewset {}".format(str(viewset)))
70
{% endautoescape %}