projects have galleries too

This commit is contained in:
j 2017-12-19 12:41:34 +01:00
parent 51aae2ec53
commit e5e44955cf
5 changed files with 21 additions and 10 deletions

View File

@ -48,7 +48,12 @@ urlpatterns = [
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')),
url(r'^gallerylist/$', GalleryListView.as_view(), name='gallery-list'), 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<shortname>\w+)/$', views.page, name='page') url(r'^(?P<shortname>\w+)/$', views.page, name='page')
] ]

View File

@ -143,6 +143,14 @@ class Content(models.Model):
def get_gallery(self): def get_gallery(self):
gallery, created = Gallery.objects.get_or_create(slug=self.shortname) 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 return gallery
class Meta: class Meta:

View File

@ -13,14 +13,7 @@
<p> {{events.formatted_header|safe}} </p> <p> {{events.formatted_header|safe}} </p>
<p> {{events.formatted_body|safe}} </p> <p> {{events.formatted_body|safe}} </p>
{% include "opt.html" with content=events %} {% include "opt.html" with content=events %}
{% if gallery %} {% include "gallery.html" with gallery=gallery %}
<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>
{% endfor %}
{% endif %}
</ul>
</div> </div>
</div> </div>

View File

@ -13,6 +13,7 @@
<p> {{projects.formatted_header|safe}} </p> <p> {{projects.formatted_header|safe}} </p>
<p> {{projects.formatted_body|safe}} </p> <p> {{projects.formatted_body|safe}} </p>
{% include "opt.html" with content=projects %} {% include "opt.html" with content=projects %}
{% include "gallery.html" with gallery=gallery %}
</div> </div>
</div> </div>

View File

@ -87,7 +87,11 @@ def projects(request, shortname=None):
raise Http404 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=None): def works(request, shortname=None):
if not shortname: if not shortname: