diff --git a/com/migrations/0003_auto_20170103_1341.py b/com/migrations/0003_auto_20170103_1341.py new file mode 100644 index 00000000..ebcddb20 --- /dev/null +++ b/com/migrations/0003_auto_20170103_1341.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +from django.conf import settings + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('club', '0006_auto_20161229_0040'), + ('com', '0002_news_newsdate'), + ] + + operations = [ + migrations.CreateModel( + name='Weekmail', + fields=[ + ('id', models.AutoField(primary_key=True, verbose_name='ID', serialize=False, auto_created=True)), + ('title', models.CharField(verbose_name='title', max_length=64)), + ('intro', models.TextField(verbose_name='intro', blank=True)), + ('joke', models.TextField(verbose_name='joke', blank=True)), + ('protip', models.TextField(verbose_name='protip', blank=True)), + ('conclusion', models.TextField(verbose_name='conclusion', blank=True)), + ('sent', models.BooleanField(verbose_name='sent', default=False)), + ], + options={ + 'ordering': ['-id'], + }, + ), + migrations.CreateModel( + name='WeekmailArticle', + fields=[ + ('id', models.AutoField(primary_key=True, verbose_name='ID', serialize=False, auto_created=True)), + ('title', models.CharField(verbose_name='title', max_length=64)), + ('content', models.TextField(verbose_name='content')), + ('rank', models.IntegerField(verbose_name='rank', default=-1)), + ('author', models.ForeignKey(related_name='owned_weekmail_articles', to=settings.AUTH_USER_MODEL, verbose_name='author')), + ('club', models.ForeignKey(related_name='weekmail_articles', to='club.Club', verbose_name='club')), + ('weekmail', models.ForeignKey(related_name='articles', to='com.Weekmail', verbose_name='weekmail')), + ], + ), + migrations.AddField( + model_name='sith', + name='weekmail_destinations', + field=models.TextField(verbose_name='weekmail destinations', default=''), + ), + ] diff --git a/com/models.py b/com/models.py index 6c48e332..65f8558e 100644 --- a/com/models.py +++ b/com/models.py @@ -11,6 +11,7 @@ class Sith(models.Model): alert_msg = models.TextField(_("alert message"), default="", blank=True) info_msg = models.TextField(_("info message"), default="", blank=True) index_page = models.TextField(_("index page"), default="", blank=True) + weekmail_destinations = models.TextField(_("weekmail destinations"), default="") def is_owned_by(self, user): return user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) @@ -64,3 +65,35 @@ class NewsDate(models.Model): def __str__(self): return "%s: %s - %s" % (self.news.title, self.start_date, self.end_date) + +class Weekmail(models.Model): + """ + The weekmail class + """ + title = models.CharField(_("title"), max_length=64) + intro = models.TextField(_("intro"), blank=True) + joke = models.TextField(_("joke"), blank=True) + protip = models.TextField(_("protip"), blank=True) + conclusion = models.TextField(_("conclusion"), blank=True) + sent = models.BooleanField(_("sent"), default=False) + + class Meta: + ordering = ['-id'] + + def send(self): + print("Sending weekmail n°" + str(self.id)) + self.sent = True + self.save() + +class WeekmailArticle(models.Model): + weekmail = models.ForeignKey(Weekmail, related_name="articles", verbose_name=_("weekmail")) + title = models.CharField(_("title"), max_length=64) + content = models.TextField(_("content")) + author = models.ForeignKey(User, related_name="owned_weekmail_articles", verbose_name=_("author")) + club = models.ForeignKey(Club, related_name="weekmail_articles", verbose_name=_("club")) + rank = models.IntegerField(_('rank'), default=-1) + + def clean(self): + super(WeekmailArticle, self).clean() + if not self.weekmail: + self.weekmail = Weekmail.objects.order_by('-id').first() diff --git a/com/templates/com/weekmail.jinja b/com/templates/com/weekmail.jinja new file mode 100644 index 00000000..dfe2b57c --- /dev/null +++ b/com/templates/com/weekmail.jinja @@ -0,0 +1,13 @@ +{% extends "core/base.jinja" %} + +{% block title %} +{% trans %}Weekmail{% endtrans %} +{% endblock %} + +{% block content %} +

{% trans %}Weekmail{% endtrans %}

+ {{ object }} +{% endblock %} + + + diff --git a/com/urls.py b/com/urls.py index bf842472..731e3327 100644 --- a/com/urls.py +++ b/com/urls.py @@ -6,6 +6,7 @@ urlpatterns = [ url(r'^sith/edit/alert$', AlertMsgEditView.as_view(), name='alert_edit'), url(r'^sith/edit/info$', InfoMsgEditView.as_view(), name='info_edit'), url(r'^sith/edit/index$', IndexEditView.as_view(), name='index_edit'), + url(r'^weekmail$', WeekmailEditView.as_view(), name='weekmail'), url(r'^news$', NewsListView.as_view(), name='news_list'), url(r'^news/admin$', NewsAdminListView.as_view(), name='news_admin_list'), url(r'^news/create$', NewsCreateView.as_view(), name='news_new'), diff --git a/com/views.py b/com/views.py index 14a6efab..ee33491a 100644 --- a/com/views.py +++ b/com/views.py @@ -11,7 +11,7 @@ from django import forms from datetime import timedelta -from com.models import Sith, News, NewsDate +from com.models import Sith, News, NewsDate, Weekmail, WeekmailArticle from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin, CanCreateMixin from core.views.forms import SelectDateTime from core.models import Notification, RealGroup @@ -28,6 +28,11 @@ class ComTabsMixin(TabedViewMixin): def get_list_of_tabs(self): tab_list = [] + tab_list.append({ + 'url': reverse('com:weekmail'), + 'slug': 'weekmail', + 'name': _("Weekmail"), + }) tab_list.append({ 'url': reverse('com:index_edit'), 'slug': 'index', @@ -213,4 +218,13 @@ class NewsDetailView(CanViewMixin, DetailView): template_name = 'com/news_detail.jinja' pk_url_kwarg = 'news_id' +# Weekmail + +class WeekmailEditView(UpdateView): + model = Weekmail + template_name = 'com/weekmail.jinja' + + def get_object(self, queryset=None): + return self.model.objects.order_by('-id').first() +