navigate to secondary sections
This commit is contained in:
parent
9910b3ed83
commit
9f1f8c78ba
3 changed files with 40 additions and 10 deletions
|
@ -6,9 +6,34 @@
|
||||||
{% trans 'Section' as model_title %}
|
{% trans 'Section' as model_title %}
|
||||||
{% blocktrans %}Edit {{ model_title }}{% endblocktrans %}
|
{% blocktrans %}Edit {{ model_title }}{% endblocktrans %}
|
||||||
</a>
|
</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>
|
<p>
|
||||||
<a href="{% url 'editor.index' %}">« {% trans 'back to overview' %}</a>
|
{% if section.on_top_of == None %}
|
||||||
|
<a href="{% url 'editor.index' %}">« {% trans 'back to overview' %}</a>
|
||||||
|
{% else %}
|
||||||
|
<a href="{% url 'editor.sections.detail' pk=section.on_top_of.pk %}">« {% trans 'back to parent section' %}</a>
|
||||||
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{% include 'editor/fragment_child_models.html' %}
|
{% 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 %}
|
||||||
|
|
|
@ -39,7 +39,7 @@ def child_model(model_name, kwargs=None, parent=None):
|
||||||
@sidebar_view
|
@sidebar_view
|
||||||
def main_index(request):
|
def main_index(request):
|
||||||
return render(request, 'editor/index.html', {
|
return render(request, 'editor/index.html', {
|
||||||
'sections': Section.objects.filter(on_top_of__isnull=True),
|
'sections': Section.objects.all(),
|
||||||
'child_models': [
|
'child_models': [
|
||||||
child_model('LocationGroup'),
|
child_model('LocationGroup'),
|
||||||
child_model('Source'),
|
child_model('Source'),
|
||||||
|
@ -49,17 +49,18 @@ def main_index(request):
|
||||||
|
|
||||||
@sidebar_view
|
@sidebar_view
|
||||||
def section_detail(request, pk):
|
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', {
|
return render(request, 'editor/section.html', {
|
||||||
'sections': Section.objects.filter(on_top_of__isnull=True),
|
'sections': Section.objects.all(),
|
||||||
'section': section,
|
'section': section,
|
||||||
'section_url': 'editor.sections.detail',
|
'section_url': 'editor.sections.detail',
|
||||||
'section_as_pk': True,
|
'section_as_pk': True,
|
||||||
|
|
||||||
'child_models': [child_model(model_name, kwargs={'section': pk}, parent=section)
|
'child_models': [child_model(model_name, kwargs={'section': pk}, parent=section)
|
||||||
for model_name in ('Building', 'Space', 'Door')],
|
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:
|
if not new:
|
||||||
ctx.update({
|
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:
|
elif model == Space and not new:
|
||||||
ctx.update({
|
ctx.update({
|
||||||
|
@ -133,7 +134,7 @@ def edit(request, pk=None, model=None, section=None, space=None, explicit_edit=F
|
||||||
ctx.update({
|
ctx.update({
|
||||||
'section': section,
|
'section': section,
|
||||||
'back_url': reverse('editor.spaces.list', kwargs={'section': section.pk}),
|
'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'):
|
elif hasattr(model, 'section'):
|
||||||
if obj:
|
if obj:
|
||||||
|
@ -141,7 +142,7 @@ def edit(request, pk=None, model=None, section=None, space=None, explicit_edit=F
|
||||||
ctx.update({
|
ctx.update({
|
||||||
'section': section,
|
'section': section,
|
||||||
'back_url': reverse('editor.'+related_name+'.list', kwargs={'section': section.pk}),
|
'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'):
|
elif hasattr(model, 'space'):
|
||||||
if obj:
|
if obj:
|
||||||
|
@ -247,7 +248,7 @@ def list_objects(request, model=None, section=None, space=None, explicit_edit=Fa
|
||||||
'sections': Section.objects.all(),
|
'sections': Section.objects.all(),
|
||||||
'section': section,
|
'section': section,
|
||||||
'section_url': request.resolver_match.url_name,
|
'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:
|
elif space is not None:
|
||||||
reverse_kwargs['space'] = space
|
reverse_kwargs['space'] = space
|
||||||
|
|
|
@ -36,6 +36,10 @@ class Section(SpecificLocation, EditorFormMixin, models.Model):
|
||||||
raise TypeError
|
raise TypeError
|
||||||
return Section.objects.filter(altitude__gt=self.altitude, on_top_of__isnull=True).order_by('altitude')
|
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):
|
def _serialize(self, section=True, **kwargs):
|
||||||
result = super()._serialize(**kwargs)
|
result = super()._serialize(**kwargs)
|
||||||
result['altitude'] = float(str(self.altitude))
|
result['altitude'] = float(str(self.altitude))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue