Compare commits

...

14 Commits

Author SHA1 Message Date
root
f4f6b440b8 link to gallery, show related content for single photo page 2017-12-23 13:24:23 +00:00
root
01afa5aa3f related photos 2017-12-23 12:19:35 +00:00
root
daf305d123 more content 2017-12-23 11:22:39 +00:00
j
f25482a3e1 cleanup templates, reuse more blocks 2017-12-23 12:06:13 +01:00
j
068d9f4201 don't show current item in context, link to all 2017-12-23 00:06:44 +01:00
j
f7a5cdf532 results have rows 2017-12-22 23:29:10 +01:00
j
edde0cec38 results 2017-12-22 23:28:03 +01:00
j
774e749d46 dont show pages in search results 2017-12-22 23:24:48 +01:00
j
9f87135c5a per section index 2017-12-22 23:22:14 +01:00
vaishk
394580ed51 search bar 2017-12-23 02:50:19 +05:30
root
5b9d746ed7 more changes 2017-12-22 20:08:54 +00:00
root
1b916114de link to first content 2017-12-20 19:12:14 +00:00
vaishk
6f2df206c8 link gallery back to event 2017-12-21 00:14:11 +05:30
vaishk
c2c80641a8 Link back to event from gallery 2017-12-20 23:52:44 +05:30
20 changed files with 396 additions and 365 deletions

View File

