edit Location Groups
This commit is contained in:
parent
da8d29766c
commit
2a7b997980
4 changed files with 86 additions and 1 deletions
|
@ -14,3 +14,8 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="locationgroup">
|
||||||
|
<a href="{% url 'editor.locationgroups.list' %}" class="list-group-item">
|
||||||
|
Locationgroups
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
33
src/c3nav/editor/templates/editor/list.html
Normal file
33
src/c3nav/editor/templates/editor/list.html
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
{% load bootstrap3 %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% include 'editor/fragment_sections.html' %}
|
||||||
|
|
||||||
|
<a class="btn btn-default btn-sm pull-right" accesskey="n" href="{% url create_url %}">
|
||||||
|
{% blocktrans %}New {{ model_title }}{% endblocktrans %}
|
||||||
|
</a>
|
||||||
|
<h3>{% blocktrans %}{{ model_title_plural }}{% endblocktrans %}</h3>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<table class="table table-condensed itemtable" data-model="{{ model_name }}">
|
||||||
|
<tbody>
|
||||||
|
{% for item in objects %}
|
||||||
|
{% if forloop.counter0|divisibleby:10 %}
|
||||||
|
<tr>
|
||||||
|
<td><a href="{{ back_url }}">« {{ back_title }}</a></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
<tr data-pk="{{ item.pk }}">
|
||||||
|
<td>{{ item.title }}</td>
|
||||||
|
<td><a href="{% url edit_url pk=item.pk %}">{% trans 'Edit' %}</a></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
<tr>
|
||||||
|
<td><a href="{{ back_url }}">« {{ back_title }}</a></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
|
@ -1,10 +1,13 @@
|
||||||
from django.conf.urls import url
|
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 = [
|
urlpatterns = [
|
||||||
url(r'^$', main_index, name='editor.index'),
|
url(r'^$', main_index, name='editor.index'),
|
||||||
url(r'^sections/(?P<pk>[0-9]+)/$', section_detail, name='editor.section'),
|
url(r'^sections/(?P<pk>[0-9]+)/$', section_detail, name='editor.section'),
|
||||||
url(r'^sections/(?P<pk>[0-9]+)/edit$', edit, name='editor.section.edit', kwargs={'model': 'Section'}),
|
url(r'^sections/(?P<pk>[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/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<pk>[0-9]+)/$', edit, name='editor.locationgroups.edit', kwargs={'model': 'LocationGroup'}),
|
||||||
|
url(r'^locationgroups/create$', edit, name='editor.locationgroups.create', kwargs={'model': 'LocationGroup'}),
|
||||||
]
|
]
|
||||||
|
|
|
@ -5,6 +5,7 @@ from django.core.exceptions import PermissionDenied
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.views.decorators.cache import never_cache
|
from django.views.decorators.cache import never_cache
|
||||||
|
|
||||||
from c3nav.mapdata.models import Section
|
from c3nav.mapdata.models import Section
|
||||||
|
@ -77,6 +78,13 @@ def edit(request, pk=None, model=None):
|
||||||
'section': obj.space.section,
|
'section': obj.space.section,
|
||||||
'back_url': reverse('editor.space', kwargs={'pk': obj.space.pk}),
|
'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 request.method == 'POST':
|
||||||
if obj is not None and request.POST.get('delete') == '1':
|
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)
|
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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue