Unverified Commit e172b567 authored by Joost Rijneveld's avatar Joost Rijneveld
Browse files

announcements: add frontpage articles

parent a8252121
...@@ -4,7 +4,7 @@ from django.template.defaultfilters import striptags ...@@ -4,7 +4,7 @@ from django.template.defaultfilters import striptags
from thaliawebsite.templatetags.bleach_tags import bleach from thaliawebsite.templatetags.bleach_tags import bleach
from utils.translation import TranslatedModelAdmin from utils.translation import TranslatedModelAdmin
from .models import Announcement from .models import Announcement, FrontpageArticle
@admin.register(Announcement) @admin.register(Announcement)
...@@ -19,3 +19,12 @@ class AnnouncementAdmin(TranslatedModelAdmin): ...@@ -19,3 +19,12 @@ class AnnouncementAdmin(TranslatedModelAdmin):
def visible(self, obj): def visible(self, obj):
return obj.is_visible return obj.is_visible
visible.boolean = True visible.boolean = True
@admin.register(FrontpageArticle)
class FrontpageArticleAdmin(TranslatedModelAdmin):
list_display = ('title', 'since', 'until', 'visible')
def visible(self, obj):
return obj.is_visible
visible.boolean = True
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-08-24 19:53
from __future__ import unicode_literals
from django.db import migrations, models
import django.utils.timezone
import tinymce.models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0003_auto_20170517_1925'),
]
operations = [
migrations.CreateModel(
name='FrontpageArticle',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('since', models.DateTimeField(default=django.utils.timezone.now, help_text='Hide this article before this time.', verbose_name='Display since')),
('until', models.DateTimeField(blank=True, help_text='Hide this article after this time.', null=True, verbose_name='Display until')),
('title_en', models.CharField(help_text='The title of the article; what goes in the header', max_length=80, verbose_name='Title (EN)')),
('title_nl', models.CharField(help_text='The title of the article; what goes in the header', max_length=80, verbose_name='Title (NL)')),
('content_en', tinymce.models.HTMLField(help_text='The content of the article; what text to display.', max_length=5000, verbose_name='Content (EN)')),
('content_nl', tinymce.models.HTMLField(help_text='The content of the article; what text to display.', max_length=5000, verbose_name='Content (NL)')),
],
options={
'ordering': ('-since',),
},
),
]
...@@ -50,3 +50,46 @@ class Announcement(models.Model, metaclass=ModelTranslateMeta): ...@@ -50,3 +50,46 @@ class Announcement(models.Model, metaclass=ModelTranslateMeta):
"""Is this announcement currently visible""" """Is this announcement currently visible"""
return ((self.until is None or self.until > timezone.now()) and return ((self.until is None or self.until > timezone.now()) and
(self.since is None or self.since <= timezone.now())) (self.since is None or self.since <= timezone.now()))
class FrontpageArticle(models.Model, metaclass=ModelTranslateMeta):
title = MultilingualField(
models.CharField,
verbose_name=_('Title'),
help_text=_('The title of the article; what goes in the header'),
blank=False,
max_length=80,
)
content = MultilingualField(
HTMLField,
verbose_name=_('Content'),
help_text=_('The content of the article; what text to display.'),
blank=False,
max_length=5000,
)
since = models.DateTimeField(
verbose_name=_('Display since'),
help_text=_("Hide this article before this time."),
default=timezone.now,
)
until = models.DateTimeField(
verbose_name=_('Display until'),
help_text=_("Hide this article after this time."),
blank=True,
null=True,
)
class Meta:
ordering = ('-since', )
def __str__(self):
return self.title
@property
def is_visible(self):
"""Is this announcement currently visible"""
return ((self.until is None or self.until > timezone.now()) and
(self.since is None or self.since <= timezone.now()))
{% load bleach_tags %}
{% for article in articles %}
<h1>{{ article.title }}</h1>
<p class="text-center">{{ article.content | bleach }}</p>
{% endfor %}
from django import template
from announcements.models import FrontpageArticle
register = template.Library()
@register.inclusion_tag('announcements/frontpage_articles.html')
def render_frontpage_articles():
return {'articles': [a for a in FrontpageArticle.objects.all()
if a.is_visible]}
{% extends 'base.html' %} {% extends 'base.html' %}
{% load i18n event_cards %} {% load i18n event_cards frontpage_articles %}
{% block body %} {% block body %}
<h1>{% trans "Thalia, the study association of Computer Science and Information Science" %}</h1> <h1>{% trans "Thalia, the study association of Computer Science and Information Science" %}</h1>
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
{% blocktrans %}Thalia is the study association for the Computer Science and Information Science students at Radboud University in Nijmegen. Thalia provides you the necessary distractions during your studies, as we've been doing for the past 25 years. And via Thalia students can easily connect with teachers and students from other years.{% endblocktrans %} {% blocktrans %}Thalia is the study association for the Computer Science and Information Science students at Radboud University in Nijmegen. Thalia provides you the necessary distractions during your studies, as we've been doing for the past 25 years. And via Thalia students can easily connect with teachers and students from other years.{% endblocktrans %}
</p> </p>
{% render_frontpage_articles %}
<h1>{% trans "Upcoming events" %}</h1> <h1>{% trans "Upcoming events" %}</h1>
{% show_cards %} {% show_cards %}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment