Add news moderation tool

This commit is contained in:
Skia 2016-12-23 18:40:12 +01:00
parent c95e7565e7
commit 1dc1a0a42c
12 changed files with 386 additions and 100 deletions

View File

@ -3,6 +3,10 @@
{% block content %} {% block content %}
<h3>{% trans %}Club tools{% endtrans %}</h3> <h3>{% trans %}Club tools{% endtrans %}</h3>
<div> <div>
<h4>{% trans %}Communication:{% endtrans %}</h4>
<ul>
<li> <a href="{{ url('com:news_new') }}?club={{ object.id }}">{% trans %}Create a news{% endtrans %}</a></li>
</ul>
<h4>{% trans %}Counters:{% endtrans %}</h4> <h4>{% trans %}Counters:{% endtrans %}</h4>
<ul> <ul>
{% if object.unix_name == settings.SITH_LAUNDERETTE_MANAGER['unix_name'] %} {% if object.unix_name == settings.SITH_LAUNDERETTE_MANAGER['unix_name'] %}

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
('com', '0002_news_newsdate'),
]
operations = [
migrations.RenameField(
model_name='news',
old_name='owner',
new_name='author',
),
migrations.AlterField(
model_name='news',
name='moderator',
field=models.ForeignKey(null=True, to=settings.AUTH_USER_MODEL, related_name='moderated_news', verbose_name='moderator'),
),
]

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
('com', '0003_auto_20161223_1548'),
]
operations = [
migrations.AlterField(
model_name='news',
name='author',
field=models.ForeignKey(to=settings.AUTH_USER_MODEL, related_name='owned_news', verbose_name='author'),
),
]

View File

@ -32,9 +32,18 @@ class News(models.Model):
content = models.TextField(_("content")) content = models.TextField(_("content"))
type = models.CharField(_("type"), max_length=16, choices=NEWS_TYPES, default="EVENT") type = models.CharField(_("type"), max_length=16, choices=NEWS_TYPES, default="EVENT")
club = models.ForeignKey(Club, related_name="news", verbose_name=_("club")) club = models.ForeignKey(Club, related_name="news", verbose_name=_("club"))
owner = models.ForeignKey(User, related_name="owned_news", verbose_name=_("owner")) author = models.ForeignKey(User, related_name="owned_news", verbose_name=_("author"))
is_moderated = models.BooleanField(_("is moderated"), default=False) is_moderated = models.BooleanField(_("is moderated"), default=False)
moderator = models.ForeignKey(User, related_name="moderated_news", verbose_name=_("owner"), null=True) moderator = models.ForeignKey(User, related_name="moderated_news", verbose_name=_("moderator"), null=True)
def is_owned_by(self, user):
return user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) or user == self.author
def can_be_edited_by(self, user):
return user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID)
def can_be_viewed_by(self, user):
return self.is_moderated or user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('com:news_detail', kwargs={'news_id': self.id}) return reverse('com:news_detail', kwargs={'news_id': self.id})

View File

@ -1,4 +1,5 @@
{% extends "core/base.jinja" %} {% extends "core/base.jinja" %}
{% from 'core/macros.jinja' import user_profile_link %}
{% block title %} {% block title %}
{% trans %}News admin{% endtrans %} {% trans %}News admin{% endtrans %}
@ -6,19 +7,73 @@
{% block content %} {% block content %}
<h3>{% trans %}News{% endtrans %}</h3> <h3>{% trans %}News{% endtrans %}</h3>
<ul> <h4>{% trans %}Displayed news{% endtrans %}</h4>
{% for news in object_list %} <table>
<li> <thead>
<p>{{ news.get_type_display() }} - {{ news.title }}: <tr>
<span>{{ news.dates.first().start_date|localtime|date(DATETIME_FORMAT) }} <td>{% trans %}Type{% endtrans %}</td>
{{ news.dates.first().start_date|localtime|time(DATETIME_FORMAT) }}</span> - <td>{% trans %}Title{% endtrans %}</td>
<span>{{ news.dates.first().end_date|localtime|date(DATETIME_FORMAT) }} <td>{% trans %}Summary{% endtrans %}</td>
{{ news.dates.first().end_date|localtime|time(DATETIME_FORMAT) }}</span> - <td>{% trans %}Club{% endtrans %}</td>
<a href="{{ url('com:news_edit', news_id=news.id) }}">{% trans %}Edit{% endtrans %}</a> <td>{% trans %}Author{% endtrans %}</td>
</p> <td>{% trans %}Moderator{% endtrans %}</td>
</li> <td>{% trans %}Start{% endtrans %}</td>
<td>{% trans %}End{% endtrans %}</td>
<td>{% trans %}Actions{% endtrans %}</td>
</tr>
</thead>
<tbody>
{% for news in object_list.filter(is_moderated=True) %}
<tr>
<td>{{ news.get_type_display() }}</td>
<td>{{ news.title }}</td>
<td>{{ news.summary|markdown }}</td>
<td><a href="{{ news.club.get_absolute_url() }}">{{ news.club }}</a></td>
<td>{{ user_profile_link(news.author) }}</td>
<td>{{ user_profile_link(news.moderator) }}</td>
<td>{{ news.dates.first().start_date|localtime|date(DATETIME_FORMAT) }}
{{ news.dates.first().start_date|localtime|time(DATETIME_FORMAT) }}</td>
<td>{{ news.dates.first().end_date|localtime|date(DATETIME_FORMAT) }}
{{ news.dates.first().end_date|localtime|time(DATETIME_FORMAT) }}</td>
<td><a href="{{ url('com:news_detail', news_id=news.id) }}">{% trans %}View{% endtrans %}</a>
<a href="{{ url('com:news_edit', news_id=news.id) }}">{% trans %}Edit{% endtrans %}</a> </td>
</tr>
{% endfor %} {% endfor %}
</ul> </tbody>
</table>
<h4>{% trans %}News to moderate{% endtrans %}</h4>
<table>
<thead>
<tr>
<td>{% trans %}Type{% endtrans %}</td>
<td>{% trans %}Title{% endtrans %}</td>
<td>{% trans %}Summary{% endtrans %}</td>
<td>{% trans %}Club{% endtrans %}</td>
<td>{% trans %}Author{% endtrans %}</td>
<td>{% trans %}Start{% endtrans %}</td>
<td>{% trans %}End{% endtrans %}</td>
<td>{% trans %}Actions{% endtrans %}</td>
</tr>
</thead>
<tbody>
{% for news in object_list.filter(is_moderated=False) %}
<tr>
<td>{{ news.get_type_display() }}</td>
<td>{{ news.title }}</td>
<td>{{ news.summary|markdown }}</td>
<td><a href="{{ news.club.get_absolute_url() }}">{{ news.club }}</a></td>
<td>{{ user_profile_link(news.author) }}</td>
<td>{{ news.dates.first().start_date|localtime|date(DATETIME_FORMAT) }}
{{ news.dates.first().start_date|localtime|time(DATETIME_FORMAT) }}</td>
<td>{{ news.dates.first().end_date|localtime|date(DATETIME_FORMAT) }}
{{ news.dates.first().end_date|localtime|time(DATETIME_FORMAT) }}</td>
<td><a href="{{ url('com:news_detail', news_id=news.id) }}">{% trans %}View{% endtrans %}</a>
<a href="{{ url('com:news_edit', news_id=news.id) }}">{% trans %}Edit{% endtrans %}</a>
<a href="{{ url('com:news_moderate', news_id=news.id) }}">{% trans %}Moderate{% endtrans %}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %} {% endblock %}

View File

@ -1,4 +1,5 @@
{% extends "core/base.jinja" %} {% extends "core/base.jinja" %}
{% from 'core/macros.jinja' import user_profile_link %}
{% block title %} {% block title %}
{% trans %}News{% endtrans %} - {% trans %}News{% endtrans %} -
@ -6,9 +7,30 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<p><a href="{{ url('com:news_list') }}">{% trans %}Back to news{% endtrans %}</a></p>
<h3>{% trans %}News{% endtrans %}</h3> <h3>{% trans %}News{% endtrans %}</h3>
{{ object }} {% if user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) or user.is_root %}
{{ object.dates.all() }} {% endif %}
<section class="news_event">
<h4>{{ news.title }}</h4>
<p class="date">
<span>{{ news.dates.first().start_date|localtime|date(DATETIME_FORMAT) }}
{{ news.dates.first().start_date|localtime|time(DATETIME_FORMAT) }}</span> -
<span>{{ news.dates.first().end_date|localtime|date(DATETIME_FORMAT) }}
{{ news.dates.first().end_date|localtime|time(DATETIME_FORMAT) }}</span>
</p>
<p><a href="{{ news.club.get_absolute_url() }}">{{ news.club }}</a></p>
<p>{{ news.summary|markdown }}</p>
<p>{% trans %}Author: {% endtrans %}{{ user_profile_link(news.author) }}</p>
{% if news.moderator %}
<p>{% trans %}Moderator: {% endtrans %}{{ user_profile_link(news.moderator) }}</p>
{% elif user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) %}
<p> <a href="{{ url('com:news_moderate', news_id=news.id) }}">{% trans %}Moderate{% endtrans %}</a></p>
{% endif %}
{% if user.can_edit(news) %}
<p> <a href="{{ url('com:news_edit', news_id=news.id) }}">{% trans %}Edit (will be remoderated){% endtrans %}</a></p>
{% endif %}
</section>
{% endblock %} {% endblock %}

View File

@ -17,8 +17,15 @@
<form action="" method="post"> <form action="" method="post">
{% csrf_token %} {% csrf_token %}
{{ form.non_field_errors() }} {{ form.non_field_errors() }}
{{ form.owner }} {{ form.author }}
<p>{{ form.type.errors }}<label for="{{ form.type.name }}">{{ form.type.label }}</label> {{ form.type }}</p> <p>{{ form.type.errors }}<label for="{{ form.type.name }}">{{ form.type.label }}</label>
<ul>
<li>Notice: Information, election result - no date</li>
<li>Evenement: punctual event, associated with one date</li>
<li>Weekly: recurrent event, associated with many dates (specify the first one, and a deadline)</li>
<li>Call: long time event, associated with a long date (election appliance, ...)</li>
</ul>
{{ form.type }}</p>
<p class="date">{{ form.start_date.errors }}<label for="{{ form.start_date.name }}">{{ form.start_date.label }}</label> {{ form.start_date }}</p> <p class="date">{{ form.start_date.errors }}<label for="{{ form.start_date.name }}">{{ form.start_date.label }}</label> {{ form.start_date }}</p>
<p class="date">{{ form.end_date.errors }}<label for="{{ form.end_date.name }}">{{ form.end_date.label }}</label> {{ form.end_date }}</p> <p class="date">{{ form.end_date.errors }}<label for="{{ form.end_date.name }}">{{ form.end_date.label }}</label> {{ form.end_date }}</p>
<p class="until">{{ form.until.errors }}<label for="{{ form.until.name }}">{{ form.until.label }}</label> {{ form.until }}</p> <p class="until">{{ form.until.errors }}<label for="{{ form.until.name }}">{{ form.until.label }}</label> {{ form.until }}</p>
@ -26,6 +33,10 @@
<p>{{ form.club.errors }}<label for="{{ form.club.name }}">{{ form.club.label }}</label> {{ form.club }}</p> <p>{{ form.club.errors }}<label for="{{ form.club.name }}">{{ form.club.label }}</label> {{ form.club }}</p>
<p>{{ form.summary.errors }}<label for="{{ form.summary.name }}">{{ form.summary.label }}</label> {{ form.summary }}</p> <p>{{ form.summary.errors }}<label for="{{ form.summary.name }}">{{ form.summary.label }}</label> {{ form.summary }}</p>
<p>{{ form.content.errors }}<label for="{{ form.content.name }}">{{ form.content.label }}</label> {{ form.content }}</p> <p>{{ form.content.errors }}<label for="{{ form.content.name }}">{{ form.content.label }}</label> {{ form.content }}</p>
{% if user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) %}
<p>{{ form.automoderation.errors }}<label for="{{ form.automoderation.name }}">{{ form.automoderation.label }}</label>
{{ form.automoderation }}</p>
{% endif %}
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p> <p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
</form> </form>
{% endblock %} {% endblock %}

View File

@ -10,10 +10,11 @@
section { section {
padding: 5px; padding: 5px;
} }
section.news_call { section.news_call, section.news_notice {
background: lightgrey; background: lightgrey;
margin: 2px;
} }
section.news_event:nth-child(even) { section.news_event:nth-of-type(even) {
background: lightblue; background: lightblue;
} }
.date { .date {
@ -25,50 +26,62 @@ section.news_event:nth-child(even) {
{% block content %} {% block content %}
<h3>{% trans %}News{% endtrans %}</h3> <h3>{% trans %}News{% endtrans %}</h3>
<hr>
<h4>{% trans %}Notice{% endtrans %}</h4>
{% for news in object_list.filter(type="NOTICE") %} {% for news in object_list.filter(type="NOTICE") %}
<section class="news_notice"> <section class="news_notice">
<h4>{{ news.title }}</h4> <h4> <a href="{{ url('com:news_detail', news_id=news.id) }}">{{ news.title }}</a></h4>
<p>{{ news.summary }}</p> <p>{{ news.summary|markdown }}</p>
</section> </section>
{% endfor %} {% endfor %}
<hr>
<h4>{% trans %}Calls{% endtrans %}</h4>
{% for news in object_list.filter(dates__start_date__lte=timezone.now(), dates__end_date__gte=timezone.now(), type="CALL") %} {% for news in object_list.filter(dates__start_date__lte=timezone.now(), dates__end_date__gte=timezone.now(), type="CALL") %}
<section class="news_call"> <section class="news_call">
<h4>{{ news.title }}</h4> <h4> <a href="{{ url('com:news_detail', news_id=news.id) }}">{{ news.title }}</a></h4>
<p class="date"> <p class="date">
<span>{{ news.dates.first().start_date|localtime|date(DATETIME_FORMAT) }} <span>{{ news.dates.first().start_date|localtime|date(DATETIME_FORMAT) }}
{{ news.dates.first().start_date|localtime|time(DATETIME_FORMAT) }}</span> - {{ news.dates.first().start_date|localtime|time(DATETIME_FORMAT) }}</span> -
<span>{{ news.dates.first().end_date|localtime|date(DATETIME_FORMAT) }} <span>{{ news.dates.first().end_date|localtime|date(DATETIME_FORMAT) }}
{{ news.dates.first().end_date|localtime|time(DATETIME_FORMAT) }}</span> {{ news.dates.first().end_date|localtime|time(DATETIME_FORMAT) }}</span>
</p> </p>
<p>{{ news.summary }}</p> <p>{{ news.summary|markdown }}</p>
</section> </section>
{% endfor %} {% endfor %}
<hr> <hr>
<h4>{% trans %}Events{% endtrans %}</h4> <h4>{% trans %}Events today and the next few days{% endtrans %}</h4>
{% for news in object_list.filter(dates__end_date__gte=timezone.now(), type="EVENT") %} {% for d in NewsDate.objects.filter(end_date__gte=timezone.now(), start_date__lte=timezone.now()+timedelta(days=5),
news__type="EVENT", news__is_moderated=True).datetimes('start_date', 'day') %}
<h5 class="date">{{ d|localtime|date(DATETIME_FORMAT) }}</h5>
{% for news in object_list.filter(dates__start_date__gte=d, dates__start_date__lte=d+timedelta(days=1),
type="EVENT").exclude(dates__end_date__lt=timezone.now()) %}
<section class="news_event"> <section class="news_event">
<h4>{{ news.title }}</h4> <h4> <a href="{{ url('com:news_detail', news_id=news.id) }}">{{ news.title }}</a></h4>
<p class="date"> <p class="date">
<span>{{ news.dates.first().start_date|localtime|date(DATETIME_FORMAT) }} <span>{{ news.dates.first().start_date|localtime|time(DATETIME_FORMAT) }}</span> -
{{ news.dates.first().start_date|localtime|time(DATETIME_FORMAT) }}</span> - <span>{{ news.dates.first().end_date|localtime|time(DATETIME_FORMAT) }}</span>
<span>{{ news.dates.first().end_date|localtime|date(DATETIME_FORMAT) }}
{{ news.dates.first().end_date|localtime|time(DATETIME_FORMAT) }}</span>
</p> </p>
<p><a href="{{ news.club.get_absolute_url() }}">{{ news.club }}</a></p> <p><a href="{{ news.club.get_absolute_url() }}">{{ news.club }}</a></p>
<p>{{ news.summary|markdown }}</p> <p>{{ news.summary|markdown }}</p>
</section> </section>
{% endfor %} {% endfor %}
<hr> <hr>
<h4>{% trans %}Coming soon... don't miss!{% endtrans %}</h4>
{% endfor %}
{% for news in object_list.filter(dates__start_date__gte=timezone.now()+timedelta(days=5), type="EVENT") %}
<section>
<h4> <a href="{{ url('com:news_detail', news_id=news.id) }}">{{ news.title }}</a>
<span class="date">{{ news.dates.first().start_date|localtime|date(DATETIME_FORMAT) }}
{{ news.dates.first().start_date|localtime|time(DATETIME_FORMAT) }} -
{{ news.dates.first().end_date|localtime|date(DATETIME_FORMAT) }}
{{ news.dates.first().end_date|localtime|time(DATETIME_FORMAT) }}</span>
</h4>
</section>
{% endfor %}
<!--
<hr>
<h4>{% trans %}Weekly{% endtrans %}</h4> <h4>{% trans %}Weekly{% endtrans %}</h4>
{% for news in object_list.filter(dates__end_date__gte=timezone.now(), type="WEEKLY").distinct() %} {% for news in object_list.filter(dates__end_date__gte=timezone.now(), type="WEEKLY").distinct() %}
<!-- buggy when more than one news, anyway, we won't use it this way --> buggy when more than one news, anyway, we won't use it this way
{% for d in news.dates.all() %} {% for d in news.dates.all() %}
<section class="news_weekly"> <section class="news_weekly">
<h4>{{ news.title }}</h4> <h4> <a href="{{ url('com:news_detail', news_id=news.id) }}">{{ news.title }}</a></h4>
<p class="date"> <p class="date">
<span>{{ d.start_date|localtime|date(DATETIME_FORMAT) }} <span>{{ d.start_date|localtime|date(DATETIME_FORMAT) }}
{{ d.start_date|localtime|time(DATETIME_FORMAT) }}</span> - {{ d.start_date|localtime|time(DATETIME_FORMAT) }}</span> -
@ -80,6 +93,7 @@ section.news_event:nth-child(even) {
</section> </section>
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
-->
{% endblock %} {% endblock %}

View File

@ -9,6 +9,7 @@ urlpatterns = [
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'),
url(r'^news/(?P<news_id>[0-9]+)/moderate$', NewsModerateView.as_view(), name='news_moderate'),
url(r'^news/(?P<news_id>[0-9]+)/edit$', NewsEditView.as_view(), name='news_edit'), url(r'^news/(?P<news_id>[0-9]+)/edit$', NewsEditView.as_view(), name='news_edit'),
url(r'^news/(?P<news_id>[0-9]+)$', NewsDetailView.as_view(), name='news_detail'), url(r'^news/(?P<news_id>[0-9]+)$', NewsDetailView.as_view(), name='news_detail'),
] ]

View File

@ -1,6 +1,7 @@
from django.shortcuts import render from django.shortcuts import render, redirect
from django.views.generic import ListView, DetailView, RedirectView from django.views.generic import ListView, DetailView, RedirectView
from django.views.generic.edit import UpdateView, CreateView from django.views.generic.edit import UpdateView, CreateView
from django.views.generic.detail import SingleObjectMixin
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse, reverse_lazy from django.core.urlresolvers import reverse, reverse_lazy
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
@ -10,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
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin, CanCreateMixin
from core.views.forms import SelectDateTime from core.views.forms import SelectDateTime
from club.models import Club from club.models import Club
@ -69,14 +70,15 @@ class IndexEditView(ComEditView):
class NewsForm(forms.ModelForm): class NewsForm(forms.ModelForm):
class Meta: class Meta:
model = News model = News
fields = ['type', 'title', 'club', 'summary', 'content', 'owner'] fields = ['type', 'title', 'club', 'summary', 'content', 'author']
widgets = { widgets = {
'owner': forms.HiddenInput, 'author': forms.HiddenInput,
'type': forms.RadioSelect, 'type': forms.RadioSelect,
} }
start_date = forms.DateTimeField(['%Y-%m-%d %H:%M:%S'], label=_("Start date"), widget=SelectDateTime, required=False) start_date = forms.DateTimeField(['%Y-%m-%d %H:%M:%S'], label=_("Start date"), widget=SelectDateTime, required=False)
end_date = forms.DateTimeField(['%Y-%m-%d %H:%M:%S'], label=_("End date"), widget=SelectDateTime, required=False) end_date = forms.DateTimeField(['%Y-%m-%d %H:%M:%S'], label=_("End date"), widget=SelectDateTime, required=False)
until = forms.DateTimeField(['%Y-%m-%d %H:%M:%S'], label=_("Until"), widget=SelectDateTime, required=False) until = forms.DateTimeField(['%Y-%m-%d %H:%M:%S'], label=_("Until"), widget=SelectDateTime, required=False)
automoderation = forms.BooleanField(label=_("Automoderation"), required=False)
def clean(self): def clean(self):
self.cleaned_data = super(NewsForm, self).clean() self.cleaned_data = super(NewsForm, self).clean()
@ -107,7 +109,7 @@ class NewsForm(forms.ModelForm):
end_date += timedelta(days=7) end_date += timedelta(days=7)
return ret return ret
class NewsEditView(UpdateView): class NewsEditView(CanEditMixin, UpdateView):
model = News model = News
form_class = NewsForm form_class = NewsForm
template_name = 'com/news_edit.jinja' template_name = 'com/news_edit.jinja'
@ -123,27 +125,70 @@ class NewsEditView(UpdateView):
except: pass except: pass
return init return init
class NewsCreateView(CreateView): def form_valid(self, form):
self.object = form.save()
if form.cleaned_data['automoderation'] and self.request.user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID):
self.object.moderator = self.request.user
self.object.is_moderated = True
self.object.save()
else:
self.object.is_moderated = False
self.object.save()
return super(NewsEditView, self).form_valid(form)
class NewsCreateView(CanCreateMixin, CreateView):
model = News model = News
form_class = NewsForm form_class = NewsForm
template_name = 'com/news_edit.jinja' template_name = 'com/news_edit.jinja'
def get_initial(self): def get_initial(self):
init = {'owner': self.request.user} init = {'author': self.request.user}
try: try:
init['club'] = Club.objects.filter(id=self.request.GET['club']).first() init['club'] = Club.objects.filter(id=self.request.GET['club']).first()
except: pass except: pass
return init return init
class NewsAdminListView(ListView): def form_valid(self, form):
self.object = form.save()
print(form.cleaned_data)
if form.cleaned_data['automoderation'] and self.request.user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID):
print("GUY")
self.object.moderator = self.request.user
self.object.is_moderated = True
self.object.save()
return super(NewsCreateView, self).form_valid(form)
class NewsModerateView(CanEditMixin, SingleObjectMixin):
model = News
pk_url_kwarg = 'news_id'
def get(self, request, *args, **kwargs):
self.object = self.get_object()
self.object.is_moderated = True
self.object.moderator = request.user
self.object.save()
if 'next' in self.request.GET.keys():
return redirect(self.request.GET['next'])
return redirect('com:news_admin_list')
class NewsAdminListView(CanEditMixin, ListView):
model = News model = News
template_name = 'com/news_admin_list.jinja' template_name = 'com/news_admin_list.jinja'
queryset = News.objects.filter(dates__end_date__gte=timezone.now()).distinct().order_by('id')
class NewsListView(ListView): class NewsListView(CanViewMixin, ListView):
model = News model = News
template_name = 'com/news_list.jinja' template_name = 'com/news_list.jinja'
class NewsDetailView(DetailView): def get_context_data(self, **kwargs):
kwargs = super(NewsListView, self).get_context_data(**kwargs)
kwargs['NewsDate'] = NewsDate
kwargs['timedelta'] = timedelta
return kwargs
class NewsDetailView(CanViewMixin, DetailView):
model = News model = News
template_name = 'com/news_detail.jinja' template_name = 'com/news_detail.jinja'
pk_url_kwarg = 'news_id' pk_url_kwarg = 'news_id'

View File

@ -66,6 +66,7 @@
<h4>{% trans %}Communication{% endtrans %}</h4> <h4>{% trans %}Communication{% endtrans %}</h4>
<ul> <ul>
{% if user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) or user.is_root %} {% if user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) or user.is_root %}
<li><a href="{{ url('com:news_admin_list') }}">{% trans %}Moderate news{% endtrans %}</a></li>
<li><a href="{{ url('com:index_edit') }}">{% trans %}Edit index page{% endtrans %}</a></li> <li><a href="{{ url('com:index_edit') }}">{% trans %}Edit index page{% endtrans %}</a></li>
<li><a href="{{ url('com:alert_edit') }}">{% trans %}Edit alert message{% endtrans %}</a></li> <li><a href="{{ url('com:alert_edit') }}">{% trans %}Edit alert message{% endtrans %}</a></li>
<li><a href="{{ url('com:info_edit') }}">{% trans %}Edit information message{% endtrans %}</a></li> <li><a href="{{ url('com:info_edit') }}">{% trans %}Edit information message{% endtrans %}</a></li>

View File

@ -6,7 +6,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-12-23 03:16+0100\n" "POT-Creation-Date: 2016-12-23 18:25+0100\n"
"PO-Revision-Date: 2016-07-18\n" "PO-Revision-Date: 2016-07-18\n"
"Last-Translator: Skia <skia@libskia.so>\n" "Last-Translator: Skia <skia@libskia.so>\n"
"Language-Team: AE info <ae.info@utbm.fr>\n" "Language-Team: AE info <ae.info@utbm.fr>\n"
@ -178,6 +178,8 @@ msgid "User"
msgstr "Utilisateur" msgstr "Utilisateur"
#: accounting/models.py:207 club/templates/club/club_detail.jinja:5 #: accounting/models.py:207 club/templates/club/club_detail.jinja:5
#: com/templates/com/news_admin_list.jinja:17
#: com/templates/com/news_admin_list.jinja:51
#: counter/templates/counter/invoices_call.jinja:20 #: counter/templates/counter/invoices_call.jinja:20
msgid "Club" msgid "Club"
msgstr "Club" msgstr "Club"
@ -347,7 +349,8 @@ msgstr "Nouveau compte club"
#: accounting/templates/accounting/bank_account_list.jinja:21 #: accounting/templates/accounting/bank_account_list.jinja:21
#: accounting/templates/accounting/club_account_details.jinja:55 #: accounting/templates/accounting/club_account_details.jinja:55
#: accounting/templates/accounting/journal_details.jinja:73 club/views.py:54 #: accounting/templates/accounting/journal_details.jinja:73 club/views.py:54
#: com/templates/com/news_admin_list.jinja:17 core/templates/core/file.jinja:38 #: com/templates/com/news_admin_list.jinja:39
#: com/templates/com/news_admin_list.jinja:71 core/templates/core/file.jinja:38
#: core/templates/core/page.jinja:31 core/templates/core/user_tools.jinja:38 #: core/templates/core/page.jinja:31 core/templates/core/user_tools.jinja:38
#: core/views/user.py:152 counter/templates/counter/cash_summary_list.jinja:53 #: core/views/user.py:152 counter/templates/counter/cash_summary_list.jinja:53
#: counter/templates/counter/counter_list.jinja:17 #: counter/templates/counter/counter_list.jinja:17
@ -411,10 +414,14 @@ msgid "Name"
msgstr "Nom" msgstr "Nom"
#: accounting/templates/accounting/club_account_details.jinja:29 #: accounting/templates/accounting/club_account_details.jinja:29
#: com/templates/com/news_admin_list.jinja:20
#: com/templates/com/news_admin_list.jinja:53
msgid "Start" msgid "Start"
msgstr "Début" msgstr "Début"
#: accounting/templates/accounting/club_account_details.jinja:30 #: accounting/templates/accounting/club_account_details.jinja:30
#: com/templates/com/news_admin_list.jinja:21
#: com/templates/com/news_admin_list.jinja:54
msgid "End" msgid "End"
msgstr "Fin" msgstr "Fin"
@ -436,6 +443,8 @@ msgstr "Fermé"
#: accounting/templates/accounting/club_account_details.jinja:34 #: accounting/templates/accounting/club_account_details.jinja:34
#: accounting/templates/accounting/journal_details.jinja:41 #: accounting/templates/accounting/journal_details.jinja:41
#: com/templates/com/news_admin_list.jinja:22
#: com/templates/com/news_admin_list.jinja:55
msgid "Actions" msgid "Actions"
msgstr "Actions" msgstr "Actions"
@ -450,7 +459,9 @@ msgid "No"
msgstr "Non" msgstr "Non"
#: accounting/templates/accounting/club_account_details.jinja:54 #: accounting/templates/accounting/club_account_details.jinja:54
#: core/templates/core/file.jinja:36 core/templates/core/page.jinja:28 #: com/templates/com/news_admin_list.jinja:38
#: com/templates/com/news_admin_list.jinja:70 core/templates/core/file.jinja:36
#: core/templates/core/page.jinja:28
msgid "View" msgid "View"
msgstr "Voir" msgstr "Voir"
@ -616,7 +627,7 @@ msgid "Edit operation"
msgstr "Éditer l'opération" msgstr "Éditer l'opération"
#: accounting/templates/accounting/operation_edit.jinja:41 #: accounting/templates/accounting/operation_edit.jinja:41
#: com/templates/com/news_edit.jinja:29 core/templates/core/create.jinja:12 #: com/templates/com/news_edit.jinja:40 core/templates/core/create.jinja:12
#: core/templates/core/edit.jinja:7 core/templates/core/edit.jinja.py:15 #: core/templates/core/edit.jinja:7 core/templates/core/edit.jinja.py:15
#: core/templates/core/edit.jinja:20 core/templates/core/file_edit.jinja:8 #: core/templates/core/edit.jinja:20 core/templates/core/file_edit.jinja:8
#: core/templates/core/page_prop.jinja:8 #: core/templates/core/page_prop.jinja:8
@ -913,19 +924,27 @@ msgid "Payment method"
msgstr "Méthode de paiement" msgstr "Méthode de paiement"
#: club/templates/club/club_tools.jinja:4 #: club/templates/club/club_tools.jinja:4
#: core/templates/core/user_tools.jinja:81 #: core/templates/core/user_tools.jinja:82
msgid "Club tools" msgid "Club tools"
msgstr "Outils club" msgstr "Outils club"
#: club/templates/club/club_tools.jinja:6 #: club/templates/club/club_tools.jinja:6
msgid "Communication:"
msgstr "Communication : "
#: club/templates/club/club_tools.jinja:8
msgid "Create a news"
msgstr "Créer une nouvelle"
#: club/templates/club/club_tools.jinja:10
msgid "Counters:" msgid "Counters:"
msgstr "Comptoirs : " msgstr "Comptoirs : "
#: club/templates/club/club_tools.jinja:22 #: club/templates/club/club_tools.jinja:26
msgid "Accouting: " msgid "Accouting: "
msgstr "Comptabilité : " msgstr "Comptabilité : "
#: club/templates/club/club_tools.jinja:30 #: club/templates/club/club_tools.jinja:34
msgid "Manage launderettes" msgid "Manage launderettes"
msgstr "Gestion des laveries" msgstr "Gestion des laveries"
@ -960,7 +979,7 @@ msgstr "Vous n'avez pas la permission de faire cela"
msgid "Begin date" msgid "Begin date"
msgstr "Date de début" msgstr "Date de début"
#: club/views.py:166 com/views.py:78 counter/views.py:909 #: club/views.py:166 com/views.py:79 counter/views.py:909
msgid "End date" msgid "End date"
msgstr "Date de fin" msgstr "Date de fin"
@ -981,7 +1000,7 @@ msgstr "message d'info"
msgid "index page" msgid "index page"
msgstr "page d'accueil" msgstr "page d'accueil"
#: com/models.py:22 com/templates/com/news_list.jinja:29 #: com/models.py:22
msgid "Notice" msgid "Notice"
msgstr "Notification" msgstr "Notification"
@ -989,7 +1008,7 @@ msgstr "Notification"
msgid "Event" msgid "Event"
msgstr "Événement" msgstr "Événement"
#: com/models.py:24 com/templates/com/news_list.jinja:66 #: com/models.py:24 com/templates/com/news_list.jinja:79
msgid "Weekly" msgid "Weekly"
msgstr "Hebdomadaire" msgstr "Hebdomadaire"
@ -1014,36 +1033,98 @@ msgstr "contenu de la nouvelle"
msgid "type" msgid "type"
msgstr "type" msgstr "type"
#: com/models.py:35 com/models.py:37 core/models.py:524 core/models.py:532 #: com/models.py:35
msgid "owner" msgid "author"
msgstr "propriétaire" msgstr "auteur"
#: com/models.py:36 core/models.py:531 #: com/models.py:36 core/models.py:531
msgid "is moderated" msgid "is moderated"
msgstr "est modéré" msgstr "est modéré"
#: com/models.py:52 #: com/models.py:37
msgid "moderator"
msgstr "modérateur"
#: com/models.py:61
msgid "news_date" msgid "news_date"
msgstr "date de la nouvelle" msgstr "date de la nouvelle"
#: com/models.py:53 #: com/models.py:62
msgid "start_date" msgid "start_date"
msgstr "date de début" msgstr "date de début"
#: com/models.py:54 #: com/models.py:63
msgid "end_date" msgid "end_date"
msgstr "date de fin" msgstr "date de fin"
#: com/templates/com/news_admin_list.jinja:4 #: com/templates/com/news_admin_list.jinja:5
msgid "News admin" msgid "News admin"
msgstr "Administration des nouvelles" msgstr "Administration des nouvelles"
#: com/templates/com/news_admin_list.jinja:8 #: com/templates/com/news_admin_list.jinja:9
#: com/templates/com/news_detail.jinja:4 com/templates/com/news_detail.jinja:9 #: com/templates/com/news_detail.jinja:5 com/templates/com/news_detail.jinja:11
#: com/templates/com/news_list.jinja:4 com/templates/com/news_list.jinja:27 #: com/templates/com/news_list.jinja:4 com/templates/com/news_list.jinja:28
msgid "News" msgid "News"
msgstr "Nouvelles" msgstr "Nouvelles"
#: com/templates/com/news_admin_list.jinja:10
msgid "Displayed news"
msgstr "Nouvelles affichées"
#: com/templates/com/news_admin_list.jinja:14
#: com/templates/com/news_admin_list.jinja:48
#: launderette/templates/launderette/launderette_admin.jinja:42
#: launderette/views.py:156
msgid "Type"
msgstr "Type"
#: com/templates/com/news_admin_list.jinja:15
#: com/templates/com/news_admin_list.jinja:49
msgid "Title"
msgstr "Titre"
#: com/templates/com/news_admin_list.jinja:16
#: com/templates/com/news_admin_list.jinja:50
msgid "Summary"
msgstr "Résumé"
#: com/templates/com/news_admin_list.jinja:18
#: com/templates/com/news_admin_list.jinja:52
msgid "Author"
msgstr "Auteur"
#: com/templates/com/news_admin_list.jinja:19
msgid "Moderator"
msgstr "Modérateur"
#: com/templates/com/news_admin_list.jinja:44
msgid "News to moderate"
msgstr "Nouvelles à modérer"
#: com/templates/com/news_admin_list.jinja:72
#: com/templates/com/news_detail.jinja:28
#: core/templates/core/file_detail.jinja:65
#: core/templates/core/file_moderation.jinja:23
#: sas/templates/sas/moderation.jinja:17 sas/templates/sas/picture.jinja:114
msgid "Moderate"
msgstr "Modérer"
#: com/templates/com/news_detail.jinja:10
msgid "Back to news"
msgstr "Retour aux nouvelles"
#: com/templates/com/news_detail.jinja:24
msgid "Author: "
msgstr "Auteur : "
#: com/templates/com/news_detail.jinja:26 sas/templates/sas/picture.jinja:82
msgid "Moderator: "
msgstr "Modérateur : "
#: com/templates/com/news_detail.jinja:31
msgid "Edit (will be remoderated)"
msgstr "Éditer (sera resoumise à modération)"
#: com/templates/com/news_edit.jinja:5 com/templates/com/news_edit.jinja:13 #: com/templates/com/news_edit.jinja:5 com/templates/com/news_edit.jinja:13
msgid "Edit news" msgid "Edit news"
msgstr "Éditer la nouvelle" msgstr "Éditer la nouvelle"
@ -1052,39 +1133,43 @@ msgstr "Éditer la nouvelle"
msgid "Create news" msgid "Create news"
msgstr "Créer nouvelle" msgstr "Créer nouvelle"
#: com/templates/com/news_list.jinja:37 #: com/templates/com/news_list.jinja:48
msgid "Calls" msgid "Events today and the next few days"
msgstr "Appels" msgstr "Événement aujourd'hui et dans les prochains jours"
#: com/templates/com/news_list.jinja:51 #: com/templates/com/news_list.jinja:65
msgid "Events" msgid "Coming soon... don't miss!"
msgstr "Événements" msgstr "Prochainement... à ne pas rater!"
#: com/views.py:24 #: com/views.py:25
msgid "Communication administration" msgid "Communication administration"
msgstr "Administration de la communication" msgstr "Administration de la communication"
#: com/views.py:31 #: com/views.py:32
msgid "Index page" msgid "Index page"
msgstr "Page d'accueil" msgstr "Page d'accueil"
#: com/views.py:36 #: com/views.py:37
msgid "Info message" msgid "Info message"
msgstr "Message d'info" msgstr "Message d'info"
#: com/views.py:41 #: com/views.py:42
msgid "Alert message" msgid "Alert message"
msgstr "Message d'alerte" msgstr "Message d'alerte"
#: com/views.py:77 #: com/views.py:78
msgid "Start date" msgid "Start date"
msgstr "Date de début" msgstr "Date de début"
#: com/views.py:79 #: com/views.py:80
msgid "Until" msgid "Until"
msgstr "Jusqu'à" msgstr "Jusqu'à"
#: com/views.py:85 com/views.py:87 com/views.py:89 #: com/views.py:81
msgid "Automoderation"
msgstr "Automodération"
#: com/views.py:87 com/views.py:89 com/views.py:91
msgid "This field is required." msgid "This field is required."
msgstr "Ce champ est obligatoire." msgstr "Ce champ est obligatoire."
@ -1406,6 +1491,10 @@ msgstr "version allégée"
msgid "thumbnail" msgid "thumbnail"
msgstr "miniature" msgstr "miniature"
#: core/models.py:524 core/models.py:532
msgid "owner"
msgstr "propriétaire"
#: core/models.py:525 core/models.py:726 #: core/models.py:525 core/models.py:726
msgid "edit group" msgid "edit group"
msgstr "groupe d'édition" msgstr "groupe d'édition"
@ -1720,12 +1809,6 @@ msgstr "octets"
msgid "Download" msgid "Download"
msgstr "Télécharger" msgstr "Télécharger"
#: core/templates/core/file_detail.jinja:65
#: core/templates/core/file_moderation.jinja:23
#: sas/templates/sas/moderation.jinja:17 sas/templates/sas/picture.jinja:114
msgid "Moderate"
msgstr "Modérer"
#: core/templates/core/file_list.jinja:19 #: core/templates/core/file_list.jinja:19
msgid "There is no file in this website." msgid "There is no file in this website."
msgstr "Il n'y a pas de fichier sur ce site web." msgstr "Il n'y a pas de fichier sur ce site web."
@ -2291,22 +2374,26 @@ msgid "Communication"
msgstr "Communication" msgstr "Communication"
#: core/templates/core/user_tools.jinja:69 #: core/templates/core/user_tools.jinja:69
msgid "Moderate news"
msgstr "Modérer les nouvelles"
#: core/templates/core/user_tools.jinja:70
msgid "Edit index page" msgid "Edit index page"
msgstr "Éditer la page d'accueil" msgstr "Éditer la page d'accueil"
#: core/templates/core/user_tools.jinja:70 #: core/templates/core/user_tools.jinja:71
msgid "Edit alert message" msgid "Edit alert message"
msgstr "Éditer le message d'alerte" msgstr "Éditer le message d'alerte"
#: core/templates/core/user_tools.jinja:71 #: core/templates/core/user_tools.jinja:72
msgid "Edit information message" msgid "Edit information message"
msgstr "Éditer le message d'informations" msgstr "Éditer le message d'informations"
#: core/templates/core/user_tools.jinja:72 #: core/templates/core/user_tools.jinja:73
msgid "Moderate files" msgid "Moderate files"
msgstr "Modérer les fichiers" msgstr "Modérer les fichiers"
#: core/templates/core/user_tools.jinja:75 #: core/templates/core/user_tools.jinja:76
msgid "Moderate pictures" msgid "Moderate pictures"
msgstr "Modérer les photos" msgstr "Modérer les photos"
@ -3031,11 +3118,6 @@ msgstr "Machines"
msgid "New machine" msgid "New machine"
msgstr "Nouvelle machine" msgstr "Nouvelle machine"
#: launderette/templates/launderette/launderette_admin.jinja:42
#: launderette/views.py:156
msgid "Type"
msgstr "Type"
#: launderette/templates/launderette/launderette_book.jinja:12 #: launderette/templates/launderette/launderette_book.jinja:12
msgid "Choose" msgid "Choose"
msgstr "Choisir" msgstr "Choisir"
@ -3147,10 +3229,6 @@ msgstr "Albums"
msgid "People" msgid "People"
msgstr "Personne(s)" msgstr "Personne(s)"
#: sas/templates/sas/picture.jinja:82
msgid "Moderator: "
msgstr "Modérateur : "
#: sas/templates/sas/picture.jinja:89 #: sas/templates/sas/picture.jinja:89
msgid "HD version" msgid "HD version"
msgstr "Version HD" msgstr "Version HD"
@ -3370,3 +3448,4 @@ msgstr "Un utilisateur avec cette adresse email existe déjà"
msgid "You must either choose an existing user or create a new one properly" msgid "You must either choose an existing user or create a new one properly"
msgstr "" msgstr ""
"Vous devez soit choisir un utilisateur existant, soit en créer un proprement" "Vous devez soit choisir un utilisateur existant, soit en créer un proprement"