@ -25,6 +25,7 @@ body, h1, h2, h3, h4, h5, h6 {
text-transform: uppercase;
font-size: 14px;
color: #ffffff;
padding-top: 20px;
}
.sidebar-title {
@ -114,7 +115,7 @@ ul.clearing-thumbs li {
.page-header {
margin-top: 30px;
padding-bottom: 20px;
line-height: 0.4em !important;
}
.thumbnail {
@ -155,3 +156,30 @@ ul.clearing-thumbs li {
table thead, table tbody, table tfoot {
background-color: #000;
}
.search-form[type=search] {
width: 15rem;
border: 0.125rem solid #e6e6e6;
box-shadow: 0 0 3.125rem rgba(0, 0, 0, 0.18);
border-radius: 0;
background-image: url("http://media.yardhouse.com/images/site/searchicon.png");
background-position: 4px center;
background-repeat: no-repeat;
background-color: #111111;
padding-left: 30px;
position: absolute;
color: #ffffff !important;
font-size: 10px !important;
top: 13px;
right: 110px;
height: 25px;
padding-top: 0;
padding-bottom: 0;
font-weight: 600;
}

View File

@ -36,6 +36,11 @@ urlpatterns = [
url(r'directions.html', RedirectView.as_view(url='/directions/')),
url(r'campstudio.html', RedirectView.as_view(url='/directions/')),
url(r'^texts/index/$', views.section_list, {'section': 'Texts'}, name='texts_list'),
url(r'^events/index/$', views.section_list, {'section': 'Events'}, name='events_list'),
url(r'^projects/index/$', views.section_list, {'section': 'Projects'}, name='projects_list'),
url(r'^works/index/$', views.section_list, {'section': 'Works'}, name='works_list'),
url(r'^texts/(?P<shortname>.+)/$', views.texts, name='texts'),
url(r'^events/(?P<shortname>.+)/$', views.events, name='events'),
url(r'^projects/(?P<shortname>.+)/$', views.projects, name='projects'),

View File

@ -35,7 +35,10 @@
</div>
</div>
</div>
<form method="get" action='/search/'>
<input type="search" name="q" class="search-form" value="{{query|default:""}}">
<input type="submit" style="visibility: hidden;" />
</form>
{% block content %}
{% endblock %}
@ -48,21 +51,34 @@
<script src="{% static "js/jquery.bxslider.js" %}"></script>
<script type="text/javascript">
$(document).ready(function(){
var slider = $('.slider1').bxSlider({
slider = $('.slider1').bxSlider({
adaptiveHeight : true,
pager : false,
});
document.querySelectorAll('.select-image').forEach(function(a) {
a.onclick = function(event) {
event.preventDefault();
slider.goToSlide(parseInt(this.dataset.id) - 1)
document.location.hash = '#' + this.dataset.id;
};
});
if (document.querySelectorAll('.select-image').length && document.location.hash.length) {
var slide = parseInt(document.location.hash.slice(1))
if (slide) {
slider.goToSlide(slide - 1)
}
}
$(document).keydown(function(e){
if (e.keyCode == 39) // Right arrow
{
slider.goToNextSlide();
slider && slider.goToNextSlide();
return false;
}
else if (e.keyCode == 37) // left arrow
{
slider.goToPrevSlide();
slider && slider.goToPrevSlide();
return false;
}
});

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,36 +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 %}
</div>
</div>
{% include "latest_content.html" with content=events %}
{% endblock %}

View File

@ -1,7 +1,7 @@
{% for content in featured %}
<div class="large-8 medium-8 columns special-column">
{% if content.image %}
<img src="{{ content.image_url }}">
<a href="{{ content.get_absolute_url }}"><img src="{{ content.image_url }}"> </a>
{% endif %}
<div class="index-text">
<h4><a href="{{ content.get_absolute_url }}" class="big-title">{{content.title}} </a></h4>

View File

@ -2,7 +2,7 @@
<h6><strong>Gallery: {{gallery.title}}</strong></h6>
<ul class="clearing-thumbs" data-clearing>
{% for photo in gallery.public %}
<li><a href="{{ photo.get_absolute_url }}"><img src="{{ photo.get_thumbnail_url }}"></a></li>
<li><a href="{{ gallery.get_absolute_url }}#{{forloop.counter}}"><img src="{{ photo.get_thumbnail_url }}"></a></li>
{% endfor %}
</ul>
{% endif %}

View File

@ -0,0 +1,18 @@
<div class="large-4 medium-4 columns">
{% include "related.html" with related=content.children.all %}
{% if latest_content_list %}
<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>
{% else %}
{% if 0 %}<p>No content.</p>{% endif %}
{% endif %}
</div>

View File

@ -1,12 +1,16 @@
{% if content.optbtn2 and content.opttext2 %}
{% if content.opttext2 %}
<div class="part2">
{% if content.optbtn2 %}
<h4>{{ content.optbtn2|safe }} </h4>
{% endif %}
<p>{{ content.opttext2|safe|linebreaks }}</p>
</div>
{% endif %}
{% if content.optbtn3 and content.opttext3 %}
{% if content.opttext3 %}
<div class="part3">
{% if content.optbtn3 %}
<h4>{{ content.optbtn3|safe }} </h4>
{% endif %}
<p>{{ content.opttext3|safe|linebreaks }}</p>
</div>
{% endif %}

View File

@ -1,6 +1,7 @@
{% extends 'base.html' %}
{% block content %}
{% include "edit.html" with content=content %}
<div class="large-8 medium-8 columns special-column">
<div class="index-text">
<h4>{{content.title}}</h4>
@ -12,6 +13,7 @@
<p>
{{content.formatted_body|safe}}
</p>
{% include "opt.html" with content=content %}
</div>
</div>
{% endblock %}

View File

@ -4,16 +4,39 @@
{% block title %}{{ gallery.title }}{% endblock %}
{% block content %}
<div class="row col-lg-12">
<h1 class="page-header">{{ gallery.title }}</h1>
<p class="muted"><small>{% trans "Published" %} {{ gallery.date_added }}</small></p>
{% if gallery.description %}{{ gallery.description|safe }}{% endif %}
<div class="row">
<div class="medium-9 columns">
{% if gallery.content.exists %}
<h6 class="page-header"><a href="{{ gallery.content.all.0.get_absolute_url }}">Back to {{ gallery.content.all.0.title }}</a></h6>
{% endif %}
<h5>{{ gallery.title }}</h5>
<ul class="slider1">
{% for photo in gallery.public %}
<a href="{{ photo.get_absolute_url }}">
<li id="slide-{{photo.slug}}">
<img src="{{ photo.get_display_url }}" alt="{{ photo.title }}">
<p>
{{ photo.caption|safe }}
{% if photo.caption %}<br>{%endif%}
<a href="{{ photo.image.url }}" target="_blank" >Link to original file</a>
</p>
</li>
{% endfor %}
</ul>
</div>
<div class="medium-3 columns">
<br>
<p>{% trans "Other photos" %}:</p>
<div>
{% for photo in gallery.public %}
<div style="float: left; padding: 4px">
<a href="{{ photo.get_absolute_url }}" class="select-image" data-id="{{forloop.counter}}">
<img src="{{ photo.get_thumbnail_url }}" class="thumbnail" alt="{{ photo.title }}">
</a>
</div>
{% endfor %}
<div><a href="{% url 'photologue:gallery-list' %}" class="btn btn-default">{% trans "View all galleries" %}</a></div>
</div>
</div>
</div>
{% endblock %}

View File

@ -4,42 +4,21 @@
{% block title %}{{ object.title }}{% endblock %}
{% block content %}
{% for gallery in object.public_galleries %}
<div class="row">
<div class="medium-9 columns">
<h5 class="page-header">From gallery {{ gallery.title }}</h5>
<ul class="slider1">
{% for photo.pk in gallery.public %}
<li>
<img src="{{ photo.get_display_url }}" alt="{{ photo.title }}">
<br /> <p>{{ photo.caption|safe }} <a href="{{ photo.image.url }}"> Link to original file </a> </p>
</li>
{% for photo in gallery.public %}
<li>
<img src="{{ photo.get_display_url }}" alt="{{ photo.title }}">
<br /> <p>{{ photo.caption|safe }} <a href="{{ photo.image.url }}" target="_blank" > Link to original file </a> </p>
</li>
{% endfor %}
<img src="{{ object.get_display_url }}" alt="{{ object.title }}">
<p>
{{ object.caption|safe }}
{% if object.caption %}<br>{%endif%}
<a href="{{ object.image.url }}" target="_blank" >Link to original file</a>
</p>
<ul>
{% for gallery in object.public_galleries %}
{% if gallery.content.exists %}
<li><a href="{{ gallery.content.all.0.get_absolute_url }}">{{ gallery.content.all.0.title }}</a></li>
{% endif %}
{% endfor %}
</ul>
</div>
<div class="medium-3 columns">
{% if object.public_galleries %}
<p>{% trans "Other photos in the gallery" %}:</p>
<table>
{% for photo in gallery.public %}
<tr>
<td><a href="{{ photo.get_absolute_url }}">
<img src="{{ photo.get_thumbnail_url }}" class="thumbnail" alt="{{ photo.title }}"></a></td>
<td>
<p>{{ photo.caption|safe }} {{ photo.count }} </p>
</td>
</tr>
{% endfor %}
</table>
{% endif %}
{% endfor %}
</div>
</div>
{% endblock %}

View File

@ -1,8 +1,17 @@
<div class="row">
<div class="row right-items">
{% if content.type.name == 'news' %}
<div class= "small-12 columns">
<h6 class="sidebar-date">
<font color="#ef4e5c"> <b> {{content.datestart}} </b>
{{ content.title }} <br />
{{ content.formatted_header }}
</font>
</h6>
</div>
{% else %}
<div class="small-6 columns">
{% if content.image_url %}
<img src="{{ content.image_url }}">
<a href="{{ content.get_absolute_url }}"><img src="{{ content.image_url }}"></a>
{% endif %}
</div>
<div class="small-6 columns">
@ -17,5 +26,5 @@
{% endif %}
<p> {{ content.formatted_teaser }} </p>
</div>
</div>
{% endif %}
</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,29 +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 %}
</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

@ -5,61 +5,62 @@
<div class="row">
<div class="row">
<div class="small-4 small-offset-2 columns results-title">
{% if section %}
<h3> {{section }}</h3>
{% else %}
<h3> Search results </h3>
{% endif %}
</div>
</div>
{% for content in results %}
{% if content.type.name == 'news' %}
{% for row in content %}
{% if row.type.name == 'news' %}
<div class="row">
<div class= "small-4 small-offset-2 columns">
<h6 class="sidebar-date"> <font color="#ef4e5c"> <b> {{content.datestart}} </b>
{{ content.title }} <br />
{{ content.formatted_header|striptags|safe }} </font>
<h6 class="sidebar-date"> <font color="#ef4e5c"> <b> {{row.datestart}} </b>
{{ row.title }} <br />
{{ row.formatted_header|striptags|safe }} </font>
</h6>
</div>
</div>
{% elif content.type.name == 'events' %}
{% else %}
<div class="row results">
<div class="small-4 small-offset-2 columns">
<img src="{{ content.image_url }}">
{% 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="{{ content.get_absolute_url }}" class="sidebar-title">{{ content.title }}</a>
<h6 class="sidebar-date"> <font color="#ef4e5c"> <b> {{ content.datestart }} {% if content.dateend %} - {{content.dateend}} {% endif %} </b></font>
{% if content.place %}<br/> {{content.place}} {% endif%}</h6>
<p> {{content.header|striptags|safe}} </p>
<a href="{{ content.get_absolute_url }}">read more</a> </p>
<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>
{% else %}
<div class="row">
<div class="small-4 small-offset-2 columns">
Add view for content type: {{content.type}}
</div>
</div>
{% endif %}
{% endfor %}
<br>
<br>
{% if results.has_other_pages %}
{% if content.has_other_pages %}
<div class="row">
<div class="small-4 small-offset-4 columns">
<ul class="pagination">
{% if results.has_previous %}
<li><a href="?q={{ query }}&page={{ results.previous_page_number }}">&laquo;</a></li>
{% if content.has_previous %}
<li><a href="?{{ base_query }}&page={{ content.previous_page_number }}">&laquo;</a></li>
{% else %}
<li class="disabled"><span>&laquo;</span></li>
{% endif %}
{% for i in results.paginator.page_range %}
{% if results.number == i %}
{% for i in content.paginator.page_range %}
{% if content.number == i %}
<li class="active"><span>{{ i }} <span class="sr-only">(current)</span></span></li>
{% else %}
<li><a href="?q={{ query }}&page={{ i }}">{{ i }}</a></li>
<li><a href="?{{ base_query }}page={{ i }}">{{ i }}</a></li>
{% endif %}
{% endfor %}
{% if results.has_next %}
<li><a href="?q={{ query }}&page={{ results.next_page_number }}">&raquo;</a></li>
{% if content.has_next %}
<li><a href="?{{ base_query }}page={{ content.next_page_number }}">&raquo;</a></li>
{% else %}
<li class="disabled"><span>&raquo;</span></li>
{% endif %}

View File

@ -4,6 +4,7 @@
{% include "featured.html" %}
<div class="large-4 medium-4 columns">
{% if content %}
<h4 class="sidebar-h4"> {{ section }} </h4>
<div class="row">
{% for content in content %}
@ -19,7 +20,11 @@
</div>
</div>
{% endfor %}
{% if more_content %}
<a href="index/">more</a>
{% endif %}
</div>
{% endif %}
</div>
{% endblock %}

View File

@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% 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 }}">
@ -13,45 +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.header|striptags|truncatechars:100}} </p>
</div>
</div>
{% endfor %}
{% else %}
<p>No texts.</p>
{% endif %}
</div>
</div>
{% include "latest_content.html" with content=texts %}
{% endblock %}

View File

@ -1,52 +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.header|striptags|truncatechars:100}} </p>
</div>
</div>
{% endfor %}
{% else %}
<p>No works.</p>
{% endif %}
</div>
</div>
{% include "latest_content.html" with content=works %}
{% endblock %}

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from datetime import datetime
from django.core.exceptions import ObjectDoesNotExist
@ -35,21 +36,65 @@ def index(request):
return render(request, 'index.html', context)
def section_index(request, types, section):
featured = Content.objects.filter(type__name__in=types, featured=True).order_by('-datestart')[:1]
SECTION_TYPE = {
'Projects': ['projects'],
'Works': ['works'],
'Texts': ['texts'],
'Events': ['events', 'news'],
}
def section_content(section):
types = SECTION_TYPE.get(section, [section.lower()])
content = Content.objects.filter(type__name__in=types).order_by('-datestart')
content = content.filter(published=True)
return content
def section_index(request, section, max_length=10):
types = SECTION_TYPE.get(section, [section.lower()])
featured = Content.objects.filter(type__name__in=types, featured=True).order_by('-datestart')[:1]
content = section_content(section)
if featured:
content = content.exclude(pk=featured[0].pk)
content = content.filter(published=True)
more_content = content.count() > max_length
content = content[:max_length]
return render(request, 'section_index.html', {
'section': section,
'featured': featured,
'content': content
'content': content,
'more_content': more_content,
})
def section_list(request, section):
content = section_content(section)
q = request.GET.get('q')
content = limit_content(content, q)
page = request.GET.get('page', 1)
paginator = Paginator(content, 5)
try:
content = paginator.page(page)
except PageNotAnInteger:
content = paginator.page(1)
except EmptyPage:
content = paginator.page(paginator.num_pages)
base_query = ''
if q:
base_query = 'q=%s&' % q
return render(request, 'results.html', {
'base_query': base_query,
'content': content,
'query': q,
'section': section,
})
def event(request):
now = datetime.now()
display_events = ['events']
display_events = ['events', 'news']
featured = Content.objects.filter(type__name='events', featured=True).order_by('-datestart')[:1]
base = Content.objects.filter(type__name__in=display_events).order_by('-datestart')
base = base.filter(published=True)
@ -65,55 +110,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='events').order_by('-datestart')[:10]
return render(request, 'events.html', {'events': events, 'latest_content_list': latest_content_list, 'gallery': gallery})
latest_content_list, more = get_related_content(types, content)
return render(request, template, {
'content': content,
'latest_content_list': latest_content_list,
'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')
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')
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')
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')
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')
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')
return render(request, 'texts.html', {
'texts': texts,
'latest_content_list': latest_content_list,
'gallery': gallery
})
return render_content(request, shortname, 'Texts', 'content.html', ['texts'])
def page(request, shortname):
@ -123,22 +166,33 @@ def page(request, shortname):
return render(request, 'page.html', {'content': content})
def limit_content(content, q):
if 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'])
q = request.GET.get('q')
results = Content.objects.filter(Q(body__icontains=q) | Q(title__icontains=q) | Q(header__icontains=q)).distinct()
results = results.filter(published=True)
results = results.order_by('-datestart')
content = limit_content(content, q)
page = request.GET.get('page', 1)
paginator = Paginator(results, 5)
paginator = Paginator(content, 5)
try:
results = paginator.page(page)
content = paginator.page(page)
except PageNotAnInteger:
results = paginator.page(1)
content = paginator.page(1)
except EmptyPage:
results = paginator.page(paginator.num_pages)
content = paginator.page(paginator.num_pages)
base_query = ''
if q:
base_query = 'q=%s&' % q
return render(request, 'results.html', {
'results': results,
'base_query': base_query,
'content': content,
'query': q
})