make section-dependend editor urls

This commit is contained in:
Laura Klünder 2017-05-19 15:23:00 +02:00
parent 866f68381f
commit 32c075301d
3 changed files with 31 additions and 12 deletions

View file

@ -3,11 +3,12 @@ from django.conf.urls import url
from c3nav.editor.views import edit, list_objects, main_index, section_detail
def add_editor_urls(name, model):
def add_editor_urls(name, model, parent_name_plural=None, parent_name=None):
prefix = '' if parent_name is None else parent_name_plural+r'/(?P<'+parent_name+'>[0-9]+)/'
return [
url(r'^'+name+r'/$', list_objects, name='editor.'+name+'.list', kwargs={'model': model}),
url(r'^'+name+r'/(?P<pk>[0-9]+)/$', edit, name='editor.'+name+'.edit', kwargs={'model': model}),
url(r'^'+name+r'/create$', edit, name='editor.'+name+'.create', kwargs={'model': model}),
url(r'^'+prefix+name+r'/$', list_objects, name='editor.'+name+'.list', kwargs={'model': model}),
url(r'^'+prefix+name+r'/(?P<pk>[0-9]+)/$', edit, name='editor.'+name+'.edit', kwargs={'model': model}),
url(r'^'+prefix+name+r'/create$', edit, name='editor.'+name+'.create', kwargs={'model': model}),
]
@ -18,4 +19,4 @@ urlpatterns = [
url(r'^sections/create$', edit, name='editor.section.create', kwargs={'model': 'Section'}),
]
urlpatterns.extend(add_editor_urls('locationgroups', 'LocationGroup'))
urlpatterns.extend(add_editor_urls('doors', 'Door'))
urlpatterns.extend(add_editor_urls('doors', 'Door', 'sections', 'section'))