mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-26 02:54:20 +00:00
Make some weekmail views
This commit is contained in:
parent
8bd8191030
commit
9d1eaed625
@ -1,7 +1,8 @@
|
|||||||
from django.db import models
|
from django.db import models, transaction
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.core.urlresolvers import reverse_lazy, reverse
|
from django.core.urlresolvers import reverse_lazy, reverse
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core.mail import EmailMessage
|
||||||
|
|
||||||
from core.models import User
|
from core.models import User
|
||||||
from club.models import Club
|
from club.models import Club
|
||||||
@ -70,7 +71,7 @@ class Weekmail(models.Model):
|
|||||||
"""
|
"""
|
||||||
The weekmail class
|
The weekmail class
|
||||||
"""
|
"""
|
||||||
title = models.CharField(_("title"), max_length=64)
|
title = models.CharField(_("title"), max_length=64, blank=True)
|
||||||
intro = models.TextField(_("intro"), blank=True)
|
intro = models.TextField(_("intro"), blank=True)
|
||||||
joke = models.TextField(_("joke"), blank=True)
|
joke = models.TextField(_("joke"), blank=True)
|
||||||
protip = models.TextField(_("protip"), blank=True)
|
protip = models.TextField(_("protip"), blank=True)
|
||||||
@ -81,9 +82,18 @@ class Weekmail(models.Model):
|
|||||||
ordering = ['-id']
|
ordering = ['-id']
|
||||||
|
|
||||||
def send(self):
|
def send(self):
|
||||||
print("Sending weekmail n°" + str(self.id))
|
with transaction.atomic():
|
||||||
self.sent = True
|
print("Sending weekmail n°" + str(self.id))
|
||||||
self.save()
|
email = EmailMessage(
|
||||||
|
subject=self.title,
|
||||||
|
body="\n\n".join([self.intro, self.joke, self.protip, self.conclusion]),
|
||||||
|
from_email=settings.DEFAULT_FROM_EMAIL,
|
||||||
|
to=[],
|
||||||
|
bcc=Sith.objects.first().weekmail_destinations.split(' '),
|
||||||
|
)
|
||||||
|
self.sent = True
|
||||||
|
self.save()
|
||||||
|
Weekmail().save()
|
||||||
|
|
||||||
class WeekmailArticle(models.Model):
|
class WeekmailArticle(models.Model):
|
||||||
weekmail = models.ForeignKey(Weekmail, related_name="articles", verbose_name=_("weekmail"))
|
weekmail = models.ForeignKey(Weekmail, related_name="articles", verbose_name=_("weekmail"))
|
||||||
|
@ -5,8 +5,13 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h3>{% trans %}Weekmail{% endtrans %}</h3>
|
<h3>{% trans %}Weekmail{% endtrans %}</h3>
|
||||||
{{ object }}
|
{{ object }}
|
||||||
|
<form action="" method="post" enctype="multipart/form-data">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p() }}
|
||||||
|
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
|
||||||
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ urlpatterns = [
|
|||||||
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'^weekmail$', WeekmailEditView.as_view(), name='weekmail'),
|
||||||
|
url(r'^weekmail/club/(?P<club_id>[0-9]+)/new_article$', WeekmailArticleCreateView.as_view(), name='weekmail_article'),
|
||||||
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'),
|
||||||
|
@ -223,8 +223,14 @@ class NewsDetailView(CanViewMixin, DetailView):
|
|||||||
class WeekmailEditView(UpdateView):
|
class WeekmailEditView(UpdateView):
|
||||||
model = Weekmail
|
model = Weekmail
|
||||||
template_name = 'com/weekmail.jinja'
|
template_name = 'com/weekmail.jinja'
|
||||||
|
fields = ['title', 'intro', 'joke', 'protip', 'conclusion']
|
||||||
|
success_url = reverse_lazy('com:weekmail')
|
||||||
|
|
||||||
def get_object(self, queryset=None):
|
def get_object(self, queryset=None):
|
||||||
return self.model.objects.order_by('-id').first()
|
weekmail = self.model.objects.filter(sent=False).order_by('-id').first()
|
||||||
|
if not weekmail.title:
|
||||||
|
now = timezone.now()
|
||||||
|
weekmail.title = _("Weekmail of the ") + (now + timedelta(days=6 - now.weekday())).strftime('%d/%m/%Y')
|
||||||
|
return weekmail
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ from core.utils import resize_image
|
|||||||
from club.models import Club, Membership
|
from club.models import Club, Membership
|
||||||
from subscription.models import Subscription
|
from subscription.models import Subscription
|
||||||
from counter.models import Customer, ProductType, Product, Counter
|
from counter.models import Customer, ProductType, Product, Counter
|
||||||
from com.models import Sith
|
from com.models import Sith, Weekmail
|
||||||
from election.models import Election, Role, Candidature, ElectionList
|
from election.models import Election, Role, Candidature, ElectionList
|
||||||
|
|
||||||
|
|
||||||
@ -87,6 +87,7 @@ class Command(BaseCommand):
|
|||||||
club_root.save()
|
club_root.save()
|
||||||
|
|
||||||
Sith().save()
|
Sith().save()
|
||||||
|
Weekmail().save()
|
||||||
|
|
||||||
p = Page(name='Index')
|
p = Page(name='Index')
|
||||||
p.set_lock(root)
|
p.set_lock(root)
|
||||||
|
Loading…
Reference in New Issue
Block a user