diff --git a/src/c3nav/editor/static/editor/js/editor.js b/src/c3nav/editor/static/editor/js/editor.js index 7235fe4c..468b8a5a 100644 --- a/src/c3nav/editor/static/editor/js/editor.js +++ b/src/c3nav/editor/static/editor/js/editor.js @@ -97,7 +97,7 @@ editor = { _sidebar_unload: function() { // unload the sidebar. called on sidebar_get and form submit. editor._section_control.disable(); - $('#sidebar').addClass('loading').find('.content').html(); + $('#sidebar').addClass('loading').find('.content').html(''); editor._unhighlight_geometry(); editor._cancel_editing(); }, diff --git a/src/c3nav/editor/templates/editor/fragment_sections.html b/src/c3nav/editor/templates/editor/fragment_sections.html index d25cedb7..ccbaaa7e 100644 --- a/src/c3nav/editor/templates/editor/fragment_sections.html +++ b/src/c3nav/editor/templates/editor/fragment_sections.html @@ -2,7 +2,7 @@ diff --git a/src/c3nav/editor/templates/editor/section.html b/src/c3nav/editor/templates/editor/section.html index d9ff149b..5e1305e2 100644 --- a/src/c3nav/editor/templates/editor/section.html +++ b/src/c3nav/editor/templates/editor/section.html @@ -11,3 +11,4 @@ « {% trans 'back to overview' %}

+{% include 'editor/fragment_child_models.html' %} diff --git a/src/c3nav/editor/templates/editor/space.html b/src/c3nav/editor/templates/editor/space.html new file mode 100644 index 00000000..5e1305e2 --- /dev/null +++ b/src/c3nav/editor/templates/editor/space.html @@ -0,0 +1,14 @@ +{% load bootstrap3 %} +{% load i18n %} +{% include 'editor/fragment_sections.html' %} + + + {% trans 'Section' as model_title %} + {% blocktrans %}Edit {{ model_title }}{% endblocktrans %} + +

{{ section.title }}

+

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

+ +{% include 'editor/fragment_child_models.html' %} diff --git a/src/c3nav/editor/urls.py b/src/c3nav/editor/urls.py index 75f0519b..c666e15f 100644 --- a/src/c3nav/editor/urls.py +++ b/src/c3nav/editor/urls.py @@ -3,13 +3,20 @@ from django.conf.urls import url from c3nav.editor.views import edit, list_objects, main_index, section_detail -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'^'+prefix+name+r'/$', list_objects, name='editor.'+name+'.list', kwargs={'model': model}), - url(r'^'+prefix+name+r'/(?P[0-9]+)/$', edit, name='editor.'+name+'.edit', kwargs={'model': model}), - url(r'^'+prefix+name+r'/create$', edit, name='editor.'+name+'.create', kwargs={'model': model}), - ] +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\d+)/'+explicit_edit+'$', edit, name=name_prefix+'edit', kwargs=kwargs), + url(r'^'+prefix+r'/create$', edit, name=name_prefix+'create', kwargs=kwargs), + ]) + return result urlpatterns = [ @@ -18,5 +25,7 @@ urlpatterns = [ 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'}), ] +urlpatterns.extend(add_editor_urls('sections', 'Section', with_list=False, explicit_edit=True)) urlpatterns.extend(add_editor_urls('locationgroups', 'LocationGroup')) +urlpatterns.extend(add_editor_urls('spaces', 'Space', 'sections', 'section', explicit_edit=True)) urlpatterns.extend(add_editor_urls('doors', 'Door', 'sections', 'section')) diff --git a/src/c3nav/editor/views.py b/src/c3nav/editor/views.py index 8b9e7cbf..6366be6f 100644 --- a/src/c3nav/editor/views.py +++ b/src/c3nav/editor/views.py @@ -8,7 +8,7 @@ from django.urls import reverse from django.utils.translation import ugettext_lazy as _ from django.views.decorators.cache import never_cache -from c3nav.mapdata.models import LocationGroup, Section +from c3nav.mapdata.models import Door, LocationGroup, Section, Space from c3nav.mapdata.models.base import EDITOR_FORM_MODELS @@ -170,20 +170,13 @@ def edit(request, pk=None, model=None, section=None, space=None, explicit_edit=F @sidebar_view -def list_objects(request, model=None, section=None, space=None): +def list_objects(request, model=None, section=None, space=None, explicit_edit=False): model = EDITOR_FORM_MODELS[model] if not request.resolver_match.url_name.endswith('.list'): raise ValueError('url_name does not end with .list') - reverse_kwargs = {} - if section is not None: - reverse_kwargs['section'] = section - if space is not None: - reverse_kwargs['space'] = space - # noinspection PyProtectedMember ctx = { - 'create_url': reverse(request.resolver_match.url_name[:-4]+'create', kwargs=reverse_kwargs), 'path': request.path, 'model_name': model.__name__.lower(), 'model_title': model._meta.verbose_name, @@ -191,23 +184,25 @@ def list_objects(request, model=None, section=None, space=None): } queryset = model.objects.all().order_by('id') - for obj in queryset: - reverse_kwargs['pk'] = obj.pk - obj.edit_url = reverse(request.resolver_match.url_name[:-4]+'edit', kwargs=reverse_kwargs) - reverse_kwargs.pop('pk', None) + reverse_kwargs = {} - if space is not None: - space = get_object_or_404(Section, pk=section) - queryset = queryset.filter(space=space) - ctx.update({ - 'back_url': reverse('editor.space', kwargs={'pk': space.pk}), - 'back_title': _('back to space'), - }) - elif section is not None: + if section is not None: + reverse_kwargs['section'] = section 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_title': _('back to section'), + 'sections': Section.objects.all(), + 'section': section, + 'section_url': request.resolver_match.url_name, + }) + elif space is not None: + reverse_kwargs['space'] = space + 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_title': _('back to space'), }) else: @@ -216,7 +211,14 @@ def list_objects(request, model=None, section=None, space=None): 'back_title': _('back to overview'), }) + edit_url_name = request.resolver_match.url_name[:-5]+('' if explicit_edit else '.edit') + for obj in queryset: + reverse_kwargs['pk'] = obj.pk + obj.edit_url = reverse(edit_url_name, kwargs=reverse_kwargs) + reverse_kwargs.pop('pk', None) + ctx.update({ + 'create_url': reverse(request.resolver_match.url_name[:-4] + 'create', kwargs=reverse_kwargs), 'objects': queryset, })