team-3/src/c3nav/editor/urls.py

36 lines
1.8 KiB
Python
Raw Normal View History

2016-08-31 17:14:31 +02:00
from django.conf.urls import url
from c3nav.editor.views import edit, list_objects, main_index, section_detail, space_detail
2016-09-23 15:23:02 +02:00
2017-05-16 18:08:07 +02:00
2017-05-19 16:34:02 +02:00
def add_editor_urls(name, model, parent_name_plural=None, parent_name=None, with_list=True, explicit_edit=False):
prefix = ('' if parent_name is None else parent_name_plural+r'/(?P<'+parent_name+'>[0-9]+)/')+name
name_prefix = 'editor.'+name+'.'
kwargs = {'model': model, 'explicit_edit': explicit_edit}
explicit_edit = r'edit' if explicit_edit else ''
result = []
if with_list:
result.append(url(r'^'+prefix+r'/$', list_objects, name=name_prefix+'list', kwargs=kwargs))
result.extend([
url(r'^'+prefix+r'/(?P<pk>\d+)/'+explicit_edit+'$', edit, name=name_prefix+'edit', kwargs=kwargs),
url(r'^'+prefix+r'/create$', edit, name=name_prefix+'create', kwargs=kwargs),
])
return result
2017-05-16 18:08:07 +02:00
2016-08-31 17:14:31 +02:00
urlpatterns = [
2017-05-14 20:21:33 +02:00
url(r'^$', main_index, name='editor.index'),
url(r'^sections/(?P<pk>[0-9]+)/$', section_detail, name='editor.sections.detail'),
url(r'^sections/(?P<section>[0-9]+)/spaces/(?P<pk>[0-9]+)/$', space_detail, name='editor.spaces.detail'),
2016-08-31 17:14:31 +02:00
]
2017-05-19 16:34:02 +02:00
urlpatterns.extend(add_editor_urls('sections', 'Section', with_list=False, explicit_edit=True))
2017-05-16 18:08:07 +02:00
urlpatterns.extend(add_editor_urls('locationgroups', 'LocationGroup'))
2017-05-19 16:34:02 +02:00
urlpatterns.extend(add_editor_urls('spaces', 'Space', 'sections', 'section', explicit_edit=True))
2017-05-19 15:23:00 +02:00
urlpatterns.extend(add_editor_urls('doors', 'Door', 'sections', 'section'))
2017-05-19 16:50:09 +02:00
urlpatterns.extend(add_editor_urls('areas', 'Area', 'spaces', 'space'))
urlpatterns.extend(add_editor_urls('stairs', 'Stair', 'spaces', 'space'))
urlpatterns.extend(add_editor_urls('obstacles', 'Obstacle', 'spaces', 'space'))
urlpatterns.extend(add_editor_urls('lineobstacles', 'LineObstacle', 'spaces', 'space'))
urlpatterns.extend(add_editor_urls('points', 'Point', 'spaces', 'space'))