From 9c35b09e10294b8a8e849a94ad1bcee0f5ee181b Mon Sep 17 00:00:00 2001 From: root Date: Mon, 18 Dec 2017 13:44:11 +0000 Subject: [PATCH] relations, fix texts, show opt pages --- camp/urls.py | 8 ++++---- content/models.py | 9 ++++++++- content/templates/events.html | 1 + content/templates/opt.html | 18 ++++++++++++++++++ content/templates/projects.html | 1 + content/templates/texts.html | 3 ++- content/views.py | 8 ++++---- 7 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 content/templates/opt.html diff --git a/camp/urls.py b/camp/urls.py index 9dec6f8..31fdb63 100644 --- a/camp/urls.py +++ b/camp/urls.py @@ -36,10 +36,10 @@ urlpatterns = [ url(r'directions.html', RedirectView.as_view(url='/directions/')), url(r'campstudio.html', RedirectView.as_view(url='/directions/')), - url(r'^events/(?P\w+)/$', views.events, name='events'), - url(r'^projects/(?P\w+)/$', views.projects, name='projects'), - url(r'^works/(?P\w+)/$', views.works, name='works'), - url(r'^texts/(?P\w+)/$', views.texts, name='texts'), + url(r'^texts/(?P.+)/$', views.texts, name='texts'), + url(r'^events/(?P.+)/$', views.events, name='events'), + url(r'^projects/(?P.+)/$', views.projects, name='projects'), + url(r'^works/(?P.+)/$', views.works, name='works'), url(r'^works/$', views.work), url(r'^projects/$', views.project), url(r'^events/$', views.event), diff --git a/content/models.py b/content/models.py index 90dbcb8..c91ab06 100644 --- a/content/models.py +++ b/content/models.py @@ -83,7 +83,7 @@ class Content(models.Model): featured = models.BooleanField(default=False) view = models.ForeignKey("Views", null=True, blank=True, db_column="view", editable=False) place = models.CharField(max_length=255, null=True, blank=True) - parentid = models.IntegerField(null=True, db_column='parentID', blank=True) # Field name made lowercase. + parentid = models.IntegerField(null=True, db_column='parentID', blank=True, editable=False) # delete parents = models.ManyToManyField('Content', through='ContentContent', related_name= "children") def __unicode__(self): @@ -142,6 +142,13 @@ class ContentContent(models.Model): # managed = False db_table = 'content_content' + def reverse(self): + r, created = ContentContent.objects.get_or_create(contentid1=self.contentid2, contentid2=self.contentid1) + return r + + def save(self, *args, **kwargs): + super(ContentContent, self).save(*args, **kwargs) + self.reverse() class ContentKeyword(models.Model): contentid = models.IntegerField(db_column='contentID') # Field name made lowercase. diff --git a/content/templates/events.html b/content/templates/events.html index 12a4cc7..a2a7664 100644 --- a/content/templates/events.html +++ b/content/templates/events.html @@ -12,6 +12,7 @@

{{events.title}}

{{events.formatted_header|safe}}

{{events.formatted_body|safe}}

+ {% include "opt.html" with content=events %} {% if gallery %}
Gallery: {{gallery.title}}
    diff --git a/content/templates/opt.html b/content/templates/opt.html new file mode 100644 index 0000000..a624b5f --- /dev/null +++ b/content/templates/opt.html @@ -0,0 +1,18 @@ +{% if content.optbtn2 and content.opttext2 %} +
    +

    {{ content.optbtn2|safe }}

    +

    {{ content.opttext2|safe|linebreaks }}

    +
    +{% endif %} +{% if content.optbtn3 and content.opttext3 %} +
    +

    {{ content.optbtn3|safe }}

    +

    {{ content.opttext3|safe|linebreaks }}

    +
    +{% endif %} +{% if content.schedule %} +
    +

    {{content.schedulebutton|default:"Schedule"}}

    +

    {{ content.schedule|safe|linebreaks }}

    +
    +{% endif %} diff --git a/content/templates/projects.html b/content/templates/projects.html index e5d1fa0..83313e1 100644 --- a/content/templates/projects.html +++ b/content/templates/projects.html @@ -12,6 +12,7 @@

    {{projects.title}}

    {{projects.formatted_header|safe}}

    {{projects.formatted_body|safe}}

    + {% include "opt.html" with content=projects %} diff --git a/content/templates/texts.html b/content/templates/texts.html index 01242fd..b52cd63 100644 --- a/content/templates/texts.html +++ b/content/templates/texts.html @@ -10,6 +10,7 @@

    {{texts.title}}

    {{texts.formatted_header|safe}}

    {{texts.formatted_body|safe}}

    + {% include "opt.html" with content=texts %} @@ -36,7 +37,7 @@ {% for texts in latest_content_list %}
    - {% texts.image %} + {% if texts.image %}
    diff --git a/content/views.py b/content/views.py index 4a72b2e..f5d61ba 100644 --- a/content/views.py +++ b/content/views.py @@ -55,7 +55,7 @@ def event(request): 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') + 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] context = { @@ -82,7 +82,7 @@ def events(request, shortname): return event(request) events = get_object_or_404(Content, shortname=shortname, type__name__in=['news', 'events']) gallery = get_or_none(Gallery, slug=shortname) - latest_content_list = Content.objects.filter(type__name='events').order_by('-datestart') + 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}) def projects(request, shortname): @@ -90,7 +90,7 @@ def projects(request, shortname): return project(request) projects = get_object_or_404(Content, shortname=shortname, type__name='projects') gallery = get_or_none(Gallery, slug=shortname) - latest_content_list = Content.objects.filter(type__name='projects') + 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}) def works(request, shortname): @@ -104,7 +104,7 @@ def works(request, shortname): def texts(request, shortname): if not shortname: return text(request) - texts = get_object_or_404(Content, shortname=shortname) + 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', {