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

Unification des adresses de création de contenu #6324

Merged
merged 3 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ <h2 class="ico-after ico-articles home-heading" itemprop="name">
</p>
<p class="lead">{% trans "Pourquoi pas la vôtre ?" %}</p>
</div>
<a href="{% url "content:create-tutorial" %}" class="btn btn-write-tutorial">{% trans "Commencer à rédiger" %}</a>
<a href="{% url "content:create-content" created_content_type='TUTORIAL' %}" class="btn btn-write-tutorial">{% trans "Commencer à rédiger" %}</a>
</div>
</div>
</section>
Expand Down
6 changes: 4 additions & 2 deletions templates/tutorialv2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,18 @@ <h2 class="ico-after ico-tutorials">

{% block sidebar_new %}
{% if contents != None %}
<a href="{% url 'content:create-tutorial' %}" class="new-btn ico-after more blue">
<a href="{% url "content:create-content" created_content_type='TUTORIAL' %}" class="new-btn ico-after more blue">
{% trans "Nouveau contenu" %}
</a>
{% else %}
<a href="{% url 'content:create-'|add:type %}" class="new-btn ico-after more blue">
{% if tutorials != None %}
<a href="{% url "content:create-content" created_content_type='TUTORIAL' %}" class="new-btn ico-after more blue">
{% trans "Nouveau tutoriel" %}
{% elif articles != None %}
<a href="{% url "content:create-content" created_content_type='ARTICLE' %}" class="new-btn ico-after more blue">
{% trans "Nouvel article" %}
{% elif opinions != None %}
<a href="{% url "content:create-content" created_content_type='OPINION' %}" class="new-btn ico-after more blue">
{% trans "Nouveau billet" %}
{% endif %}
</a>
Expand Down
12 changes: 6 additions & 6 deletions templates/tutorialv2/index_online_contents.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,35 +72,35 @@ <h1 class="ico-after ico-{% if current_content_type == "TUTORIAL" %}tutorials{%
{% block sidebar %}
<aside class="sidebar accordeon mobile-menu-bloc" data-title="{% trans "Catégories des" %} {{ verbose_type_name_plural }}">
{% if current_content_type == "TUTORIAL" %}
<a href="{% url "content:create-tutorial" %}" class="new-btn ico-after more blue">
<a href="{% url "content:create-content" created_content_type='TUTORIAL' %}" class="new-btn ico-after more blue">
{% trans "Nouveau tutoriel" %}
</a>

<a href="{% url 'content:helps' %}?type=tuto" class="new-btn ico-after help blue">
{% trans "Aider les auteurs" %}
</a>
{% elif current_content_type == "ARTICLE" %}
<a href="{% url "content:create-article" %}" class="new-btn ico-after more blue">
<a href="{% url "content:create-content" created_content_type='ARTICLE' %}" class="new-btn ico-after more blue">
{% trans "Nouvel article" %}
</a>

<a href="{% url 'content:helps' %}?type=article" class="new-btn ico-after help blue">
{% trans "Aider les auteurs" %}
</a>
{% elif current_content_type == "OPINION" %}
<a href="{% url "content:create-opinion" %}" class="new-btn ico-after more blue">
<a href="{% url "content:create-content" created_content_type='OPINION' %}" class="new-btn ico-after more blue">
{% trans "Nouveau billet" %}
</a>
{% elif not current_content_type %}
<a href="{% url "content:create-article" %}" class="new-btn ico-after more blue">
<a href="{% url "content:create-content" created_content_type='ARTICLE' %}" class="new-btn ico-after more blue">
{% trans "Nouvel article" %}
</a>

<a href="{% url "content:create-tutorial" %}" class="new-btn ico-after more blue">
<a href="{% url "content:create-content" created_content_type='TUTORIAL' %}" class="new-btn ico-after more blue">
{% trans "Nouveau tutoriel" %}
</a>

<a href="{% url "content:create-opinion" %}" class="new-btn ico-after more blue">
<a href="{% url "content:create-content" created_content_type='OPINION' %}" class="new-btn ico-after more blue">
{% trans "Nouveau billet" %}
</a>

Expand Down
4 changes: 2 additions & 2 deletions templates/tutorialv2/list_page_elements/call_for_helps.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ <h3>{% trans 'Partagez votre savoir' %}</h3>
<p>{% trans "Vous avez un savoir à partager ? Vous vous sentez pédagogue ? Commencez donc l’écriture d’un contenu !" %}</p>
</div>

<a href="{% url "content:create-tutorial" %}" class="tail">
<a href="{% url "content:create-content" created_content_type='TUTORIAL' %}" class="tail">
<p>{% trans 'Écrire un tutoriel' %}</p>
</a>

<a href="{% url "content:create-article" %}" class="tail">
<a href="{% url "content:create-content" created_content_type='ARTICLE' %}" class="tail">
<p>{% trans 'Écrire un article' %}</p>
</a>
</div>
Expand Down
4 changes: 3 additions & 1 deletion zds/tutorialv2/tests/tests_front.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ def test_the_editor_forgets_its_content_on_form_submission(self):

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-article")
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, "input[type=checkbox][name=subcategory]"))
Expand Down
2 changes: 1 addition & 1 deletion zds/tutorialv2/tests/tests_opinion_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def test_no_help_for_tribune(self):

def test_help_for_article(self):
self.client.force_login(self.user_author)
resp = self.client.get(reverse("content:create-article"))
resp = self.client.get(reverse("content:create-content", kwargs={"created_content_type": "ARTICLE"}))
self.assertEqual(200, resp.status_code)

def test_opinion_publication_staff(self):
Expand Down
18 changes: 11 additions & 7 deletions zds/tutorialv2/tests/tests_views/tests_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def test_basic_tutorial_workflow(self):
random_with_md = "un text contenant du **markdown** ."

response = self.client.post(
reverse("content:create-tutorial"),
reverse("content:create-content", kwargs={"created_content_type": "TUTORIAL"}),
{
"text": random_with_md,
"preview": "",
Expand All @@ -259,7 +259,7 @@ def test_basic_tutorial_workflow(self):
self.assertIn("<strong>markdown</strong>", result_string, "We need the text to be properly formatted")

result = self.client.post(
reverse("content:create-tutorial"),
reverse("content:create-content", kwargs={"created_content_type": "TUTORIAL"}),
{
"title": title,
"description": description,
Expand Down Expand Up @@ -1272,7 +1272,7 @@ def test_export_content(self):

# create a tutorial
result = self.client.post(
reverse("content:create-tutorial"),
reverse("content:create-content", kwargs={"created_content_type": "TUTORIAL"}),
{
"title": given_title,
"description": some_text,
Expand Down Expand Up @@ -1432,7 +1432,7 @@ def test_import_create_content(self):

# create a tutorial
result = self.client.post(
reverse("content:create-tutorial"),
reverse("content:create-content", kwargs={"created_content_type": "TUTORIAL"}),
{
"title": given_title,
"description": some_text,
Expand Down Expand Up @@ -1548,7 +1548,7 @@ def test_import_in_existing_content(self):

# create a tutorial
result = self.client.post(
reverse("content:create-tutorial"),
reverse("content:create-content", kwargs={"created_content_type": "TUTORIAL"}),
{
"title": given_title,
"description": some_text,
Expand Down Expand Up @@ -3557,7 +3557,9 @@ def test_no_invalid_titles(self):

for title in disallowed_titles:
dic["title"] = title
result = self.client.post(reverse("content:create-tutorial"), dic, follow=False)
result = self.client.post(
reverse("content:create-content", kwargs={"created_content_type": "TUTORIAL"}), dic, follow=False
)
self.assertEqual(result.status_code, 200)
self.assertEqual(PublishableContent.objects.all().count(), 1)
self.assertFalse(result.context["form"].is_valid())
Expand All @@ -3571,7 +3573,9 @@ def test_no_invalid_titles(self):

for title in allowed_titles:
dic["title"] = title
result = self.client.post(reverse("content:create-tutorial"), dic, follow=False)
result = self.client.post(
reverse("content:create-content", kwargs={"created_content_type": "TUTORIAL"}), dic, follow=False
)
self.assertEqual(result.status_code, 302)
self.assertNotEqual(PublishableContent.objects.all().count(), prev_count)
prev_count += 1
8 changes: 8 additions & 0 deletions zds/tutorialv2/tests/tests_views/tests_edgecases.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,11 @@ def test_no_bad_slug_renaming_on_rename(self):
self.assertEqual(200, result.status_code)
result = self.client.get(article.get_absolute_url())
self.assertEqual(200, result.status_code)

def test_default_content_type_is_tutorial(self):
"""
Test that if a wrong content type is provided to the create-content view, TUTORIAL is used as a default
"""
self.client.force_login(self.author.user)
result = self.client.get(reverse("content:create-content", kwargs={"created_content_type": "WRONG_TYPE"}))
self.assertEqual("TUTORIAL", result.context_data.get("form").initial.get("type"))
4 changes: 1 addition & 3 deletions zds/tutorialv2/urls/urls_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@
# typo:
re_path(r"^reactions/typo/$", WarnTypo.as_view(), name="warn-typo"),
# create:
re_path(r"^nouveau-tutoriel/$", CreateContent.as_view(created_content_type="TUTORIAL"), name="create-tutorial"),
re_path(r"^nouvel-article/$", CreateContent.as_view(created_content_type="ARTICLE"), name="create-article"),
re_path(r"^nouveau-billet/$", CreateContent.as_view(created_content_type="OPINION"), name="create-opinion"),
path("nouveau-contenu/<str:created_content_type>/", CreateContent.as_view(), name="create-content"),
re_path(
r"^nouveau-conteneur/(?P<pk>\d+)/(?P<slug>.+)/(?P<container_slug>.+)/$",
CreateContainer.as_view(),
Expand Down
4 changes: 4 additions & 0 deletions zds/tutorialv2/views/contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from zds.utils.models import get_hat_from_settings
from zds.mp.utils import send_mp, send_message_mp
from zds.utils.uuslug_wrapper import slugify
from zds.tutorialv2.models import CONTENT_TYPE_LIST

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -73,6 +74,9 @@ class CreateContent(LoggedWithReadWriteHability, FormWithPreview):

def get_form(self, form_class=ContentForm):
form = super().get_form(form_class)
content_type = self.kwargs["created_content_type"]
if content_type in CONTENT_TYPE_LIST:
self.created_content_type = content_type
form.initial["type"] = self.created_content_type
return form

Expand Down