mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
WIP: first Weekmail models
This commit is contained in:
parent
d8c9575f88
commit
8bd8191030
49
com/migrations/0003_auto_20170103_1341.py
Normal file
49
com/migrations/0003_auto_20170103_1341.py
Normal file
@ -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=''),
|
||||||
|
),
|
||||||
|
]
|
@ -11,6 +11,7 @@ class Sith(models.Model):
|
|||||||
alert_msg = models.TextField(_("alert message"), default="", blank=True)
|
alert_msg = models.TextField(_("alert message"), default="", blank=True)
|
||||||
info_msg = models.TextField(_("info message"), default="", blank=True)
|
info_msg = models.TextField(_("info message"), default="", blank=True)
|
||||||
index_page = models.TextField(_("index page"), 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):
|
def is_owned_by(self, user):
|
||||||
return user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID)
|
return user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID)
|
||||||
@ -64,3 +65,35 @@ class NewsDate(models.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s: %s - %s" % (self.news.title, self.start_date, self.end_date)
|
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()
|
||||||
|
13
com/templates/com/weekmail.jinja
Normal file
13
com/templates/com/weekmail.jinja
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{% extends "core/base.jinja" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
{% trans %}Weekmail{% endtrans %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h3>{% trans %}Weekmail{% endtrans %}</h3>
|
||||||
|
{{ object }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -6,6 +6,7 @@ urlpatterns = [
|
|||||||
url(r'^sith/edit/alert$', AlertMsgEditView.as_view(), name='alert_edit'),
|
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/info$', InfoMsgEditView.as_view(), name='info_edit'),
|
||||||
url(r'^sith/edit/index$', IndexEditView.as_view(), name='index_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$', NewsListView.as_view(), name='news_list'),
|
||||||
url(r'^news/admin$', NewsAdminListView.as_view(), name='news_admin_list'),
|
url(r'^news/admin$', NewsAdminListView.as_view(), name='news_admin_list'),
|
||||||
url(r'^news/create$', NewsCreateView.as_view(), name='news_new'),
|
url(r'^news/create$', NewsCreateView.as_view(), name='news_new'),
|
||||||
|
16
com/views.py
16
com/views.py
@ -11,7 +11,7 @@ from django import forms
|
|||||||
|
|
||||||
from datetime import timedelta
|
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 import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin, CanCreateMixin
|
||||||
from core.views.forms import SelectDateTime
|
from core.views.forms import SelectDateTime
|
||||||
from core.models import Notification, RealGroup
|
from core.models import Notification, RealGroup
|
||||||
@ -28,6 +28,11 @@ class ComTabsMixin(TabedViewMixin):
|
|||||||
|
|
||||||
def get_list_of_tabs(self):
|
def get_list_of_tabs(self):
|
||||||
tab_list = []
|
tab_list = []
|
||||||
|
tab_list.append({
|
||||||
|
'url': reverse('com:weekmail'),
|
||||||
|
'slug': 'weekmail',
|
||||||
|
'name': _("Weekmail"),
|
||||||
|
})
|
||||||
tab_list.append({
|
tab_list.append({
|
||||||
'url': reverse('com:index_edit'),
|
'url': reverse('com:index_edit'),
|
||||||
'slug': 'index',
|
'slug': 'index',
|
||||||
@ -213,4 +218,13 @@ class NewsDetailView(CanViewMixin, DetailView):
|
|||||||
template_name = 'com/news_detail.jinja'
|
template_name = 'com/news_detail.jinja'
|
||||||
pk_url_kwarg = 'news_id'
|
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()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user