diff --git a/src/c3nav/editor/templates/editor/index.html b/src/c3nav/editor/templates/editor/index.html index 7a9a722a..c8428bec 100644 --- a/src/c3nav/editor/templates/editor/index.html +++ b/src/c3nav/editor/templates/editor/index.html @@ -1,14 +1,14 @@ {% load bootstrap3 %} {% load i18n %} - + {% trans 'Section' as model_title %} {% blocktrans %}New {{ model_title }}{% endblocktrans %}

{% trans 'Sections' %}

{% for s in sections %} - + {{ s.title }} {% endfor %} diff --git a/src/c3nav/editor/templates/editor/list.html b/src/c3nav/editor/templates/editor/list.html index d4548076..da8ab863 100644 --- a/src/c3nav/editor/templates/editor/list.html +++ b/src/c3nav/editor/templates/editor/list.html @@ -6,7 +6,25 @@ {% blocktrans %}New {{ model_title }}{% endblocktrans %} -

{% blocktrans %}{{ model_title_plural }}{% endblocktrans %}

+

+ {% blocktrans %}{{ model_title_plural }}{% endblocktrans %} + {% if section %} + {% with section.title as section_title %} + {% blocktrans %}in section {{ section_title }}{% endblocktrans %} + {% endwith %} + {% endif %} + {% if space %} + {% with space.title as space_title %} + {% blocktrans %}in space {{ space_title }}{% endblocktrans %} + {% endwith %} + {% endif %} +

+ +{% if explicit_edit %} + {% trans 'Details' as edit_caption %} +{% else %} + {% trans 'Edit' as edit_caption %} +{% endif %} @@ -19,7 +37,7 @@ {% endif %} - + {% endfor %} diff --git a/src/c3nav/editor/templates/editor/section.html b/src/c3nav/editor/templates/editor/section.html index 5e1305e2..78d60e78 100644 --- a/src/c3nav/editor/templates/editor/section.html +++ b/src/c3nav/editor/templates/editor/section.html @@ -2,7 +2,7 @@ {% load i18n %} {% include 'editor/fragment_sections.html' %} - + {% trans 'Section' as model_title %} {% blocktrans %}Edit {{ model_title }}{% endblocktrans %} diff --git a/src/c3nav/editor/templates/editor/space.html b/src/c3nav/editor/templates/editor/space.html index 5e1305e2..cf29f273 100644 --- a/src/c3nav/editor/templates/editor/space.html +++ b/src/c3nav/editor/templates/editor/space.html @@ -2,13 +2,13 @@ {% load i18n %} {% include 'editor/fragment_sections.html' %} - - {% trans 'Section' as model_title %} + + {% trans 'Space' as model_title %} {% blocktrans %}Edit {{ model_title }}{% endblocktrans %} -

{{ section.title }}

+

{{ space.title }}

- « {% trans 'back to overview' %} + « {% trans 'back to section' %}

