mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-26 02:54:20 +00:00
Almost finish the weekmail
This commit is contained in:
parent
176b1bf588
commit
d988c09315
@ -4,6 +4,7 @@ from com.models import *
|
||||
|
||||
admin.site.register(Sith)
|
||||
admin.site.register(News)
|
||||
admin.site.register(Weekmail)
|
||||
|
||||
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
from django.shortcuts import render
|
||||
from django.db import models, transaction
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.core.urlresolvers import reverse_lazy, reverse
|
||||
@ -86,15 +87,22 @@ class Weekmail(models.Model):
|
||||
print("Sending weekmail n°" + str(self.id))
|
||||
email = EmailMessage(
|
||||
subject=self.title,
|
||||
body="\n\n".join([self.intro, self.joke, self.protip, self.conclusion]),
|
||||
body=self.render(),
|
||||
from_email=settings.DEFAULT_FROM_EMAIL,
|
||||
to=[],
|
||||
to=['skia@git.an'],
|
||||
bcc=Sith.objects.first().weekmail_destinations.split(' '),
|
||||
# TODO: Content-Type: text/html
|
||||
)
|
||||
email.send()
|
||||
self.sent = True
|
||||
self.save()
|
||||
Weekmail().save()
|
||||
|
||||
def render(self):
|
||||
return render(None, "com/weekmail_renderer.jinja", context={
|
||||
'weekmail': self,
|
||||
}).content.decode('utf-8')
|
||||
|
||||
class WeekmailArticle(models.Model):
|
||||
weekmail = models.ForeignKey(Weekmail, related_name="articles", verbose_name=_("weekmail"), null=True)
|
||||
title = models.CharField(_("title"), max_length=64)
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
{% block content %}
|
||||
<h3>{% trans %}Weekmail{% endtrans %}</h3>
|
||||
<p><a href="{{ url('com:weekmail_preview') }}" target="_blank">{% trans %}Preview{% endtrans %}</a></p>
|
||||
<p><a href="?send">{% trans %}Send{% endtrans %}</a></p>
|
||||
<h4>{% trans %}Articles in no weekmail yet{% endtrans %}</h4>
|
||||
<table>
|
||||
<thead>
|
||||
|
13
com/templates/com/weekmail_preview.jinja
Normal file
13
com/templates/com/weekmail_preview.jinja
Normal file
@ -0,0 +1,13 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
{% from 'core/macros.jinja' import user_profile_link %}
|
||||
|
||||
{% block title %}
|
||||
{{ weekmail.title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ weekmail_rendered|safe }}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
34
com/templates/com/weekmail_renderer.jinja
Normal file
34
com/templates/com/weekmail_renderer.jinja
Normal file
@ -0,0 +1,34 @@
|
||||
<h2>{{ weekmail.title }}</h2>
|
||||
|
||||
{% if weekmail.intro %}
|
||||
<h3>{% trans %}Intro{% endtrans %}</h3>
|
||||
{{ weekmail.intro|markdown }}
|
||||
{% endif %}
|
||||
|
||||
<h3>{% trans %}Table of content{% endtrans %}</h3>
|
||||
<ul>
|
||||
{% for a in weekmail.articles.all() %}
|
||||
<li>[{{ a.club }}] {{ a.title }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{% for a in weekmail.articles.all() %}
|
||||
<h3>[{{ a.club }}] {{ a.title }}</h3>
|
||||
{{ a.content|markdown }}
|
||||
{% endfor %}
|
||||
|
||||
{% if weekmail.joke %}
|
||||
<h3>{% trans %}Joke{% endtrans %}</h3>
|
||||
{{ weekmail.joke|markdown }}
|
||||
{% endif %}
|
||||
|
||||
{% if weekmail.protip %}
|
||||
<h3>{% trans %}Pro tip{% endtrans %}</h3>
|
||||
{{ weekmail.protip|markdown }}
|
||||
{% endif %}
|
||||
|
||||
{% if weekmail.conclusion %}
|
||||
<h3>{% trans %}Final word{% endtrans %}</h3>
|
||||
{{ weekmail.conclusion|markdown }}
|
||||
{% endif %}
|
||||
|
@ -7,6 +7,7 @@ urlpatterns = [
|
||||
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'^weekmail/preview$', WeekmailPreviewView.as_view(), name='weekmail_preview'),
|
||||
url(r'^weekmail/club/(?P<club_id>[0-9]+)/new_article$', WeekmailArticleCreateView.as_view(), name='weekmail_article'),
|
||||
url(r'^weekmail/article/(?P<article_id>[0-9]+)/delete$', WeekmailArticleDeleteView.as_view(), name='weekmail_article_delete'),
|
||||
url(r'^weekmail/article/(?P<article_id>[0-9]+)/edit$', WeekmailArticleEditView.as_view(), name='weekmail_article_edit'),
|
||||
|
18
com/views.py
18
com/views.py
@ -221,6 +221,20 @@ class NewsDetailView(CanViewMixin, DetailView):
|
||||
|
||||
# Weekmail
|
||||
|
||||
class WeekmailPreviewView(DetailView):
|
||||
model = Weekmail
|
||||
template_name = 'com/weekmail_preview.jinja'
|
||||
success_url = reverse_lazy('com:weekmail')
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
return self.model.objects.filter(sent=False).order_by('-id').first()
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""Add rendered weekmail"""
|
||||
kwargs = super(WeekmailPreviewView, self).get_context_data(**kwargs)
|
||||
kwargs['weekmail_rendered'] = self.object.render()
|
||||
return kwargs
|
||||
|
||||
class WeekmailEditView(QuickNotifMixin, UpdateView):
|
||||
model = Weekmail
|
||||
template_name = 'com/weekmail.jinja'
|
||||
@ -232,6 +246,7 @@ class WeekmailEditView(QuickNotifMixin, UpdateView):
|
||||
if not weekmail.title:
|
||||
now = timezone.now()
|
||||
weekmail.title = _("Weekmail of the ") + (now + timedelta(days=6 - now.weekday())).strftime('%d/%m/%Y')
|
||||
weekmail.save()
|
||||
return weekmail
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
@ -265,6 +280,9 @@ class WeekmailEditView(QuickNotifMixin, UpdateView):
|
||||
art.rank = -1
|
||||
art.save()
|
||||
self.quick_notif_list += ['qn_success']
|
||||
if 'send' in request.GET.keys():
|
||||
self.object.send()
|
||||
self.quick_notif_list += ['qn_success']
|
||||
return super(WeekmailEditView, self).get(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
|
Loading…
Reference in New Issue
Block a user