From 2017176633643569d97808dedb35a93c7bf32117 Mon Sep 17 00:00:00 2001 From: Philippe MILINK Date: Wed, 26 Jul 2023 18:51:38 +0200 Subject: [PATCH 1/3] Renomme et change le comportement du templatetag humane_time --- doc/source/front-end/template-tags.rst | 13 +++++++------ templates/tutorialv2/view/history.html | 4 ++-- zds/utils/templatetags/date.py | 7 ++++--- zds/utils/tests/tests_date.py | 4 ++-- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/doc/source/front-end/template-tags.rst b/doc/source/front-end/template-tags.rst index 29ff34268e..e51fe356e5 100644 --- a/doc/source/front-end/template-tags.rst +++ b/doc/source/front-end/template-tags.rst @@ -86,23 +86,24 @@ Ce filtre formate une date au format ``DateTime`` destiné à être affiché sur Ce filtre effectue la même chose que ``format_date`` mais à destination des ``tooltip``. -``humane_time`` ---------------- +``date_from_timestamp`` +----------------------- -Formate une date au format *Nombre de seconde depuis Epoch* en un élément lisible. Ainsi : +Convertit une date au format *Nombre de seconde depuis Epoch* en un objet +accepté par les autres filtres de ce module. Ainsi : .. sourcecode:: html+django {% load date %} - {{ date_epoch|humane_time }} + {{ date_epoch|date_from_timestamp|format_date }} sera rendu : .. sourcecode:: text - jeudi 01 janvier 1970 à 00h00 + jeudi 01 janvier 1970 à 00h02 - …si le contenu de ``date_epoch`` était de ``42``. + …si le contenu de ``date_epoch`` était de ``122``. ``from_elasticsearch_date`` --------------------------- diff --git a/templates/tutorialv2/view/history.html b/templates/tutorialv2/view/history.html index c7556ea4ef..0d4ac02829 100644 --- a/templates/tutorialv2/view/history.html +++ b/templates/tutorialv2/view/history.html @@ -111,7 +111,7 @@

{% endif %} - {{ commit.authored_date|humane_time }} + {{ commit.authored_date|date_from_timestamp|format_date }} @@ -161,7 +161,7 @@

{% trans "mettre à jour" %} {% endif %} {% endcaptureas %} - {% blocktrans with action=action date_version=commit.authored_date|humane_time content_title=content.title %} + {% blocktrans with action=action date_version=commit.authored_date|date_from_timestamp|format_date content_title=content.title %} Êtes-vous certain de vouloir {{ action }} la bêta pour le contenu "{{ content_title }}" dans sa version de {{ date_version }} ? {% endblocktrans %} diff --git a/zds/utils/templatetags/date.py b/zds/utils/templatetags/date.py index f3f91e8ef1..91759df4ce 100644 --- a/zds/utils/templatetags/date.py +++ b/zds/utils/templatetags/date.py @@ -85,9 +85,10 @@ def tooltip_date(value): @register.filter -def humane_time(timestamp): - """Render time (number of second from epoch) to an human readable string""" - return format_date(datetime.fromtimestamp(timestamp)) +def date_from_timestamp(timestamp): + """Convert a timestamp (number of second from epoch) to a datetime object, + another filter should then be used to format the datetime object.""" + return datetime.fromtimestamp(timestamp) @register.filter diff --git a/zds/utils/tests/tests_date.py b/zds/utils/tests/tests_date.py index 3611395727..bd2fe7e978 100644 --- a/zds/utils/tests/tests_date.py +++ b/zds/utils/tests/tests_date.py @@ -76,8 +76,8 @@ def test_tooltip_date(self): tr = Template("{% load date %}" "{{ NoneVal | tooltip_date }}").render(self.context) self.assertEqual("None", tr) - def test_humane_time(self): + def test_date_from_timestamp(self): # Default behaviour - tr = Template("{% load date %}" "{{ date_epoch | humane_time }}").render(self.context) + tr = Template("{% load date %}" "{{ date_epoch | date_from_timestamp | format_date }}").render(self.context) self.assertEqual(tr, "jeudi 01 janvier 1970 à 01h00") From 46b253e1222f16ddbf5e3f746c39a3b6d3966578 Mon Sep 17 00:00:00 2001 From: "Ph. SW" Date: Sat, 26 Aug 2023 15:00:19 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Remplace=20des=20URLs=20hard-cod=C3=A9es=20?= =?UTF-8?q?par=20des=20appels=20=C3=A0=20reverse()=20(#6523)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zds/forum/forms.py | 17 ++++++++++++----- zds/mp/forms.py | 9 +++++++-- zds/tutorialv2/forms.py | 37 +++++++++++++++++++++++-------------- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/zds/forum/forms.py b/zds/forum/forms.py index 166eb54b16..17f3108468 100644 --- a/zds/forum/forms.py +++ b/zds/forum/forms.py @@ -27,9 +27,7 @@ class TopicForm(forms.Form, FieldValidatorMixin): label=_("Tag(s) séparés par une virgule (exemple: python,django,web)"), max_length=64, required=False, - widget=forms.TextInput( - attrs={"data-autocomplete": '{ "type": "multiple", "fieldname": "title", "url": "/api/tags/?search=%s" }'} - ), + widget=forms.TextInput(), ) text = forms.CharField( @@ -44,6 +42,15 @@ class TopicForm(forms.Form, FieldValidatorMixin): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + + self.fields["tags"].widget.attrs.update( + { + "data-autocomplete": '{ "type": "multiple", "fieldname": "title", "url": "' + + reverse("api:utils:tags-list") + + '?search=%s" }' + } + ) + self.helper = FormHelper() self.helper.form_class = "content-wrapper" self.helper.form_method = "post" @@ -53,11 +60,11 @@ def __init__(self, *args, **kwargs): Field("subtitle", autocomplete="off"), Field("tags"), HTML( - """