only public

This commit is contained in:
root 2017-12-18 14:17:06 +00:00
parent 9c35b09e10
commit d10ae99722
4 changed files with 48 additions and 46 deletions

View File

@ -40,10 +40,10 @@ urlpatterns = [
url(r'^events/(?P<shortname>.+)/$', views.events, name='events'), url(r'^events/(?P<shortname>.+)/$', views.events, name='events'),
url(r'^projects/(?P<shortname>.+)/$', views.projects, name='projects'), url(r'^projects/(?P<shortname>.+)/$', views.projects, name='projects'),
url(r'^works/(?P<shortname>.+)/$', views.works, name='works'), url(r'^works/(?P<shortname>.+)/$', views.works, name='works'),
url(r'^works/$', views.work), url(r'^works/$', views.works),
url(r'^projects/$', views.project), url(r'^projects/$', views.projects),
url(r'^events/$', views.event), url(r'^events/$', views.events),
url(r'^texts/$', views.text), url(r'^texts/$', views.texts),
url(r'^search/$', views.search), url(r'^search/$', views.search),
url(r'^markdownx/', include(markdownx)), url(r'^markdownx/', include(markdownx)),
url(r'^photologue/', include('photologue.urls', namespace='photologue')), url(r'^photologue/', include('photologue.urls', namespace='photologue')),

View File

@ -118,13 +118,15 @@ class Content(models.Model):
def get_absolute_url(self): def get_absolute_url(self):
if self.shortname: if self.shortname:
parts = []
section = self.type.name section = self.type.name
if section == 'news': if section == 'news':
section = 'events' section = 'events'
if section == 'page': if section == 'page':
return '/' + self.shortname parts = [self.shortname]
return '/%s/%s' %(section, self.shortname) else:
parts = [section, self.shortname]
return '/' + '/'.join(parts)
class Meta: class Meta:
managed = True managed = True

View File

@ -6,7 +6,7 @@
<h6 class="sidebar-date"> <h6 class="sidebar-date">
<font color="#ef4e5c"> <b> {{content.datestart}} </b> <font color="#ef4e5c"> <b> {{content.datestart}} </b>
{{ content.title }} <br /> {{ content.title }} <br />
{{ content.formatted_header|striptags|safe }} {{ content.formatted_header }}
</font> </font>
</h6> </h6>
</div> </div>

View File

@ -4,7 +4,7 @@ from datetime import datetime
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Q from django.db.models import Q
from django.http import HttpResponse from django.http import HttpResponse, Http404
from django.shortcuts import get_object_or_404, render, redirect from django.shortcuts import get_object_or_404, render, redirect
from django.urls import reverse from django.urls import reverse
from django.views.generic.list import ListView from django.views.generic.list import ListView
@ -19,9 +19,12 @@ from .models import Content, ContentContent
def index(request): def index(request):
now = datetime.now() now = datetime.now()
display_events = ['news', 'events'] display_events = ['news', 'events']
upcoming_events = Content.objects.filter(datestart__gt=now).filter(type__name__in=display_events).order_by('-datestart')[:12] base = Content.objects.filter(type__name__in=display_events).order_by('-datestart')
ongoing_events = Content.objects.filter(datestart__lt=now, dateend__gte=now).filter(type__name__in=display_events).order_by('-datestart')[:12] base = base.filter(published=True)
past_events = Content.objects.filter(dateend__lt=now).filter(type__name__in=display_events).order_by('-datestart')[:12] upcoming_events = base.filter(datestart__gt=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]
homepage = Content.objects.filter(type__name='homepage').order_by('-datestart')[:1] homepage = Content.objects.filter(type__name='homepage').order_by('-datestart')[:1]
context = { context = {
'upcoming_events': upcoming_events, 'upcoming_events': upcoming_events,
@ -30,22 +33,15 @@ def index(request):
'homepage': homepage} 'homepage': homepage}
return render(request, 'index.html', context) return render(request, 'index.html', context)
def project(request):
type = 'projects'
featured = Content.objects.filter(type__name=type, featured=True).order_by('-datestart')[:1]
content = Content.objects.filter(type__name=type).order_by('-datestart')
return render(request, 'section_index.html', {
'section': 'Projects',
'featured': featured,
'content': content
})
def work(request): def section_index(request, types, section):
type = 'works' featured = Content.objects.filter(type__name__in=types, featured=True).order_by('-datestart')[:1]
featured = Content.objects.filter(type__name=type, featured=True).order_by('-datestart')[:1] content = Content.objects.filter(type__name__in=types).order_by('-datestart')
content = Content.objects.filter(type__name=type).order_by('-datestart') if featured:
content = content.exclude(pk=featured[0].pk)
content = content.filter(published=True)
return render(request, 'section_index.html', { return render(request, 'section_index.html', {
'section': 'Works', 'section': section,
'featured': featured, 'featured': featured,
'content': content 'content': content
}) })
@ -53,11 +49,16 @@ def work(request):
def event(request): def event(request):
now = datetime.now() now = datetime.now()
display_events = ['events'] display_events = ['events']
upcoming_events = Content.objects.filter(datestart__gt=now).filter(type__name__in=display_events).order_by('-datestart')
ongoing_events = Content.objects.filter(datestart__lt=now, dateend__gte=now).filter(type__name__in=display_events).order_by('-datestart')
past_events = Content.objects.filter(Q(dateend__lt=now)|Q(dateend=None, datestart__lt=now)).filter(type__name__in=display_events).order_by('-datestart')[:10]
featured = Content.objects.filter(type__name='events', featured=True).order_by('-datestart')[:1] 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)
if featured:
base = base.exclude(pk=featured[0].pk)
upcoming_events = base.filter(datestart__gt=now).order_by('-datestart')
ongoing_events = base.filter(datestart__lt=now, dateend__gte=now).order_by('-datestart')
past_events = base.filter(Q(dateend__lt=now)|Q(dateend=None, datestart__lt=now))[:10]
context = { context = {
'upcoming_events': upcoming_events, 'upcoming_events': upcoming_events,
'ongoing_events': ongoing_events, 'ongoing_events': ongoing_events,
@ -66,44 +67,40 @@ def event(request):
} }
return render(request, 'event.html', context) return render(request, 'event.html', context)
def text(request):
type = 'texts'
featured = Content.objects.filter(type__name=type, featured=True).order_by('-datestart')[:1]
content = Content.objects.filter(type__name=type).order_by('-datestart')
return render(request, 'section_index.html', {
'section': 'Texts',
'featured': featured,
'content': content
})
def events(request, shortname): def events(request, shortname):
if not shortname: if not shortname:
return event(request) return event(request)
events = get_object_or_404(Content, shortname=shortname, type__name__in=['news', 'events']) events = get_object_or_404(Content, shortname=shortname, type__name__in=['news', 'events'])
if not events.published and not request.user.is_admin:
raise Http404
gallery = get_or_none(Gallery, slug=shortname) gallery = get_or_none(Gallery, slug=shortname)
latest_content_list = Content.objects.filter(type__name='events').order_by('-datestart')[:10] 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}) return render(request, 'events.html', {'events': events, 'latest_content_list': latest_content_list, 'gallery': gallery})
def projects(request, shortname): def projects(request, shortname=None):
if not shortname: if not shortname:
return project(request) return section_index(request, ['projects'], 'Projects')
projects = get_object_or_404(Content, shortname=shortname, type__name='projects') projects = get_object_or_404(Content, shortname=shortname, type__name='projects')
if not projects.published and not request.user.is_admin:
raise Http404
gallery = get_or_none(Gallery, slug=shortname) gallery = get_or_none(Gallery, slug=shortname)
latest_content_list = Content.objects.filter(type__name='projects').order_by('-datestart') 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(request, 'projects.html', {'projects': projects, 'latest_content_list': latest_content_list, 'gallery':gallery})
def works(request, shortname): def works(request, shortname):
if not shortname: if not shortname:
return work(request) return section_index(request, ['works'], 'Works')
works = get_object_or_404(Content, shortname=shortname, type__name='works') works = get_object_or_404(Content, shortname=shortname, type__name='works')
if not works.published and not request.user.is_admin:
raise Http404
gallery = get_or_none(Gallery, slug=shortname) gallery = get_or_none(Gallery, slug=shortname)
latest_content_list = Content.objects.filter(type__name='works') 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(request, 'works.html', {'works': works, 'latest_content_list': latest_content_list, 'gallery':gallery})
def texts(request, shortname): def texts(request, shortname):
if not shortname: if not shortname:
return text(request) return section_index(request, ['texts'], 'Texts')
texts = get_object_or_404(Content, shortname=shortname, type__name='texts') texts = get_object_or_404(Content, shortname=shortname, type__name='texts')
gallery = get_or_none(Gallery, slug=shortname) gallery = get_or_none(Gallery, slug=shortname)
latest_content_list = Content.objects.filter(type__name='texts') latest_content_list = Content.objects.filter(type__name='texts')
@ -116,6 +113,8 @@ def texts(request, shortname):
def page(request, shortname): def page(request, shortname):
content = get_object_or_404(Content, shortname=shortname, type__name='page') content = get_object_or_404(Content, shortname=shortname, type__name='page')
if not content.published and not request.user.is_admin:
raise Http404
return render(request, 'page.html', {'content': content}) return render(request, 'page.html', {'content': content})
@ -148,11 +147,12 @@ def redirect_index(request):
def redirect_event(request): def redirect_event(request):
shortname = request.GET.get('this') shortname = request.GET.get('this')
if shortname: if shortname:
return redirect(reverse('content', kwargs={'shortname': shortname})) content = get_object_or_404(Content, shortname=shortname)
return redirect(content.get_absolute_url())
id = request.GET.get('id') id = request.GET.get('id')
if id: if id:
content = get_object_or_404(Content, id=id) content = get_object_or_404(Content, id=id)
return redirect(reverse('content', kwargs={'shortname': content.shortname})) return redirect(content.get_absolute_url())
return redirect(reverse('events')) return redirect(reverse('events'))