From 2a7b99798036f0e9e0d4bee75f3bad836169b5e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Kl=C3=BCnder?= Date: Tue, 16 May 2017 17:45:56 +0200 Subject: [PATCH] edit Location Groups --- src/c3nav/editor/templates/editor/index.html | 5 +++ src/c3nav/editor/templates/editor/list.html | 33 +++++++++++++++ src/c3nav/editor/urls.py | 5 ++- src/c3nav/editor/views.py | 44 ++++++++++++++++++++ 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/c3nav/editor/templates/editor/list.html diff --git a/src/c3nav/editor/templates/editor/index.html b/src/c3nav/editor/templates/editor/index.html index 2eb4866d..cf3e821a 100644 --- a/src/c3nav/editor/templates/editor/index.html +++ b/src/c3nav/editor/templates/editor/index.html @@ -14,3 +14,8 @@ {% endfor %} +
+ + Locationgroups + +
diff --git a/src/c3nav/editor/templates/editor/list.html b/src/c3nav/editor/templates/editor/list.html new file mode 100644 index 00000000..21491fd9 --- /dev/null +++ b/src/c3nav/editor/templates/editor/list.html @@ -0,0 +1,33 @@ +{% load bootstrap3 %} +{% load i18n %} + +{% include 'editor/fragment_sections.html' %} + + + {% blocktrans %}New {{ model_title }}{% endblocktrans %} + +

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

+

+ +

+ + + + {% for item in objects %} + {% if forloop.counter0|divisibleby:10 %} + + + + + {% endif %} + + + + + {% endfor %} + + + + + +
« {{ back_title }}
{{ item.title }}{% trans 'Edit' %}
« {{ back_title }}
diff --git a/src/c3nav/editor/urls.py b/src/c3nav/editor/urls.py index 36771b5d..b06f1b02 100644 --- a/src/c3nav/editor/urls.py +++ b/src/c3nav/editor/urls.py @@ -1,10 +1,13 @@ from django.conf.urls import url -from c3nav.editor.views import edit, main_index, section_detail +from c3nav.editor.views import edit, list_objects, main_index, section_detail 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'^locationgroups/$', list_objects, name='editor.locationgroups.list', kwargs={'model': 'LocationGroup'}), + url(r'^locationgroups/(?P[0-9]+)/$', edit, name='editor.locationgroups.edit', kwargs={'model': 'LocationGroup'}), + url(r'^locationgroups/create$', edit, name='editor.locationgroups.create', kwargs={'model': 'LocationGroup'}), ] diff --git a/src/c3nav/editor/views.py b/src/c3nav/editor/views.py index 2782ff57..13d613ec 100644 --- a/src/c3nav/editor/views.py +++ b/src/c3nav/editor/views.py @@ -5,6 +5,7 @@ from django.core.exceptions import PermissionDenied from django.http import HttpResponseRedirect from django.shortcuts import get_object_or_404, redirect, render 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 Section @@ -77,6 +78,13 @@ def edit(request, pk=None, model=None): 'section': obj.space.section, 'back_url': reverse('editor.space', kwargs={'pk': obj.space.pk}), }) + else: + if not request.resolver_match.url_name.endswith('.edit'): + raise ValueError('url_name does not end with .edit') + ctx.update({ + 'back_url': reverse(request.resolver_match.url_name[:-4]+'list'), + }) + if request.method == 'POST': if obj is not None and request.POST.get('delete') == '1': @@ -118,3 +126,39 @@ def edit(request, pk=None, model=None): }) return render(request, 'editor/edit.html', ctx) + + +@sidebar_view +def list_objects(request, model=None, section=None, space=None): + model = EDITOR_FORM_MODELS[model] + if not request.resolver_match.url_name.endswith('.list'): + raise ValueError('url_name does not end with .list') + + # noinspection PyProtectedMember + ctx = { + 'create_url': request.resolver_match.url_name[:-4]+'create', + 'edit_url': request.resolver_match.url_name[:-4]+'edit', + 'path': request.path, + 'model_name': model.__name__.lower(), + 'model_title': model._meta.verbose_name, + 'model_title_plural': model._meta.verbose_name_plural, + 'objects': model.objects.all().order_by('id'), + } + + if space is not None: + ctx.update({ + 'back_url': reverse('editor.space', kwargs={'pk': space}), + 'back_title': _('back to space'), + }) + elif section is not None: + ctx.update({ + 'back_url': reverse('editor.space', kwargs={'pk': space}), + 'back_title': _('back to space'), + }) + else: + ctx.update({ + 'back_url': reverse('editor.index'), + 'back_title': _('back to overview'), + }) + + return render(request, 'editor/list.html', ctx)