navigate to secondary sections

This commit is contained in:
Laura Klünder 2017-06-10 23:04:28 +02:00
parent 9910b3ed83
commit 9f1f8c78ba
3 changed files with 40 additions and 10 deletions

View file

@ -6,9 +6,34 @@
{% trans 'Section' as model_title %}
{% blocktrans %}Edit {{ model_title }}{% endblocktrans %}
</a>
<h3>{{ section.title }}</h3>
<h3>
{{ section.title }}
{% if section.on_top_of != None %}
{% with section.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>
<p>
<a href="{% url 'editor.index' %}">&laquo; {% trans 'back to overview' %}</a>
{% if section.on_top_of == None %}
<a href="{% url 'editor.index' %}">&laquo; {% trans 'back to overview' %}</a>
{% else %}
<a href="{% url 'editor.sections.detail' pk=section.on_top_of.pk %}">&laquo; {% trans 'back to parent section' %}</a>
{% endif %}
</p>
{% include 'editor/fragment_child_models.html' %}
{% if section.on_top_of == None %}
<a class="btn btn-default btn-sm pull-right" accesskey="n" href="{{ create_url }}">
{% blocktrans %}New {{ model_title }}{% endblocktrans %}
</a>
<h3>{% trans 'Sections on top' %}</h3>
<div class="list-group">
{% for s in sections_on_top %}
<a href="{% url 'editor.sections.detail' pk=s.pk %}" class="list-group-item">
{{ s.title }}
</a>
{% endfor %}
</div>
{% endif %}

View file

@ -39,7 +39,7 @@ def child_model(model_name, kwargs=None, parent=None):
@sidebar_view
def main_index(request):
return render(request, 'editor/index.html', {
'sections': Section.objects.filter(on_top_of__isnull=True),
'sections': Section.objects.all(),
'child_models': [
child_model('LocationGroup'),
child_model('Source'),
@ -49,17 +49,18 @@ def main_index(request):
@sidebar_view
def section_detail(request, pk):
section = get_object_or_404(Section, pk=pk)
section = get_object_or_404(Section.objects.select_related('on_top_of'), pk=pk)
return render(request, 'editor/section.html', {
'sections': Section.objects.filter(on_top_of__isnull=True),
'sections': Section.objects.all(),
'section': section,
'section_url': 'editor.sections.detail',
'section_as_pk': True,
'child_models': [child_model(model_name, kwargs={'section': pk}, parent=section)
for model_name in ('Building', 'Space', 'Door')],
'geometry_url': '/api/editor/geometries/?section='+pk,
'sections_on_top': section.sections_on_top.all(),
'geometry_url': '/api/editor/geometries/?section='+str(section.primary_section_pk),
})
@ -121,7 +122,7 @@ def edit(request, pk=None, model=None, section=None, space=None, explicit_edit=F
})
if not new:
ctx.update({
'geometry_url': '/api/editor/geometries/?section='+pk,
'geometry_url': '/api/editor/geometries/?section='+str(section.primary_section_pk),
})
elif model == Space and not new:
ctx.update({
@ -133,7 +134,7 @@ def edit(request, pk=None, model=None, section=None, space=None, explicit_edit=F
ctx.update({
'section': section,
'back_url': reverse('editor.spaces.list', kwargs={'section': section.pk}),
'geometry_url': '/api/editor/geometries/?section='+str(section.pk),
'geometry_url': '/api/editor/geometries/?section='+str(section.primary_section_pk),
})
elif hasattr(model, 'section'):
if obj:
@ -141,7 +142,7 @@ def edit(request, pk=None, model=None, section=None, space=None, explicit_edit=F
ctx.update({
'section': section,
'back_url': reverse('editor.'+related_name+'.list', kwargs={'section': section.pk}),
'geometry_url': '/api/editor/geometries/?section='+str(section.pk),
'geometry_url': '/api/editor/geometries/?section='+str(section.primary_section_pk),
})
elif hasattr(model, 'space'):
if obj:
@ -247,7 +248,7 @@ def list_objects(request, model=None, section=None, space=None, explicit_edit=Fa
'sections': Section.objects.all(),
'section': section,
'section_url': request.resolver_match.url_name,
'geometry_url': '/api/editor/geometries/?section='+str(section.pk),
'geometry_url': '/api/editor/geometries/?section='+str(section.primary_section_pk),
})
elif space is not None:
reverse_kwargs['space'] = space

View file

@ -36,6 +36,10 @@ class Section(SpecificLocation, EditorFormMixin, models.Model):
raise TypeError
return Section.objects.filter(altitude__gt=self.altitude, on_top_of__isnull=True).order_by('altitude')
@property
def primary_section_pk(self):
return self.pk if self.on_top_of_id is None else self.on_top_of_id
def _serialize(self, section=True, **kwargs):
result = super()._serialize(**kwargs)
result['altitude'] = float(str(self.altitude))