{% include 'editor/fragment_child_models.html' %} diff --git a/src/c3nav/editor/urls.py b/src/c3nav/editor/urls.py index c666e15f..aae983e8 100644 --- a/src/c3nav/editor/urls.py +++ b/src/c3nav/editor/urls.py @@ -1,6 +1,6 @@ from django.conf.urls import url -from c3nav.editor.views import edit, list_objects, main_index, section_detail +from c3nav.editor.views import edit, list_objects, main_index, section_detail, space_detail def add_editor_urls(name, model, parent_name_plural=None, parent_name=None, with_list=True, explicit_edit=False): @@ -21,9 +21,8 @@ def add_editor_urls(name, model, parent_name_plural=None, parent_name=None, with urlpatterns = [ url(r'^$', main_index, name='editor.index'), - url(r'^sections/(?P[0-9]+)/$', section_detail, name='editor.section'), - url(r'^sections/(?P[0-9]+)/edit$', edit, name='editor.section.edit', kwargs={'model': 'Section'}), - url(r'^sections/create$', edit, name='editor.section.create', kwargs={'model': 'Section'}), + url(r'^sections/(?P[0-9]+)/$', section_detail, name='editor.sections.detail'), + url(r'^sections/(?P
[0-9]+)/spaces/(?P[0-9]+)/$', space_detail, name='editor.spaces.detail'), ] urlpatterns.extend(add_editor_urls('sections', 'Section', with_list=False, explicit_edit=True)) urlpatterns.extend(add_editor_urls('locationgroups', 'LocationGroup')) diff --git a/src/c3nav/editor/views.py b/src/c3nav/editor/views.py index 6366be6f..3a9007dc 100644 --- a/src/c3nav/editor/views.py +++ b/src/c3nav/editor/views.py @@ -42,7 +42,7 @@ def section_detail(request, pk): return render(request, 'editor/section.html', { 'sections': Section.objects.all(), 'section': section, - 'section_url': 'editor.section', + 'section_url': 'editor.sections.detail', 'section_as_pk': True, 'child_models': [{ @@ -59,23 +59,13 @@ def section_detail(request, pk): @sidebar_view def space_detail(request, section, pk): - section = get_object_or_404(Section, pk=pk) + space = get_object_or_404(Space, section__id=section, pk=pk) - return render(request, 'editor/section.html', { - 'sections': Section.objects.all(), - 'section': section, - 'section_url': 'editor.section', - 'section_as_pk': True, + return render(request, 'editor/space.html', { + 'section': space.section, + 'space': space, - 'child_models': [{ - 'title': Space._meta.verbose_name_plural, - 'url': reverse('editor.spaces.list', kwargs={'section': pk}), - 'count': section.spaces.count(), - }, { - 'title': Door._meta.verbose_name_plural, - 'url': reverse('editor.doors.list', kwargs={'section': pk}), - 'count': section.doors.count(), - }], + 'child_models': [], }) @@ -110,21 +100,30 @@ def edit(request, pk=None, model=None, section=None, space=None, explicit_edit=F 'section': obj, 'back_url': reverse('editor.index') if new else reverse('editor.section', kwargs={'pk': pk}), }) + elif model == Space and not new: + ctx.update({ + 'section': obj, + 'back_url': reverse('editor.spaces.detail', kwargs={'section': obj.section.pk, 'pk': pk}), + }) elif hasattr(obj, 'section'): ctx.update({ 'section': obj.section, - 'back_url': reverse('editor.section', kwargs={'pk': obj.section.pk}), + 'back_url': reverse('editor.sections.detail', kwargs={'pk': obj.section.pk}), }) elif hasattr(obj, 'space'): ctx.update({ 'section': obj.space.section, - 'back_url': reverse('editor.space', kwargs={'pk': obj.space.pk}), + 'back_url': reverse('editor.spaces.detail', kwargs={'pk': obj.space.pk}), }) else: - if not request.resolver_match.url_name.endswith('.edit'): - raise ValueError('url_name does not end with .edit') + kwargs = {} + if section is not None: + kwargs.update({'section': section}) + elif space is not None: + kwargs.update({'space': space}) + ctx.update({ - 'back_url': reverse(request.resolver_match.url_name[:-4]+'list'), + 'back_url': reverse('.'.join(request.resolver_match.url_name.split('.')[:-1]+['list']), kwargs=kwargs), }) if request.method == 'POST': @@ -181,6 +180,7 @@ def list_objects(request, model=None, section=None, space=None, explicit_edit=Fa 'model_name': model.__name__.lower(), 'model_title': model._meta.verbose_name, 'model_title_plural': model._meta.verbose_name_plural, + 'explicit_edit': explicit_edit, } queryset = model.objects.all().order_by('id') @@ -191,7 +191,7 @@ def list_objects(request, model=None, section=None, space=None, explicit_edit=Fa section = get_object_or_404(Section, pk=section) queryset = queryset.filter(section=section) ctx.update({ - 'back_url': reverse('editor.section', kwargs={'pk': section.pk}), + 'back_url': reverse('editor.sections.detail', kwargs={'pk': section.pk}), 'back_title': _('back to section'), 'sections': Section.objects.all(), 'section': section, @@ -202,7 +202,7 @@ def list_objects(request, model=None, section=None, space=None, explicit_edit=Fa space = get_object_or_404(Section, pk=space) queryset = queryset.filter(space=space) ctx.update({ - 'back_url': reverse('editor.space', kwargs={'pk': space.pk}), + 'back_url': reverse('editor.spaces.detail', kwargs={'pk': space.pk}), 'back_title': _('back to space'), }) else: @@ -211,7 +211,7 @@ def list_objects(request, model=None, section=None, space=None, explicit_edit=Fa 'back_title': _('back to overview'), }) - edit_url_name = request.resolver_match.url_name[:-5]+('' if explicit_edit else '.edit') + edit_url_name = request.resolver_match.url_name[:-4]+('detail' if explicit_edit else 'edit') for obj in queryset: reverse_kwargs['pk'] = obj.pk obj.edit_url = reverse(edit_url_name, kwargs=reverse_kwargs)
{{ item.title }}{% trans 'Edit' %}{{ edit_caption }}