cleanup templates, reuse more blocks

This commit is contained in:
j 2017-12-23 12:06:13 +01:00
parent 068d9f4201
commit f25482a3e1
11 changed files with 169 additions and 333 deletions

View File

@ -0,0 +1,19 @@
{% extends 'base.html' %}
{% block content %}
{% include "edit.html" %}
<div class="large-8 medium-8 columns special-column">
{% if content.image %}
<img src="{{ content.image_url }}">
{% endif %}
<div class="index-text">
<h4><a href="{{ content.get_absolute_url }}" class="big-title">{{content.title}}</a></h4>
<p> {{content.formatted_header|safe}} </p>
<p> {{content.formatted_body|safe}} </p>
{% include "opt.html" %}
{% include "links.html" %}
{% include "gallery.html" with gallery=content.gallery %}
</div>
</div>
{% include "latest_content.html" %}
{% endblock %}

View File

@ -1,10 +1,7 @@
{% extends 'base.html' %}
{% block content %}
{% include "edit.html" with content=events %}
<div class="large-8 medium-8 columns special-column">
{% if events.image %}
<img src="{{events.image_url}}">
@ -18,37 +15,5 @@
{% include "gallery.html" with gallery=gallery %}
</div>
</div>
<div class="large-4 medium-4 columns">
{% include "related.html" with related=events.children.all %}
<h4 class="sidebar-h4">Events </h4>
<div class="row">
{% for events in latest_content_list %}
<div class="row right-items">
<div class="small-6 columns">
<a href="{{ events.get_absolute_url }}/"> <img src="{{ events.image_url }}"> </a>
</div>
<div class="small-6 columns">
<a href="{{ events.get_absolute_url }}/" class="sidebar-title" >{{ events.title }}</a>
<h6 class="sidebar-date">
<font color="#ef4e5c">
<b> {{ events.datestart }} {% if events.dateend %} - {{events.dateend}} {% endif %} </b>
</font>
{% if events.place %}<br/>{{events.place}}{% endif%}
</h6>
<p> {{ events.formatted_teaser }} </p>
</div>
</div>
{% endfor %}
<a href="{% url 'events_list' %}">more</a>
</div>
</div>
{% include "latest_content.html" with content=events %}
{% endblock %}

View File

@ -0,0 +1,18 @@
{% if latest_content_list %}
<div class="large-4 medium-4 columns">
{% include "related.html" with related=content.children.all %}
<h4 class="sidebar-h4">{{section}}</h4>
<div class="row">
{% for content in latest_content_list %}
{% include "preview.html" with content=content %}
{% endfor %}
{% with section|lower|add:'_list' as section_list %}
{% if has_more_content %}
<a href="{% url section_list %}">more</a>
{% endif %}
{% endwith %}
</div>
</div>
{% else %}
<p>No content.</p>
{% endif %}

View File

@ -1,4 +1,3 @@
<div class="row">
<div class="row right-items">
<div class="small-6 columns">
{% if content.image_url %}
@ -18,4 +17,3 @@
<p> {{ content.formatted_teaser }} </p>
</div>
</div>
</div>

View File

@ -1,10 +1,7 @@
{% extends 'base.html' %}
{% block content %}
{% include "edit.html" with content=projects %}
<div class="large-8 medium-8 columns special-column">
{% if projects.image %}
<img src="{{ projects.image_url }}">
@ -18,30 +15,5 @@
{% include "gallery.html" with gallery=gallery %}
</div>
</div>
{% if latest_content_list %}
<div class="large-4 medium-4 columns">
{% include "related.html" with related=projects.children.all %}
<h4 class="sidebar-h4">Projects </h4>
<div class="row">
{% for projects in latest_content_list %}
<div class="row right-items">
<div class="small-6 columns">
<a href="{{ projects.get_absolute_url }}"> <img src="{{ projects.image_url }}"> </a>
</div>
<div class="small-6 columns">
<a href="{{ projects.get_absolute_url }}" class="sidebar-title">{{ projects.title }}</a>
<p> {{projects.formatted_teaser}} </p>
</div>
</div>
{% endfor %}
{% else %}
<p>No projects.</p>
{% endif %}
<a href="{% url 'projects_list' %}">more</a>
</div>
</div>
{% include "latest_content.html" with content=texts %}
{% endblock %}

View File

@ -1,7 +1,9 @@
{% if related %}
<h4 class="sidebar-h4"> Related </h4>
{% for content in related %}
<div class="row">
{% include "preview.html" %}
</div>
{% endfor %}
<br>
<br>

View File

@ -22,7 +22,7 @@
</h6>
</div>
</div>
{% elif row.type.name == 'events' %}
{% else %}
<div class="row results">
<div class="small-4 small-offset-2 columns">
{% if row.image_url %}
@ -31,59 +31,14 @@
</div>
<div class="small-4 end columns">
<a href="{{ row.get_absolute_url }}" class="sidebar-title">{{ row.title }}</a>
{% if row.type.name == 'events' %}
<h6 class="sidebar-date"> <font color="#ef4e5c"> <b> {{ row.datestart }} {% if row.dateend %} - {{row.dateend}} {% endif %} </b></font>
{% if row.place %}<br/> {{row.place}} {% endif%}</h6>
{% endif %}
<p> {{row.formatted_teaser}} </p>
<a href="{{ row.get_absolute_url }}">read more</a> </p>
</div>
</div>
{% elif row.type.name == 'projects' %}
<div class="row results">
<div class="small-4 small-offset-2 columns">
{% if row.image_url %}
<a href="{{ row.get_absolute_url }}"> <img src="{{ row.image_url }}"> </a>
{% endif %}
</div>
<div class="small-4 end columns">
<a href="{{ row.get_absolute_url }}" class="sidebar-title">{{ row.title }}</a>
<p> {{row.formatted_teaser}} </p>
<a href="{{ row.get_absolute_url }}">read more</a> </p>
</div>
</div>
{% elif row.type.name == 'works' %}
<div class="row results">
<div class="small-4 small-offset-2 columns">
{% if row.image_url %}
<a href="{{ row.get_absolute_url }}"> <img src="{{ row.image_url }}"> </a>
{% endif %}
</div>
<div class="small-4 end columns">
<a href="{{ row.get_absolute_url }}" class="sidebar-title">{{ row.title }}</a>
<p> {{row.formatted_teaser}} </p>
<a href="{{ row.get_absolute_url }}">read more</a> </p>
</div>
</div>
{% elif row.type.name == 'texts' %}
<div class="row results">
<div class="small-4 small-offset-2 columns">
{% if row.image_url %}
<a href="{{ row.get_absolute_url }}"> <img src="{{ row.image_url }}"> </a>
{% endif %}
</div>
<div class="small-4 end columns">
<a href="{{ row.get_absolute_url }}" class="sidebar-title">{{ row.title }}</a>
<p> {{row.formatted_teaser}} </p>
<a href="{{ row.get_absolute_url }}">read more</a> </p>
</div>
</div>
{% else %}
{% if request.user.is_staff %}
<div class="row">
<div class="small-4 small-offset-2 columns">
Add view for content type: {{row.type}}
</div>
</div>
{% endif %}
{% endif %}
{% endfor %}
<br>

View File

@ -2,7 +2,6 @@
{% block content %}
{% include "edit.html" with content=texts %}
<div class="large-8 medium-8 columns special-column">
{% if texts.image %}
<img src="{{ texts.image_url }}">
@ -14,46 +13,5 @@
{% include "opt.html" with content=texts %}
</div>
</div>
{% if latest_content_list %}
<div class="large-4 medium-4 columns">
{% if texts.children.all %}
<h4 class="sidebar-h4"> Related </h4>
{% for child in texts.children.all %}
<div class="row related-row">
{% if child.image %}
<div class="small-6 columns">
<a href="{{ child.get_absolute_url }}"> <img src="{{ child.image_url }}"> </a>
</div>
{% endif %}
<div class="small-6 columns">
<h6><a href="{{ child.get_absolute_url }}" class="sidebar-title"> {{child}} </a> </h6>
</div>
</div>
{% endfor %}
{% endif %}
<h4 class="sidebar-h4"> Texts </h4>
<div class="row">
{% for texts in latest_content_list %}
<div class="row right-items">
{% if texts.image %}
<div class="small-6 columns">
<a href="{{ texts.get_absolute_url }}"> <img src="{{ texts.image_url }}"></a>
</div>
{% endif %}
<div class="small-6 columns">
<a href="{{ texts.get_absolute_url }}" class="sidebar-title">{{ texts.title }}</a>
<p> {{ texts.formatted_teaser }} </p>
</div>
</div>
{% endfor %}
{% else %}
<p>No texts.</p>
{% endif %}
<a href="{% url 'texts_list' %}">more</a>
</div>
</div>
{% include "latest_content.html" with content=texts %}
{% endblock %}

View File

@ -1,53 +1,19 @@
{% extends 'base.html' %}
{% block content %}
{% include "edit.html" with content=works %}
<div class="large-8 medium-8 columns special-column">
{% if works.image %}
<img src="{{ works.image_url }}">
{% endif %}
<div class="index-text">
<h4><a href="{{ works.get_absolute_url }}" class="big-title">{{works.title}} </a></h4>
<p> {{works.formatted_header|safe}} </p>
<p> {{works.formatted_body|safe}} </p>
{% include "opt.html" with content=works %}
{% include "links.html" with content=projects %}
{% include "gallery.html" with gallery=gallery %}
</div>
</div>
{% if latest_content_list %}
<div class="large-4 medium-4 columns">
{% if works.children.all %}
<h4 class="sidebar-h4"> Related </h4>
{% for child in works.children.all %}
<div class="row related-row">
<div class="small-6 columns">
<a href="{{ child.get_absolute_url }}"> <img src="{{ child.image_url }}"> </a>
</div>
<div class="small-6 columns">
<h6><a href="{{ child.get_absolute_url }}" class="sidebar-title"> {{child}} </a> </h6>
</div>
</div>
{% endfor %}
{% endif %}
<h4 class="sidebar-h4"> Works </h4>
<div class="row">
{% for works in latest_content_list %}
<div class="row right-items">
<div class="small-6 columns">
<a href="{{ works.get_absolute_url }}"> <img src="{{ works.image_url }}"></a>
</div>
<div class="small-6 columns">
<a href="{{ works.get_absolute_url }}" class="sidebar-title">{{ works.title }}</a>
<p> {{ works.formatted_teaser }} </p>
</div>
</div>
{% endfor %}
{% else %}
<p>No works.</p>
{% endif %}
<a href="{% url 'works_list' %}">more</a>
</div>
</div>
{% include "latest_content.html" with content=works %}
{% endblock %}

