From e5e44955cfa295a4398e823300a42847ea15e0f7 Mon Sep 17 00:00:00 2001 From: j Date: Tue, 19 Dec 2017 12:41:34 +0100 Subject: [PATCH] projects have galleries too --- camp/urls.py | 7 ++++++- content/models.py | 8 ++++++++ content/templates/events.html | 9 +-------- content/templates/projects.html | 1 + content/views.py | 6 +++++- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/camp/urls.py b/camp/urls.py index ee719e7..cc494c6 100644 --- a/camp/urls.py +++ b/camp/urls.py @@ -48,7 +48,12 @@ urlpatterns = [ url(r'^markdownx/', include(markdownx)), url(r'^photologue/', include('photologue.urls', namespace='photologue')), url(r'^gallerylist/$', GalleryListView.as_view(), name='gallery-list'), -] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + [ +] + +if settings.DEBUG: + urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + +urlpatterns += [ url(r'^(?P\w+)/$', views.page, name='page') ] diff --git a/content/models.py b/content/models.py index 4f44f8e..36eb2e2 100644 --- a/content/models.py +++ b/content/models.py @@ -143,6 +143,14 @@ class Content(models.Model): def get_gallery(self): gallery, created = Gallery.objects.get_or_create(slug=self.shortname) + if created: + title = self.title + n = 1 + while Gallery.objects.filter(title=title).exclude(pk=gallery.pk).exists(): + n += 1 + title = '%s [%s]' % (self.title, n) + gallery.title = title + gallery.save() return gallery class Meta: diff --git a/content/templates/events.html b/content/templates/events.html index 2d2c367..fa76841 100644 --- a/content/templates/events.html +++ b/content/templates/events.html @@ -13,14 +13,7 @@

{{events.formatted_header|safe}}

{{events.formatted_body|safe}}

{% include "opt.html" with content=events %} - {% if gallery %} -
Gallery: {{gallery.title}}
- + {% include "gallery.html" with gallery=gallery %} diff --git a/content/templates/projects.html b/content/templates/projects.html index f62ad28..166c2af 100644 --- a/content/templates/projects.html +++ b/content/templates/projects.html @@ -13,6 +13,7 @@

{{projects.formatted_header|safe}}

{{projects.formatted_body|safe}}

{% include "opt.html" with content=projects %} + {% include "gallery.html" with gallery=gallery %} diff --git a/content/views.py b/content/views.py index 5aa1f2f..aead5b9 100644 --- a/content/views.py +++ b/content/views.py @@ -87,7 +87,11 @@ def projects(request, shortname=None): 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(request, 'projects.html', { + 'projects': projects, + 'latest_content_list': latest_content_list, + 'gallery': gallery + }) def works(request, shortname=None): if not shortname: