mirror of
https://github.com/ae-utbm/sith.git
synced 2024-10-31 19:38:04 +00:00
Improve weekmail
This commit is contained in:
parent
0aef7656b8
commit
097d238962
@ -6,6 +6,7 @@
|
||||
<h4>{% trans %}Communication:{% endtrans %}</h4>
|
||||
<ul>
|
||||
<li> <a href="{{ url('com:news_new') }}?club={{ object.id }}">{% trans %}Create a news{% endtrans %}</a></li>
|
||||
<li> <a href="{{ url('com:weekmail_article', club_id=object.id) }}">{% trans %}Post in the Weekmail{% endtrans %}</a></li>
|
||||
</ul>
|
||||
<h4>{% trans %}Counters:{% endtrans %}</h4>
|
||||
<ul>
|
||||
|
24
com/migrations/0004_auto_20170107_1222.py
Normal file
24
com/migrations/0004_auto_20170107_1222.py
Normal file
@ -0,0 +1,24 @@
|
||||
# -*- 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 = [
|
||||
migrations.AlterField(
|
||||
model_name='weekmail',
|
||||
name='title',
|
||||
field=models.CharField(verbose_name='title', max_length=64, blank=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='weekmailarticle',
|
||||
name='weekmail',
|
||||
field=models.ForeignKey(related_name='articles', to='com.Weekmail', verbose_name='weekmail', null=True),
|
||||
),
|
||||
]
|
@ -96,14 +96,10 @@ class Weekmail(models.Model):
|
||||
Weekmail().save()
|
||||
|
||||
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()
|
||||
|
@ -1,4 +1,5 @@
|
||||
{% 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>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<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>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for a in orphans.all() %}
|
||||
<tr>
|
||||
<td>{{ user_profile_link(a.author) }}</td>
|
||||
<td><a href="{{ a.club.get_absolute_url() }}">{{ a.club }}</a></td>
|
||||
<td>{{ a.title }}</td>
|
||||
<td>{{ a.content|markdown }}</td>
|
||||
<td><a href="?add_article={{ a.id }}">{% trans %}Add to weekmail{% endtrans %}</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<h4>{% trans %}Articles included the next weekmail{% endtrans %}</h4>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<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>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for a in object.articles.order_by('rank') %}
|
||||
<tr>
|
||||
<td>{{ user_profile_link(a.author) }}</td>
|
||||
<td><a href="{{ a.club.get_absolute_url() }}">{{ a.club }}</a></td>
|
||||
<td>{{ a.title }}</td>
|
||||
<td>{{ a.content|markdown }}</td>
|
||||
<td>
|
||||
<a href="{{ url('com:weekmail_article_edit', article_id=a.id) }}">{% trans %}Edit{% endtrans %}</a> |
|
||||
<a href="?del_article={{ a.id }}">{% trans %}Delete from weekmail{% endtrans %}</a> |
|
||||
<a href="?up_article={{ a.id }}">{% trans %}Up{% endtrans %}</a> |
|
||||
<a href="?down_article={{ a.id }}">{% trans %}Down{% endtrans %}</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<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'),
|
||||
|
82
com/views.py
82
com/views.py
@ -1,18 +1,19 @@
|
||||
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 = timezone.now()
|
||||
weekmail.title = _("Weekmail of the ") + (now + timedelta(days=6 - now.weekday())).strftime('%d/%m/%Y')
|
||||
print(self.quick_notif_list)
|
||||
return weekmail
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
print(self.quick_notif_list)
|
||||
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
|
||||
art.save()
|
||||
prev_art.save()
|
||||
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
|
||||
art.save()
|
||||
next_art.save()
|
||||
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
|
||||
art.save()
|
||||
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
|
||||
art.save()
|
||||
self.quick_notif_list += ['qn_success']
|
||||
print(self.quick_notif_list)
|
||||
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'])
|
||||
form.instance.club = club
|
||||
form.instance.author = self.request.user
|
||||
return super(WeekmailArticleCreateView, self).form_valid(form)
|
||||
|
||||
class WeekmailArticleDeleteView(DeleteView):
|
||||
"""Delete an article"""
|
||||
model = WeekmailArticle
|
||||
template_name = 'core/delete_confirm.jinja'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user