View File

@ -84,9 +84,9 @@ def section_list(request, section):
return render(request, 'results.html', {
'base_query': base_query,
'section': section,
'content': content,
'query': q
'query': q,
'section': section,
})
def event(request):
@ -107,71 +107,53 @@ def event(request):
'ongoing_events': ongoing_events,
'past_events': past_events,
'featured': featured,
'section': 'Events',
}
return render(request, 'event.html', context)
def events(request, shortname=None):
def get_related_content(types, current=None, max_length=10):
latest_content_list = Content.objects.filter(type__name__in=types).order_by('-datestart')
if current:
latest_content_list = latest_content_list.exclude(pk=current.pk)
latest_content_list = latest_content_list.filter(published=True)
more = latest_content_list.count > max_length
latest_content_list = latest_content_list[:max_length]
return latest_content_list, more
def render_content(request, shortname, section, template, types):
if not shortname:
if section == 'Events':
return event(request)
events = get_object_or_404(Content, shortname=shortname, type__name__in=['news', 'events'])
if not events.published and not request.user.is_staff:
else:
return section_index(request, section)
content = get_object_or_404(Content, shortname=shortname, type__name__in=types)
if not content.published and not request.user.is_staff:
raise Http404
gallery = get_or_none(Gallery, slug=shortname)
latest_content_list = Content.objects.filter(type__name__in=['events', 'news']).order_by('-datestart')
latest_content_list = latest_content_list.exclude(pk=events.pk)
latest_content_list = latest_content_list[:10]
return render(request, 'events.html', {
'events': events,
latest_content_list, more = get_related_content(types, content)
return render(request, template, {
'content': content,
'latest_content_list': latest_content_list,
'gallery': gallery
'has_more_content': more,
'section': section,
})
def events(request, shortname=None):
return render_content(request, shortname, 'Events', 'content.html', ['events', 'news'])
def projects(request, shortname=None):
if not shortname:
return section_index(request, 'Projects')
projects = get_object_or_404(Content, shortname=shortname, type__name='projects')
if not projects.published and not request.user.is_staff:
raise Http404
gallery = get_or_none(Gallery, slug=shortname)
latest_content_list = Content.objects.filter(type__name='projects').order_by('-datestart')
latest_content_list = latest_content_list.exclude(pk=projects.pk)
latest_content_list = latest_content_list[:10]
return render(request, 'projects.html', {
'projects': projects,
'latest_content_list': latest_content_list,
'gallery': gallery
})
return render_content(request, shortname, 'Projects', 'content.html', ['projects'])
def works(request, shortname=None):
if not shortname:
return section_index(request, 'Works')
works = get_object_or_404(Content, shortname=shortname, type__name='works')
if not works.published and not request.user.is_staff:
raise Http404
gallery = get_or_none(Gallery, slug=shortname)
latest_content_list = Content.objects.filter(type__name='works')
latest_content_list = latest_content_list.exclude(pk=works.pk)
latest_content_list = latest_content_list[:10]
return render(request, 'works.html', {
'works': works,
'latest_content_list': latest_content_list,
'gallery': gallery
})
return render_content(request, shortname, 'Works', 'content.html', ['works'])
def texts(request, shortname=None):
if not shortname:
return section_index(request, 'Texts')
texts = get_object_or_404(Content, shortname=shortname, type__name='texts')
gallery = get_or_none(Gallery, slug=shortname)
latest_content_list = Content.objects.filter(type__name='texts')
latest_content_list = latest_content_list.exclude(pk=texts.pk)
latest_content_list = latest_content_list[:10]
return render(request, 'texts.html', {
'texts': texts,
'latest_content_list': latest_content_list,
'gallery': gallery
})
return render_content(requests, shortname, 'Texts', 'content.html', ['texts'])
def page(request, shortname):
@ -186,6 +168,7 @@ def limit_content(content, q):
content = content.filter(Q(body__icontains=q) | Q(title__icontains=q) | Q(header__icontains=q)).distinct()
return content
def search(request):
content = Content.objects.filter(published=True).order_by('-datestart')
content = content.exclude(type__name__in=['page', 'homepage'])