Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajoute des formulaires dédiés à l'introduction et la conclusion #6642

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f01ebe5
Simplifie la création de publication
Arnaud-D Sep 11, 2024
41119e1
Supprime le formulaire "Éditer"
Arnaud-D Sep 11, 2024
cc527bb
Suppprime un import inutile
Arnaud-D Sep 11, 2024
b9951f0
Ajoute le formulaire introduction
Arnaud-D Sep 11, 2024
a8e00cb
Ajoute le formulaire de conclusion
Arnaud-D Sep 15, 2024
0d33fce
Ajoute des tests pour les vues intro et conclusion
Arnaud-D Sep 15, 2024
5a5a603
Corrige 'tests_display.py'
Arnaud-D Sep 15, 2024
f51f4c2
Corrige 'test_validation_subscription()'
Arnaud-D Sep 15, 2024
625b4a0
Corrige 'test_ask_validation_update()'
Arnaud-D Sep 15, 2024
1c72abe
Corrige 'test_unpublish_with_title_change()'
Arnaud-D Sep 15, 2024
bb618eb
Corrige 'test_validation_history()'
Arnaud-D Sep 15, 2024
08a2b38
Corrige 'test_validation_list_has_good_title()'
Arnaud-D Sep 15, 2024
4edf01d
Corrige 'test_export_content()'
Arnaud-D Sep 15, 2024
2f7bcf4
Corrige 'test_import_create_content()'
Arnaud-D Sep 15, 2024
cf6d47a
Corrige 'test_import_in_existing_content()'
Arnaud-D Sep 15, 2024
b04156b
Corrige 'test_basic_tutorial_workflow()'
Arnaud-D Sep 17, 2024
e66e741
Corrige 'test_collaborative_article_edition_and_editor_persistence()'
Arnaud-D Sep 17, 2024
45be765
Remove 'test_the_editor_forgets_its_content_on_form_submission()'
Arnaud-D Sep 18, 2024
a874d97
Corrige 'test_publication_and_attributes_consistency()'
Arnaud-D Sep 18, 2024
edfb494
Corrige 'test_list_categories()'
Arnaud-D Sep 18, 2024
9900318
Ajoute le message de commit aux formulaires
Arnaud-D Sep 23, 2024
d0a824d
Ajoute la suggestion de barre horizontale
Arnaud-D Sep 23, 2024
e3b83bd
Supprime un import inutile
Arnaud-D Sep 24, 2024
f555774
Merge branch 'dev' into formulaires-intro-et-conclusion
philippemilink Sep 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions templates/tutorialv2/edit/conclusion.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends "tutorialv2/base.html" %}
{% load crispy_forms_tags %}
{% load i18n %}

{% block title %}
{% trans "Modifier la conclusion de " %}{{ content.title }}
{% endblock %}

{% block breadcrumb %}
<li><a href="{{ content.get_absolute_url }}">{{ content.title }}</a></li>
<li>{% trans "Modifier la conclusion" %}</li>
{% endblock %}

{% block headline %}
<h1 {% if content.image %}class="illu"{% endif %}>
{% if content.image %}
<img src="{{content.image.physical.tutorial_illu.url }}" alt="">
{% endif %}
{% blocktrans with title=content.title %}Modifier la conclusion de « {{ title }} »{% endblocktrans %}
</h1>
{% endblock %}


{% block content %}
{% crispy form %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,23 @@
{% load feminize %}

{% block title %}
{% trans "Éditer " %}{{ content.textual_type }}
{% trans "Modifier l'introduction de " %}{{ content.title }}
{% endblock %}

{% block breadcrumb %}
<li><a href="{{ content.get_absolute_url }}">{{ content.title }}</a></li>
<li>{% trans "Éditer " %}{{ content.textual_type|lower }}</li>
<li>{% trans "Modifier l'introduction" %}</li>
{% endblock %}

{% block headline %}
<h1 {% if content.image %}class="illu"{% endif %}>
{% if content.image %}
<img src="{{content.image.physical.tutorial_illu.url }}" alt="">
{% endif %}
{% trans "Éditer" %} : {{ content.title }}
{% blocktrans with title=content.title %}Modifier l'introduction de « {{ title }} »{% endblocktrans %}
</h1>
{% endblock %}

{% block headline_sub %}
{{ content.description }}
{% endblock %}


{% block content %}
{% if new_version %}
Expand Down
10 changes: 6 additions & 4 deletions templates/tutorialv2/includes/content/content.part.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% if content.get_introduction %}
{% if display_config.draft_actions.enable_edit %}
<div class="simple-edit-button">
<a class="ico-after edit btn btn-grey" href="{% url "content:edit" content.pk content.slug %}#div_id_introduction">
<a class="ico-after edit btn btn-grey" href="{% url "content:edit-introduction" content.pk %}">
{% trans "Modifier l'introduction" %}
</a>
</div>
Expand All @@ -15,10 +15,12 @@
<p>
{% trans "Il n’y a pas d’introduction." %}
{% if display_config.draft_actions.enable_edit %}
{% trans "Vous pouvez " %}<a href="{% url "content:edit" content.pk content.slug %}">{% trans "en ajouter une" %}</a>.
{% trans "Vous pouvez " %}<a href="{% url "content:edit-introduction" content.pk %}">{% trans "en ajouter une" %}</a>.
{% endif %}
</p>
</div>
philippemilink marked this conversation as resolved.
Show resolved Hide resolved

<hr>
{% endif %}

{% if content.has_extracts or content.can_add_extract %}
Expand Down Expand Up @@ -108,7 +110,7 @@ <h2>
{% if content.get_conclusion %}
{% if display_config.draft_actions.enable_edit %}
<div class="simple-edit-button">
<a class="ico-after edit btn btn-grey" href="{% url "content:edit" content.pk content.slug %}#div_id_conclusion">
<a class="ico-after edit btn btn-grey" href="{% url "content:edit-conclusion" content.pk %}">
{% trans "Modifier la conclusion" %}
</a>
</div>
Expand All @@ -119,7 +121,7 @@ <h2>
<p>
{% trans "Il n’y a pas de conclusion." %}
{% if display_config.draft_actions.enable_edit %}
{% trans "Vous pouvez " %}<a href="{% url "content:edit" content.pk content.slug %}">{% trans "en ajouter une" %}</a>.
{% trans "Vous pouvez " %}<a href="{% url "content:edit-conclusion" content.pk %}">{% trans "en ajouter une" %}</a>.
{% endif %}
</p>
</div>
Expand Down
7 changes: 0 additions & 7 deletions templates/tutorialv2/view/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,6 @@
{% endfor %}
{% endif %}

{% if display_config.draft_actions.show_license_edit %}
<li>
{% url "content:edit" content.pk content.slug as edit_url %}
<a href="{{ edit_url }}" class="ico-after edit blue">{% trans "Éditer" %}</a>
</li>
{% endif %}

{% if display_config.draft_actions.show_import_link %}
<li>
{% url "content:import" content.pk content.slug as import_url %}
Expand Down
50 changes: 3 additions & 47 deletions zds/tutorialv2/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from zds.tutorialv2.models.database import PublishableContent
from django.utils.translation import gettext_lazy as _
from zds.utils.forms import IncludeEasyMDE
from zds.utils.validators import with_svg_validator, slugify_raise_on_invalid, InvalidSlugError
from zds.utils.validators import slugify_raise_on_invalid, InvalidSlugError


class FormWithTitle(forms.Form):
Expand Down Expand Up @@ -108,32 +108,14 @@ def __init__(self, *args, **kwargs):


class ContentForm(ContainerForm):
type = forms.ChoiceField(choices=TYPE_CHOICES, required=False)
type = forms.ChoiceField(choices=TYPE_CHOICES, required=True)

def _create_layout(self):
self.helper.layout = Layout(
IncludeEasyMDE(),
Field("title"),
Field("type"),
Field("introduction", css_class="md-editor preview-source"),
ButtonHolder(
StrictButton(_("Aperçu"), type="preview", name="preview", css_class="btn btn-grey preview-btn"),
),
HTML(
'{% if form.introduction.value %}{% include "misc/preview.part.html" \
with text=form.introduction.value %}{% endif %}'
),
Field("conclusion", css_class="md-editor preview-source"),
ButtonHolder(
StrictButton(_("Aperçu"), type="preview", name="preview", css_class="btn btn-grey preview-btn"),
),
HTML(
'{% if form.conclusion.value %}{% include "misc/preview.part.html" \
with text=form.conclusion.value %}{% endif %}'
),
Field("last_hash"),
Field("msg_commit"),
ButtonHolder(StrictButton("Valider", type="submit")),
StrictButton("Valider", type="submit"),
)

def __init__(self, *args, **kwargs):
Expand All @@ -148,32 +130,6 @@ def __init__(self, *args, **kwargs):
self.helper["type"].wrap(Field, disabled=True)


class EditContentForm(ContentForm):
title = None
description = None
type = None

def _create_layout(self):
self.helper.layout = Layout(
IncludeEasyMDE(),
Field("introduction", css_class="md-editor preview-source"),
StrictButton(_("Aperçu"), type="preview", name="preview", css_class="btn btn-grey preview-btn"),
HTML(
'{% if form.introduction.value %}{% include "misc/preview.part.html" \
with text=form.introduction.value %}{% endif %}'
),
Field("conclusion", css_class="md-editor preview-source"),
StrictButton(_("Aperçu"), type="preview", name="preview", css_class="btn btn-grey preview-btn"),
HTML(
'{% if form.conclusion.value %}{% include "misc/preview.part.html" \
with text=form.conclusion.value %}{% endif %}'
),
Field("last_hash"),
Field("msg_commit"),
ButtonHolder(StrictButton("Valider", type="submit")),
)


class ExtractForm(FormWithTitle):
text = forms.CharField(
label=_("Texte"),
Expand Down
2 changes: 1 addition & 1 deletion zds/tutorialv2/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def form_invalid(self, form):

class FormWithPreview(FormView):
def post(self, request, *args, **kwargs):
form = self.form_class(request.POST)
form = self.get_form()

if "preview" in request.POST:
self.form_invalid(form)
Expand Down
32 changes: 20 additions & 12 deletions zds/tutorialv2/tests/models/tests_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,26 +449,34 @@ def test_publication_and_attributes_consistency(self):
old_description = article.public_version.description()
article.licence = LicenceFactory()
article.save()

self.client.force_login(self.user_author)
self.client.post(
reverse("content:edit", args=[article.pk, article.slug]),
{
"title": old_title + "bla",
"description": old_description + "bla",
"type": "ARTICLE",
"licence": article.licence.pk,
"subcategory": SubCategoryFactory().pk,
"last_hash": article.sha_draft,
},

new_title = old_title + "bla"
result = self.client.post(
reverse("content:edit-title", args=[article.pk]),
{"title": new_title},
follow=True,
)
self.assertEqual(result.status_code, 200)

new_description = old_description + "bla"
result = self.client.post(
reverse("content:edit-subtitle", args=[article.pk]),
{"subtitle": new_description},
follow=True,
)
self.assertEqual(result.status_code, 200)

article = PublishableContent.objects.prefetch_related("public_version").get(pk=article.pk)
article.public_version.load_public_version()
self.assertEqual(old_title, article.public_version.title())
self.assertEqual(old_description, article.public_version.description())
self.assertEqual(old_date, article.public_version.publication_date)

publish_content(article, article.load_version(), False)
article = PublishableContent.objects.get(pk=article.pk)
article.public_version.load_public_version()

article = PublishableContent.objects.prefetch_related("public_version").get(pk=article.pk)
self.assertEqual(old_date, article.public_version.publication_date)
self.assertNotEqual(old_date, article.public_version.update_date)

Expand Down
39 changes: 5 additions & 34 deletions zds/tutorialv2/tests/tests_front.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_collaborative_article_edition_and_editor_persistence(self):
article.sha_draft = versioned_article.repo_update("article", "", "", update_slug=False)
article.save()

article_edit_url = reverse("content:edit", args=[article.pk, article.slug])
article_edit_url = reverse("content:edit-introduction", args=[article.pk])

self.login(author)
selenium.execute_script('localStorage.setItem("editor_choice", "new")') # we want the new editor
Expand All @@ -130,7 +130,7 @@ def test_collaborative_article_edition_and_editor_persistence(self):
intro = self.find_element("div#div_id_introduction div.CodeMirror")
# ActionChains: Support for CodeMirror https://stackoverflow.com/a/48969245/2226755
action_chains = ActionChains(selenium)
scrollDriverTo(selenium, 0, 312)
scroll_driver_to(selenium, 0, 312)
action_chains.click(intro).perform()
action_chains.send_keys("intro").perform()

Expand All @@ -144,36 +144,7 @@ def test_collaborative_article_edition_and_editor_persistence(self):

self.assertEqual("new intro", self.find_element(".md-editor#id_introduction").get_attribute("value"))

def test_the_editor_forgets_its_content_on_form_submission(self):
selenium = self.selenium

author = ProfileFactory()

self.login(author)
selenium.execute_script('localStorage.setItem("editor_choice", "new")') # we want the new editor
new_article_url = self.live_server_url + reverse(
"content:create-content", kwargs={"created_content_type": "ARTICLE"}
)
selenium.get(new_article_url)
WebDriverWait(self.selenium, 10).until(ec.element_to_be_clickable((By.CSS_SELECTOR, "#id_title"))).click()

self.find_element("#id_title").send_keys("Oulipo")

intro = self.find_element("div#div_id_introduction div.CodeMirror")
action_chains = ActionChains(selenium)
scrollDriverTo(selenium, 0, 312)
action_chains.click(intro).perform()
action_chains.send_keys("Le cadavre exquis boira le vin nouveau.").perform()

self.find_element(".content-container button[type=submit]").click()

self.assertTrue(WebDriverWait(selenium, 10).until(ec.title_contains("Oulipo")))

selenium.get(new_article_url)

self.assertEqual("", self.find_element(".md-editor#id_introduction").get_attribute("value"))


def scrollDriverTo(driver, x, y):
scriptScrollTo = f"window.scrollTo({x}, {y});"
driver.execute_script(scriptScrollTo)
def scroll_driver_to(driver, x, y):
script_scroll_to = f"window.scrollTo({x}, {y});"
driver.execute_script(script_scroll_to)
2 changes: 1 addition & 1 deletion zds/tutorialv2/tests/tests_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_list_categories(self):

context_categories = list(resp.context_data["categories"])
self.assertEqual(context_categories[0].contents_count, 10)
self.assertEqual(context_categories[0].subcategories, [subcategory_1, subcategory_2])
self.assertCountEqual(context_categories[0].subcategories, [subcategory_1, subcategory_2])
self.assertIn(category_1, context_categories)

def test_private_lists(self):
Expand Down
Loading