From be44a3ab0bef2fcf8e1c189babbf96a18e7efdfa Mon Sep 17 00:00:00 2001
From: Skia
Date: Fri, 23 Dec 2016 19:43:59 +0100
Subject: [PATCH] Add preview button to news
---
com/templates/com/news_detail.jinja | 2 -
com/templates/com/news_edit.jinja | 34 +++++++++++++++--
com/views.py | 15 ++++++++
locale/fr/LC_MESSAGES/django.po | 57 ++++++++++++++++++++---------
4 files changed, 85 insertions(+), 23 deletions(-)
diff --git a/com/templates/com/news_detail.jinja b/com/templates/com/news_detail.jinja
index 6e3fa925..a399cd97 100644
--- a/com/templates/com/news_detail.jinja
+++ b/com/templates/com/news_detail.jinja
@@ -9,8 +9,6 @@
{% block content %}
{% trans %}Back to news{% endtrans %}
{% trans %}News{% endtrans %}
- {% if user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) or user.is_root %}
- {% endif %}
{{ news.title }}
diff --git a/com/templates/com/news_edit.jinja b/com/templates/com/news_edit.jinja
index 1b046e96..1fa00414 100644
--- a/com/templates/com/news_edit.jinja
+++ b/com/templates/com/news_edit.jinja
@@ -1,4 +1,5 @@
{% extends "core/base.jinja" %}
+{% from 'core/macros.jinja' import user_profile_link %}
{% block title %}
{% if object %}
@@ -9,6 +10,30 @@
{% endblock %}
{% block content %}
+{% if 'preview' in request.POST.keys() %}
+
+
+
+ {{ form.instance.dates.first().start_date|localtime|time(DATETIME_FORMAT) }} -
+ {{ form.instance.dates.first().end_date|localtime|time(DATETIME_FORMAT) }}
+
+ {{ form.instance.club or "Club" }}
+ {{ form.instance.summary|markdown }}
+
+
+
+ {{ form.instance.title }}
+
+ {{ form.instance.dates.first().start_date|localtime|date(DATETIME_FORMAT) }}
+ {{ form.instance.dates.first().start_date|localtime|time(DATETIME_FORMAT) }} -
+ {{ form.instance.dates.first().end_date|localtime|date(DATETIME_FORMAT) }}
+ {{ form.instance.dates.first().end_date|localtime|time(DATETIME_FORMAT) }}
+
+ {{ form.instance.club or "Club" }}
+ {{ form.instance.summary|markdown }}
+ {% trans %}Author: {% endtrans %} {{ user_profile_link(form.instance.author) }}
+
+{% endif %}
{% if object %}
{% trans %}Edit news{% endtrans %}
{% else %}
@@ -20,10 +45,10 @@
{{ form.author }}
{{ form.type.errors }}
- - Notice: Information, election result - no date
- - Evenement: punctual event, associated with one date
- - Weekly: recurrent event, associated with many dates (specify the first one, and a deadline)
- - Call: long time event, associated with a long date (election appliance, ...)
+ - {% trans %}Notice: Information, election result - no date{% endtrans %}
+ - {% trans %}Event: punctual event, associated with one date{% endtrans %}
+ - {% trans %}Weekly: recurrent event, associated with many dates (specify the first one, and a deadline){% endtrans %}
+ - {% trans %}Call: long time event, associated with a long date (election appliance, ...){% endtrans %}
{{ form.type }}
{{ form.start_date.errors }} {{ form.start_date }}
@@ -37,6 +62,7 @@
{{ form.automoderation.errors }}
{{ form.automoderation }}
{% endif %}
+
{% endblock %}
diff --git a/com/views.py b/com/views.py
index e90055ee..3b2888fb 100644
--- a/com/views.py
+++ b/com/views.py
@@ -125,6 +125,13 @@ class NewsEditView(CanEditMixin, UpdateView):
except: pass
return init
+ def post(self, request, *args, **kwargs):
+ form = self.get_form()
+ if form.is_valid() and not 'preview' in request.POST.keys():
+ return self.form_valid(form)
+ else:
+ return self.form_invalid(form)
+
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):
@@ -148,6 +155,14 @@ class NewsCreateView(CanCreateMixin, CreateView):
except: pass
return init
+ def post(self, request, *args, **kwargs):
+ form = self.get_form()
+ if form.is_valid() and not 'preview' in request.POST.keys():
+ return self.form_valid(form)
+ else:
+ self.object = form.instance
+ return self.form_invalid(form)
+
def form_valid(self, form):
self.object = form.save()
print(form.cleaned_data)
diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po
index 7f8956a7..06d8669d 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: 2016-12-23 18:25+0100\n"
+"POT-Creation-Date: 2016-12-23 19:35+0100\n"
"PO-Revision-Date: 2016-07-18\n"
"Last-Translator: Skia \n"
"Language-Team: AE info \n"
@@ -627,7 +627,7 @@ msgid "Edit operation"
msgstr "Éditer l'opération"
#: accounting/templates/accounting/operation_edit.jinja:41
-#: com/templates/com/news_edit.jinja:40 core/templates/core/create.jinja:12
+#: com/templates/com/news_edit.jinja:66 core/templates/core/create.jinja:12
#: 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/page_prop.jinja:8
@@ -1002,7 +1002,7 @@ msgstr "page d'accueil"
#: com/models.py:22
msgid "Notice"
-msgstr "Notification"
+msgstr "Information"
#: com/models.py:23
msgid "Event"
@@ -1057,6 +1057,11 @@ msgstr "date de début"
msgid "end_date"
msgstr "date de fin"
+#: com/templates/com/macros.jinja:26 com/templates/com/news_detail.jinja:22
+#: com/templates/com/news_edit.jinja:34
+msgid "Author: "
+msgstr "Auteur : "
+
#: com/templates/com/news_admin_list.jinja:5
msgid "News admin"
msgstr "Administration des nouvelles"
@@ -1102,7 +1107,7 @@ msgid "News to moderate"
msgstr "Nouvelles à modérer"
#: com/templates/com/news_admin_list.jinja:72
-#: com/templates/com/news_detail.jinja:28
+#: com/templates/com/news_detail.jinja:26
#: 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
@@ -1113,26 +1118,49 @@ msgstr "Modérer"
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
+#: com/templates/com/news_detail.jinja:24 sas/templates/sas/picture.jinja:82
msgid "Moderator: "
msgstr "Modérateur : "
-#: com/templates/com/news_detail.jinja:31
+#: com/templates/com/news_detail.jinja:29
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:6 com/templates/com/news_edit.jinja:38
msgid "Edit news"
msgstr "Éditer la nouvelle"
-#: com/templates/com/news_edit.jinja:7 com/templates/com/news_edit.jinja:15
+#: com/templates/com/news_edit.jinja:8 com/templates/com/news_edit.jinja:40
msgid "Create news"
msgstr "Créer nouvelle"
+#: com/templates/com/news_edit.jinja:48
+msgid "Notice: Information, election result - no date"
+msgstr "Information, resultat d'élection - sans date"
+
+#: com/templates/com/news_edit.jinja:49
+msgid "Event: punctual event, associated with one date"
+msgstr "Événement : événement ponctuel associé à une date"
+
+#: com/templates/com/news_edit.jinja:50
+msgid ""
+"Weekly: recurrent event, associated with many dates (specify the first one, "
+"and a deadline)"
+msgstr ""
+"Hebdomadaire : événement récurrent, associé à plusieurs dates (spécifier la première, "
+"ainsi que la date de fin)"
+
+#: com/templates/com/news_edit.jinja:51
+msgid ""
+"Call: long time event, associated with a long date (election appliance, ...)"
+msgstr ""
+"Appel : événement de longue durée, associé à une longue date (candidature, concours, ...)"
+
+#: com/templates/com/news_edit.jinja:65
+#: core/templates/core/pagerev_edit.jinja:23
+msgid "Preview"
+msgstr "Prévisualiser"
+
#: com/templates/com/news_list.jinja:48
msgid "Events today and the next few days"
msgstr "Événement aujourd'hui et dans les prochains jours"
@@ -2000,10 +2028,6 @@ msgstr "Propriétés de la page"
msgid "Edit page"
msgstr "Éditer la page"
-#: core/templates/core/pagerev_edit.jinja:23
-msgid "Preview"
-msgstr "Prévisualiser"
-
#: core/templates/core/password_change.jinja:6
#, python-format
msgid "Change password for %(user)s"
@@ -3448,4 +3472,3 @@ msgstr "Un utilisateur avec cette adresse email existe déjà"
msgid "You must either choose an existing user or create a new one properly"
msgstr ""
"Vous devez soit choisir un utilisateur existant, soit en créer un proprement"
-