Commit 097d2389 authored by Skia's avatar Skia 🤘
Browse files

Improve weekmail

parent 0aef7656
......@@ -6,6 +6,7 @@
<h4>{% trans %}Communication:{% endtrans %}</h4>
<li> <a href="{{ url('com:news_new') }}?club={{ }}">{% trans %}Create a news{% endtrans %}</a></li>
<li> <a href="{{ url('com:weekmail_article', }}">{% trans %}Post in the Weekmail{% endtrans %}</a></li>
<h4>{% trans %}Counters:{% endtrans %}</h4>
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('com', '0003_auto_20170103_1341'),
operations = [
field=models.CharField(verbose_name='title', max_length=64, blank=True),
field=models.ForeignKey(related_name='articles', to='com.Weekmail', verbose_name='weekmail', null=True),
......@@ -96,14 +96,10 @@ class Weekmail(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"), null=True)
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()
{% extends "core/base.jinja" %}
{% from 'core/macros.jinja' import user_profile_link %}
{% block title %}
{% trans %}Weekmail{% endtrans %}
......@@ -6,7 +7,57 @@
{% block content %}
<h3>{% trans %}Weekmail{% endtrans %}</h3>
{{ object }}
<h4>{% trans %}Articles in no weekmail yet{% endtrans %}</h4>
<td>{% trans %}Author{% endtrans %}</td>
<td>{% trans %}Club{% endtrans %}</td>
<td>{% trans %}Title{% endtrans %}</td>
<td>{% trans %}Content{% endtrans %}</td>
<td>{% trans %}Actions{% endtrans %}</td>
{% for a in orphans.all() %}
<td>{{ user_profile_link( }}</td>
<td><a href="{{ }}">{{ }}</a></td>
<td>{{ a.title }}</td>
<td>{{ a.content|markdown }}</td>
<td><a href="?add_article={{ }}">{% trans %}Add to weekmail{% endtrans %}</a></td>
{% endfor %}
<h4>{% trans %}Articles included the next weekmail{% endtrans %}</h4>
<td>{% trans %}Author{% endtrans %}</td>
<td>{% trans %}Club{% endtrans %}</td>
<td>{% trans %}Title{% endtrans %}</td>
<td>{% trans %}Content{% endtrans %}</td>
<td>{% trans %}Actions{% endtrans %}</td>
{% for a in object.articles.order_by('rank') %}
<td>{{ user_profile_link( }}</td>
<td><a href="{{ }}">{{ }}</a></td>
<td>{{ a.title }}</td>
<td>{{ a.content|markdown }}</td>
<a href="{{ url('com:weekmail_article_edit', }}">{% trans %}Edit{% endtrans %}</a> |
<a href="?del_article={{ }}">{% trans %}Delete from weekmail{% endtrans %}</a> |
<a href="?up_article={{ }}">{% trans %}Up{% endtrans %}</a> |
<a href="?down_article={{ }}">{% trans %}Down{% endtrans %}</a>
{% endfor %}
<form action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p() }}
......@@ -8,6 +8,8 @@ urlpatterns = [
url(r'^sith/edit/index$', IndexEditView.as_view(), name='index_edit'),
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'^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'),
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'),
from django.shortcuts import render, redirect
from django.shortcuts import render, redirect, get_object_or_404
from django.views.generic import ListView, DetailView, RedirectView
from django.views.generic.edit import UpdateView, CreateView
from django.views.generic.edit import UpdateView, CreateView, DeleteView
from django.views.generic.detail import SingleObjectMixin
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse, reverse_lazy
from django.core.exceptions import ValidationError
from django.utils import timezone
from django.conf import settings
from django.db.models import Max
from django import forms
from datetime import timedelta
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, QuickNotifMixin
from core.views.forms import SelectDateTime
from core.models import Notification, RealGroup
from club.models import Club
......@@ -220,7 +221,7 @@ class NewsDetailView(CanViewMixin, DetailView):
# Weekmail
class WeekmailEditView(UpdateView):
class WeekmailEditView(QuickNotifMixin, UpdateView):
model = Weekmail
template_name = 'com/weekmail.jinja'
fields = ['title', 'intro', 'joke', 'protip', 'conclusion']
......@@ -231,6 +232,79 @@ class WeekmailEditView(UpdateView):
if not weekmail.title:
now =
weekmail.title = _("Weekmail of the ") + (now + timedelta(days=6 - now.weekday())).strftime('%d/%m/%Y')
return weekmail
def get(self, request, *args, **kwargs):
self.object = self.get_object()
if 'up_article' in request.GET.keys():
art = get_object_or_404(WeekmailArticle, id=request.GET['up_article'], weekmail=self.object)
prev_art = self.object.articles.order_by('rank').filter(rank__lt=art.rank).last()
if prev_art:
art.rank, prev_art.rank = prev_art.rank, art.rank
self.quick_notif_list += ['qn_success']
if 'down_article' in request.GET.keys():
art = get_object_or_404(WeekmailArticle, id=request.GET['down_article'], weekmail=self.object)
next_art = self.object.articles.order_by('rank').filter(rank__gt=art.rank).first()
if next_art:
art.rank, next_art.rank = next_art.rank, art.rank
self.quick_notif_list += ['qn_success']
if 'add_article' in request.GET.keys():
art = get_object_or_404(WeekmailArticle, id=request.GET['add_article'], weekmail=None)
art.weekmail = self.object
art.rank = self.object.articles.aggregate(Max('rank'))['rank__max'] or 0
art.rank += 1
self.quick_notif_list += ['qn_success']
if 'del_article' in request.GET.keys():
art = get_object_or_404(WeekmailArticle, id=request.GET['del_article'], weekmail=self.object)
art.weekmail = None
art.rank = -1
self.quick_notif_list += ['qn_success']
return super(WeekmailEditView, self).get(request, *args, **kwargs)
def get_context_data(self, **kwargs):
"""Add orphan articles """
kwargs = super(WeekmailEditView, self).get_context_data(**kwargs)
kwargs['orphans'] = WeekmailArticle.objects.filter(weekmail=None)
return kwargs
class WeekmailArticleEditView(QuickNotifMixin, UpdateView):
"""Edit an article"""
model = WeekmailArticle
fields = ['title', 'content']
pk_url_kwarg = "article_id"
template_name = 'core/edit.jinja'
success_url = reverse_lazy('com:weekmail')
quick_notif_url_arg = "qn_weekmail_article_edit"
class WeekmailArticleCreateView(QuickNotifMixin, CreateView):
"""Post an article"""
model = WeekmailArticle
fields = ['title', 'content']
template_name = 'core/create.jinja'
success_url = reverse_lazy('core:user_tools')
quick_notif_url_arg = "qn_weekmail_new_article"
def form_valid(self, form):
club = get_object_or_404(Club, id=self.kwargs['club_id']) = club = self.request.user
return super(WeekmailArticleCreateView, self).form_valid(form)
class WeekmailArticleDeleteView(DeleteView):
"""Delete an article"""
model = WeekmailArticle
template_name = 'core/delete_confirm.jinja'
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