urls.tpl 2.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
{% autoescape off %}
# WARNING
# THIS FILE HAS BEEN AUTOMATICALLY GENERATED
# WITH /backend/generate/generate_all.py
# 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

12
13
14
15
ALL_MODELS = []
ALL_VIEWSETS = []
{% for model in data %}
    {% if not model.requires_testing %}
16
from backend.models.{{model.import_location}} import {{model.viewset}}
17
18
19
20
21
22
23
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 %}
24
25
26
27
28
29
30
31
32
33

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:
34
    {% for model in data %}{% if model.requires_testing %}
35
    from backend.models.{{model.import_location}} import {{model.viewset}}
36
37
38
39
40
    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 %}
41
42
43
44
45
46
    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 %}


47
{% for model in data %}{% if not model.requires_testing %}
48
49
50
51
52
53
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))]
54
55

for model in ALL_MODELS:
Florent Chehab's avatar
Florent Chehab committed
56
    if model.model_config is None:
57
58
59
60
61
62
63
64
        raise Exception("You forgot to set the moderation_level variable in the model {}".format(str(model)))

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)))
65
{% endautoescape %}