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,11 +1,8 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block content %} {% block content %}
{% include "edit.html" with content=events %} {% include "edit.html" with content=events %}
<div class="large-8 medium-8 columns special-column">
<div class="large-8 medium-8 columns special-column">
{% if events.image %} {% if events.image %}
<img src="{{events.image_url}}"> <img src="{{events.image_url}}">
{% endif %} {% endif %}
@ -16,39 +13,7 @@
{% include "opt.html" with content=events %} {% include "opt.html" with content=events %}
{% include "links.html" with content=events %} {% include "links.html" with content=events %}
{% include "gallery.html" with gallery=gallery %} {% 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>
</div> </div>
{% include "latest_content.html" with content=events %}
{% endfor %}
<a href="{% url 'events_list' %}">more</a>
</div>
</div>
{% endblock %} {% 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,5 +1,4 @@
<div class="row"> <div class="row right-items">
<div class="row right-items">
<div class="small-6 columns"> <div class="small-6 columns">
{% if content.image_url %} {% if content.image_url %}
<a href="{{ content.get_absolute_url }}"><img src="{{ content.image_url }}"></a> <a href="{{ content.get_absolute_url }}"><img src="{{ content.image_url }}"></a>
@ -17,5 +16,4 @@
{% endif %} {% endif %}
<p> {{ content.formatted_teaser }} </p> <p> {{ content.formatted_teaser }} </p>
</div> </div>
</div>
</div> </div>

View File

@ -1,11 +1,8 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block content %} {% block content %}
{% include "edit.html" with content=projects %} {% include "edit.html" with content=projects %}
<div class="large-8 medium-8 columns special-column">
<div class="large-8 medium-8 columns special-column">
{% if projects.image %} {% if projects.image %}
<img src="{{ projects.image_url }}"> <img src="{{ projects.image_url }}">
{% endif %} {% endif %}
@ -16,32 +13,7 @@
{% include "opt.html" with content=projects %} {% include "opt.html" with content=projects %}
{% include "links.html" with content=projects %} {% include "links.html" with content=projects %}
{% include "gallery.html" with gallery=gallery %} {% 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>
</div> </div>
{% endfor %} {% include "latest_content.html" with content=texts %}
{% else %}
<p>No projects.</p>
{% endif %}
<a href="{% url 'projects_list' %}">more</a>
</div>
</div>
{% endblock %} {% endblock %}

View File

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

View File

@ -22,7 +22,7 @@
</h6> </h6>
</div> </div>
</div> </div>
{% elif row.type.name == 'events' %} {% else %}
<div class="row results"> <div class="row results">
<div class="small-4 small-offset-2 columns"> <div class="small-4 small-offset-2 columns">
{% if row.image_url %} {% if row.image_url %}
@ -31,59 +31,14 @@
</div> </div>
<div class="small-4 end columns"> <div class="small-4 end columns">
<a href="{{ row.get_absolute_url }}" class="sidebar-title">{{ row.title }}</a> <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> <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> {% if row.place %}<br/> {{row.place}} {% endif%}</h6>
{% endif %}
<p> {{row.formatted_teaser}} </p> <p> {{row.formatted_teaser}} </p>
<a href="{{ row.get_absolute_url }}">read more</a> </p> <a href="{{ row.get_absolute_url }}">read more</a> </p>
</div> </div>
</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 %} {% endif %}
{% endfor %} {% endfor %}
<br> <br>

View File

@ -2,8 +2,7 @@
{% block content %} {% block content %}
{% include "edit.html" with content=texts %} {% include "edit.html" with content=texts %}
<div class="large-8 medium-8 columns special-column">
<div class="large-8 medium-8 columns special-column">
{% if texts.image %} {% if texts.image %}
<img src="{{ texts.image_url }}"> <img src="{{ texts.image_url }}">
{% endif %} {% endif %}
@ -12,48 +11,7 @@
<p> {{texts.formatted_header|safe}} </p> <p> {{texts.formatted_header|safe}} </p>
<p> {{texts.formatted_body|safe}} </p> <p> {{texts.formatted_body|safe}} </p>
{% include "opt.html" with content=texts %} {% 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>
</div> </div>
{% endfor %} {% include "latest_content.html" with content=texts %}
{% 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>
{% endblock %} {% endblock %}

View File

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

View File

@ -25,7 +25,7 @@ def index(request):
base = base.filter(published=True) base = base.filter(published=True)
upcoming_events = base.filter(datestart__gt=now)[:12] upcoming_events = base.filter(datestart__gt=now)[:12]
ongoing_events = base.filter(datestart__lt=now, dateend__gte=now)[:12] ongoing_events = base.filter(datestart__lt=now, dateend__gte=now)[:12]
past_events = base.filter(Q(dateend__lt=now)|Q(dateend=None, datestart__lt=now))[:12] past_events = base.filter(Q(dateend__lt=now) | Q(dateend=None, datestart__lt=now))[:12]
homepage = Content.objects.filter(type__name='homepage').order_by('-datestart')[:1] homepage = Content.objects.filter(type__name='homepage').order_by('-datestart')[:1]
context = { context = {
@ -84,9 +84,9 @@ def section_list(request, section):
return render(request, 'results.html', { return render(request, 'results.html', {
'base_query': base_query, 'base_query': base_query,
'section': section,
'content': content, 'content': content,
'query': q 'query': q,
'section': section,
}) })
def event(request): def event(request):
@ -107,71 +107,53 @@ def event(request):
'ongoing_events': ongoing_events, 'ongoing_events': ongoing_events,
'past_events': past_events, 'past_events': past_events,
'featured': featured, 'featured': featured,
'section': 'Events',
} }
return render(request, 'event.html', context) 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 not shortname:
if section == 'Events':
return event(request) return event(request)
events = get_object_or_404(Content, shortname=shortname, type__name__in=['news', 'events']) else:
if not events.published and not request.user.is_staff: 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 raise Http404
gallery = get_or_none(Gallery, slug=shortname) latest_content_list, more = get_related_content(types, content)
latest_content_list = Content.objects.filter(type__name__in=['events', 'news']).order_by('-datestart') return render(request, template, {
latest_content_list = latest_content_list.exclude(pk=events.pk) 'content': content,
latest_content_list = latest_content_list[:10]
return render(request, 'events.html', {
'events': events,
'latest_content_list': latest_content_list, '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): def projects(request, shortname=None):
if not shortname: return render_content(request, shortname, 'Projects', 'content.html', ['projects'])
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
})
def works(request, shortname=None): def works(request, shortname=None):
if not shortname: return render_content(request, shortname, 'Works', 'content.html', ['works'])
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
})
def texts(request, shortname=None): def texts(request, shortname=None):
if not shortname: return render_content(requests, shortname, 'Texts', 'content.html', ['texts'])
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
})
def page(request, shortname): 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() content = content.filter(Q(body__icontains=q) | Q(title__icontains=q) | Q(header__icontains=q)).distinct()
return content return content
def search(request): def search(request):
content = Content.objects.filter(published=True).order_by('-datestart') content = Content.objects.filter(published=True).order_by('-datestart')
content = content.exclude(type__name__in=['page', 'homepage']) content = content.exclude(type__name__in=['page', 'homepage'])