edit sections on top of other sections
This commit is contained in:
parent
5836219503
commit
cae31c3993
4 changed files with 31 additions and 7 deletions
|
@ -6,11 +6,19 @@
|
||||||
<a class="btn btn-sm {% if new %}btn-danger{% else %}btn-default{% endif %} pull-right" href="{{ back_url }}">
|
<a class="btn btn-sm {% if new %}btn-danger{% else %}btn-default{% endif %} pull-right" href="{{ back_url }}">
|
||||||
{% trans 'Cancel' %}
|
{% trans 'Cancel' %}
|
||||||
</a>
|
</a>
|
||||||
{% if new %}
|
|
||||||
<h3>{% blocktrans %}New {{ model_title }}{% endblocktrans %}</h3>
|
<h3>
|
||||||
{% else %}
|
{% if new %}
|
||||||
<h3>{% blocktrans %}Edit {{ model_title }}{% endblocktrans %}</h3>
|
{% blocktrans %}New {{ model_title }}{% endblocktrans %}
|
||||||
{% endif %}
|
{% else %}
|
||||||
|
{% blocktrans %}Edit {{ model_title }}{% endblocktrans %}
|
||||||
|
{% endif %}
|
||||||
|
{% if on_top_of %}
|
||||||
|
{% with on_top_of.title as on_top_of_section_title %}
|
||||||
|
<small>{% blocktrans %}on top of {{ on_top_of_section_title }}{% endblocktrans %}</small>
|
||||||
|
{% endwith %}
|
||||||
|
{% endif %}
|
||||||
|
</h3>
|
||||||
<form action="{{ path }}" method="post" data-onbeforeunload {% if new %}data-new="{{ model_name }}" data-geomtype="{{ geomtype }}"{% else %}data-editing="{{ model_name }}-{{ pk }}"{% endif %}>
|
<form action="{{ path }}" method="post" data-onbeforeunload {% if new %}data-new="{{ model_name }}" data-geomtype="{{ geomtype }}"{% else %}data-editing="{{ model_name }}-{{ pk }}"{% endif %}>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% bootstrap_form form %}
|
{% bootstrap_form form %}
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
{% include 'editor/fragment_child_models.html' %}
|
{% include 'editor/fragment_child_models.html' %}
|
||||||
|
|
||||||
{% if section.on_top_of == None %}
|
{% if section.on_top_of == None %}
|
||||||
<a class="btn btn-default btn-sm pull-right" accesskey="n" href="{{ create_url }}">
|
<a class="btn btn-default btn-sm pull-right" accesskey="n" href="{% url 'editor.sections_on_top.create' on_top_of=section.pk %}">
|
||||||
{% blocktrans %}New {{ model_title }}{% endblocktrans %}
|
{% blocktrans %}New {{ model_title }}{% endblocktrans %}
|
||||||
</a>
|
</a>
|
||||||
<h3>{% trans 'Sections on top' %}</h3>
|
<h3>{% trans 'Sections on top' %}</h3>
|
||||||
|
|
|
@ -32,6 +32,8 @@ 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.sections.detail'),
|
url(r'^sections/(?P<pk>[0-9]+)/$', section_detail, name='editor.sections.detail'),
|
||||||
url(r'^sections/(?P<section>[0-9]+)/spaces/(?P<pk>[0-9]+)/$', space_detail, name='editor.spaces.detail'),
|
url(r'^sections/(?P<section>[0-9]+)/spaces/(?P<pk>[0-9]+)/$', space_detail, name='editor.spaces.detail'),
|
||||||
|
url(r'^sections/(?P<on_top_of>[0-9]+)/sections_on_top/create$', edit, name='editor.sections_on_top.create',
|
||||||
|
kwargs={'model': 'Section'}),
|
||||||
]
|
]
|
||||||
urlpatterns.extend(add_editor_urls('Section', with_list=False, explicit_edit=True))
|
urlpatterns.extend(add_editor_urls('Section', with_list=False, explicit_edit=True))
|
||||||
urlpatterns.extend(add_editor_urls('LocationGroup'))
|
urlpatterns.extend(add_editor_urls('LocationGroup'))
|
||||||
|
|
|
@ -79,7 +79,7 @@ def space_detail(request, section, pk):
|
||||||
|
|
||||||
|
|
||||||
@sidebar_view
|
@sidebar_view
|
||||||
def edit(request, pk=None, model=None, section=None, space=None, explicit_edit=False):
|
def edit(request, pk=None, model=None, section=None, space=None, on_top_of=None, explicit_edit=False):
|
||||||
model = EDITOR_FORM_MODELS[model]
|
model = EDITOR_FORM_MODELS[model]
|
||||||
related_name = model._meta.default_related_name
|
related_name = model._meta.default_related_name
|
||||||
|
|
||||||
|
@ -98,6 +98,8 @@ def edit(request, pk=None, model=None, section=None, space=None, explicit_edit=F
|
||||||
section = get_object_or_404(Section, pk=section)
|
section = get_object_or_404(Section, pk=section)
|
||||||
elif space is not None:
|
elif space is not None:
|
||||||
space = get_object_or_404(Space, pk=space)
|
space = get_object_or_404(Space, pk=space)
|
||||||
|
elif on_top_of is not None:
|
||||||
|
on_top_of = get_object_or_404(Section.objects.filter(on_top_of__isnull=True), pk=on_top_of)
|
||||||
|
|
||||||
new = obj is None
|
new = obj is None
|
||||||
# noinspection PyProtectedMember
|
# noinspection PyProtectedMember
|
||||||
|
@ -123,6 +125,13 @@ def edit(request, pk=None, model=None, section=None, space=None, explicit_edit=F
|
||||||
if not new:
|
if not new:
|
||||||
ctx.update({
|
ctx.update({
|
||||||
'geometry_url': '/api/editor/geometries/?section='+str(obj.primary_section_pk),
|
'geometry_url': '/api/editor/geometries/?section='+str(obj.primary_section_pk),
|
||||||
|
'on_top_of': obj.on_top_of,
|
||||||
|
})
|
||||||
|
elif on_top_of:
|
||||||
|
ctx.update({
|
||||||
|
'geometry_url': '/api/editor/geometries/?section=' + str(on_top_of.pk),
|
||||||
|
'on_top_of': on_top_of,
|
||||||
|
'back_url': reverse('editor.sections.detail', kwargs={'pk': on_top_of.pk}),
|
||||||
})
|
})
|
||||||
elif model == Space and not new:
|
elif model == Space and not new:
|
||||||
ctx.update({
|
ctx.update({
|
||||||
|
@ -172,6 +181,8 @@ def edit(request, pk=None, model=None, section=None, space=None, explicit_edit=F
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
obj.delete()
|
obj.delete()
|
||||||
if model == Section:
|
if model == Section:
|
||||||
|
if obj.on_top_of_id is not None:
|
||||||
|
return redirect(reverse('editor.sections.detail', kwargs={'pk': obj.on_top_of_id}))
|
||||||
return redirect(reverse('editor.index'))
|
return redirect(reverse('editor.index'))
|
||||||
elif model == Space:
|
elif model == Space:
|
||||||
return redirect(reverse('editor.spaces.list', kwargs={'section': obj.section.pk}))
|
return redirect(reverse('editor.spaces.list', kwargs={'section': obj.section.pk}))
|
||||||
|
@ -206,6 +217,9 @@ def edit(request, pk=None, model=None, section=None, space=None, explicit_edit=F
|
||||||
if space is not None:
|
if space is not None:
|
||||||
obj.space = space
|
obj.space = space
|
||||||
|
|
||||||
|
if on_top_of is not None:
|
||||||
|
obj.on_top_of = on_top_of
|
||||||
|
|
||||||
obj.save()
|
obj.save()
|
||||||
form.save_m2m()
|
form.save_m2m()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue