From a0bd5ee8ff20e66552aaa454384b2f558bdc253d Mon Sep 17 00:00:00 2001 From: Skia Date: Thu, 11 May 2017 18:33:45 +0200 Subject: [PATCH] Some more trombi pimping --- locale/fr/LC_MESSAGES/django.po | 46 +++++++++++++++++++----- trombi/templates/trombi/user_tools.jinja | 10 ++++++ trombi/views.py | 18 +++++++++- 3 files changed, 64 insertions(+), 10 deletions(-) diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 2c8e774d..0258a475 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-05-10 23:26+0200\n" +"POT-Creation-Date: 2017-05-11 18:32+0200\n" "PO-Revision-Date: 2016-07-18\n" "Last-Translator: Skia \n" "Language-Team: AE info \n" @@ -590,7 +590,7 @@ msgstr "Effectuées" #: counter/templates/counter/cash_summary_list.jinja:37 counter/views.py:798 #: trombi/templates/trombi/comment.jinja:4 #: trombi/templates/trombi/comment.jinja:8 -#: trombi/templates/trombi/user_tools.jinja:37 +#: trombi/templates/trombi/user_tools.jinja:46 msgid "Comment" msgstr "Commentaire" @@ -4430,15 +4430,31 @@ msgstr "Éditer mon profil" msgid "Edit my pictures" msgstr "Éditer mes photos" -#: trombi/templates/trombi/user_tools.jinja:35 +#: trombi/templates/trombi/user_tools.jinja:23 +msgid "You can not write comments at this date." +msgstr "Vous ne pouvez pas commenter à cette date." + +#: trombi/templates/trombi/user_tools.jinja:25 +msgid "" +"Comments are only allowed between %(start)s (excluded) and %(end)s (included)" +msgstr "" +"Les commentaires sont autorisés entre le %(start)s (exclu) et le %(end)s " +"(inclu)" + +#: trombi/templates/trombi/user_tools.jinja:44 msgid "Edit comment" msgstr "Éditer le commentaire" -#: trombi/views.py:94 +#: trombi/views.py:101 +#, python-format +msgid "%(name)s (deadline: %(date)s)" +msgstr "%(name)s (date limite: %(date)s)" + +#: trombi/views.py:104 msgid "Select trombi" msgstr "Choisir un trombi" -#: trombi/views.py:95 +#: trombi/views.py:105 msgid "" "This allows you to subscribe to a Trombi. Be aware that you can subscribe " "only once, so don't play with that, or you will expose yourself to the " @@ -4448,19 +4464,31 @@ msgstr "" "pouvez vous inscrire qu'à un seul Trombi, donc ne jouez pas avec cet option " "ou vous encourerez la colère des admins!" -#: trombi/views.py:138 +#: trombi/views.py:151 msgid "Personal email (not UTBM)" msgstr "Email personnel (pas UTBM)" -#: trombi/views.py:139 +#: trombi/views.py:152 msgid "Phone" msgstr "Téléphone" -#: trombi/views.py:140 +#: trombi/views.py:153 msgid "Native town" msgstr "Ville d'origine" -#: trombi/views.py:165 +#: trombi/views.py:174 +msgid "" +"You can not yet write comment, you must wait for the subscription deadline " +"to be passed." +msgstr "" +"Vous ne pouvez pas encore écrire de commentaires, vous devez attendre la fin " +"des inscriptions" + +#: trombi/views.py:177 +msgid "You can not write comment anymore, the deadline is already passed." +msgstr "Vous ne pouvez plus écrire de commentaires, la date est passée." + +#: trombi/views.py:184 #, python-format msgid "Maximum characters: %(max_length)s" msgstr "Nombre de caractères max: %(max_length)s" diff --git a/trombi/templates/trombi/user_tools.jinja b/trombi/templates/trombi/user_tools.jinja index b5a09e84..dd2fdb64 100644 --- a/trombi/templates/trombi/user_tools.jinja +++ b/trombi/templates/trombi/user_tools.jinja @@ -17,6 +17,14 @@

{% trans %}Edit my profile{% endtrans %}

{% trans %}Edit my pictures{% endtrans %}


+{% set can_comment = trombi.subscription_deadline < date.today() and + date.today() <= trombi.comments_deadline %} +{% if not can_comment %} +

{% trans %}You can not write comments at this date.{% endtrans %}

+

+{% trans start=trombi.subscription_deadline|date(DATE_FORMAT), end=trombi.comments_deadline|date(DATE_FORMAT) %}Comments are only allowed between {{ start }} (excluded) and {{ end }} (included){% endtrans %}

+
+{% endif %}
{% for u in user.trombi_user.trombi.users.exclude(id=user.trombi_user.id) %}
@@ -30,12 +38,14 @@
{{ u.user.get_display_name() }}
+ {% if can_comment %} {% set comment = u.received_comments.filter(author__id=user.trombi_user.id).first() %} {% if comment %} {% trans %}Edit comment{% endtrans %} {% else %} {% trans %}Comment{% endtrans %} {% endif %} + {% endif %}
{% endfor %} diff --git a/trombi/views.py b/trombi/views.py index 3477fdc2..e8adeba0 100644 --- a/trombi/views.py +++ b/trombi/views.py @@ -22,6 +22,7 @@ # # +from django.http import Http404 from django.shortcuts import render, get_object_or_404, redirect from django.core.urlresolvers import reverse_lazy, reverse from django.views.generic import ListView, DetailView, RedirectView, TemplateView @@ -30,6 +31,8 @@ from django.utils.translation import ugettext_lazy as _ from django import forms from django.forms.models import modelform_factory +from datetime import date + from trombi.models import Trombi, TrombiUser, TrombiComment from core.views.forms import SelectFile, SelectDate from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin, CanCreateMixin, QuickNotifMixin @@ -93,8 +96,12 @@ class TrombiDeleteUserView(CanEditPropMixin, SingleObjectMixin, RedirectView): return redirect(self.object.get_absolute_url()+"?qn_success") # User side +class TrombiModelChoiceField(forms.ModelChoiceField): + def label_from_instance(self, obj): + return _("%(name)s (deadline: %(date)s)") % {'name': str(obj), 'date': str(obj.subscription_deadline)} + class UserTrombiForm(forms.Form): - trombi = forms.ModelChoiceField(Trombi.availables.all(), required=False, label=_("Select trombi"), + trombi = TrombiModelChoiceField(Trombi.availables.all(), required=False, label=_("Select trombi"), help_text=_("This allows you to subscribe to a Trombi. " "Be aware that you can subscribe only once, so don't play with that, " "or you will expose yourself to the admins' wrath!")) @@ -119,6 +126,9 @@ class UserTrombiToolsView(QuickNotifMixin, TemplateView): kwargs['user'] = self.request.user if not hasattr(self.request.user, 'trombi_user'): kwargs['subscribe_form'] = UserTrombiForm() + else: + kwargs['trombi'] = self.request.user.trombi_user.trombi + kwargs['date'] = date return kwargs class UserTrombiEditPicturesView(UpdateView): @@ -160,6 +170,12 @@ class TrombiCommentFormView(): def get_form_class(self): self.trombi = self.request.user.trombi_user.trombi + if date.today() <= self.trombi.subscription_deadline: + raise Http404(_("You can not yet write comment, you must wait for " + "the subscription deadline to be passed.")) + if self.trombi.comments_deadline < date.today(): + raise Http404(_("You can not write comment anymore, the deadline is " + "already passed.")) return modelform_factory(self.model, fields=self.fields, widgets={ 'content': forms.widgets.Textarea(attrs={'maxlength': self.trombi.max_chars})