camp/content/views.py

88 lines
2.9 KiB
Python
Raw Normal View History

2017-05-20 12:45:26 +00:00
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
2017-06-10 09:59:00 +00:00
from django.http import HttpResponse
2017-12-05 18:10:17 +00:00
from django.shortcuts import get_object_or_404, render, redirect
from django.urls import reverse
2017-06-10 09:59:00 +00:00
from .models import Content
2017-05-20 12:45:26 +00:00
2017-06-10 09:59:00 +00:00
def index(request):
content = Content.objects.all()
content = content.filter(published=True)
2017-12-09 11:53:44 +00:00
latest_content_list = content.order_by('-datestart')[:5]
2017-06-10 09:59:00 +00:00
context = {'latest_content_list': latest_content_list}
return render(request, 'index.html', context)
def content(request, shortname):
2017-12-09 12:51:56 +00:00
if request.user.is_staff:
content = get_object_or_404(Content, shortname=shortname)
else:
content = get_object_or_404(Content, shortname=shortname, published=True)
2017-12-05 18:10:17 +00:00
return render(request, 'detail.html', {'content': content})
def projects(request):
content = Content.objects.filter(type__name='ongoing').exclude(shortname='').order_by('-datestart')
content = content.filter(published=True)
2017-12-05 18:10:17 +00:00
return render(request, 'projects.html', {
'content': content,
'title': 'Projects'
})
def events(request):
content = Content.objects.filter(type__name='events').exclude(shortname='')
content = Content.objects.filter(type__name='events').exclude(shortname='').order_by('-datestart')
content = content.filter(published=True)
2017-12-05 18:10:17 +00:00
return render(request, 'projects.html', {
'content': content,
'title': 'Upcoming Events'
})
def works(request):
content = Content.objects.filter(type__name='works').exclude(shortname='').order_by('-datestart')
content = content.filter(published=True)
2017-12-05 18:10:17 +00:00
return render(request, 'projects.html', {
'content': content,
'title': 'Works'
})
def texts(request):
content = Content.objects.filter(type__name='texts').exclude(shortname='')
content = content.filter(published=True)
2017-12-05 18:10:17 +00:00
return render(request, 'projects.html', {
'content': content,
'title': 'Texts'
})
def about(request):
content = get_object_or_404(Content, shortname='about')
return render(request, 'detail.html', {'content': content})
def contact(request):
content = get_object_or_404(Content, shortname='contact')
2017-06-10 09:59:00 +00:00
return render(request, 'detail.html', {'content': content})
2017-12-05 18:10:17 +00:00
def redirect_index(request):
segment = request.GET.get('show')
if segment == 'pastevents':
return redirect(reverse('works'))
elif segment == 'contact':
return redirect(reverse('contact'))
return redirect(reverse('index'))
def redirect_event(request):
shortname = request.GET.get('this')
if shortname:
return redirect(reverse('content', kwargs={'shortname': shortname}))
id = request.GET.get('id')
if id:
content = get_object_or_404(Content, id=id)
return redirect(reverse('content', kwargs={'shortname': content.shortname}))
return redirect(reverse('events'))
2017-12-08 21:22:01 +00:00
def redirect_images(request, image):
return redirect(image)