Skip to content

Commit

Permalink
Refactorise les URL du module 'mp'
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud-D committed Apr 10, 2022
1 parent 4064492 commit cb1c64c
Show file tree
Hide file tree
Showing 21 changed files with 201 additions and 228 deletions.
6 changes: 3 additions & 3 deletions templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
<div class="notifs-links">
{# MESSAGERIE PRIVEE #}
<div>
<a href="{% url "mp-list" %}" class="ico-link" title="{% trans 'Messagerie privée' %}">
<a href="{% url "mp:list" %}" class="ico-link" title="{% trans 'Messagerie privée' %}">
{% if header_private_topic_notifications.total > 0 %}
<span class="notif-count">{{ header_private_topic_notifications.total }}</span>
{% endif %}
Expand All @@ -229,7 +229,7 @@
<div class="header-dropdown">
<span class="dropdown-title dropdown-pm">
<h1>{% trans "Messagerie privée" %}</h1>
<a href="{% url "mp-new" %}" class="ico-after pm-new white" title="{% trans 'Envoyer un nouveau message privé' %}"></a>
<a href="{% url "mp:create" %}" class="ico-after pm-new white" title="{% trans 'Envoyer un nouveau message privé' %}"></a>
</span>

<ul class="dropdown-list">
Expand All @@ -252,7 +252,7 @@ <h1>{% trans "Messagerie privée" %}</h1>
</li>
{% endif %}
</ul>
<a href="{% url "mp-list" %}" class="dropdown-link-all">
<a href="{% url "mp:list" %}" class="dropdown-link-all">
{% trans "Toutes les conversations" %}
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/member/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ <h1>
</a>
{% endif %}
{% if usr != user and not profile.is_private and profile.can_read_now %}
<a href="{% url 'mp-new' %}?username={{ usr.username }}" class="btn-ico btn ico-after cite light">
<a href="{% url "mp:create" %}?username={{ usr.username }}" class="btn-ico btn ico-after cite light">
{% trans "Envoyer un message" %}
</a>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion templates/member/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h3>{% trans "Actions" %}</h3>
<ul>
{% if usr != user and not profile.is_private and profile.can_read_now %}
<li>
<a href="{% url 'mp-new' %}?username={{ usr.username }}" class="ico-after cite blue">
<a href="{% url "mp:create" %}?username={{ usr.username }}" class="ico-after cite blue">
{% trans "Envoyer un message privé" %}
</a>
</li>
Expand Down
4 changes: 2 additions & 2 deletions templates/mp/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@


{% block breadcrumb_base %}
<li><a href="{% url "mp-list" %}">{% trans "Messagerie privée" %}</a></li>
<li><a href="{% url "mp:list" %}">{% trans "Messagerie privée" %}</a></li>
{% endblock %}



{% block sidebar %}
<aside class="sidebar mobile-menu-hide">
<a href="{% url 'mp-new' %}" class="new-btn ico-after more blue">
<a href="{% url "mp:create" %}" class="new-btn ico-after more blue">
{% trans "Nouvelle conversation" %}
</a>
{% block sidebar_actions %}{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion templates/mp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ <h3>{% trans "Actions" %}</h3>
{% trans "Supprimer les conversations sélectionnées" %}
</a>

<form action="{% url "mp-list-delete" %}" method="post" id="delete-conversations" class="modal modal-flex">
<form action="{% url "mp:list-delete" %}" method="post" id="delete-conversations" class="modal modal-flex">
<p>
{% trans "Attention, vous vous apprêtez à supprimer toutes les conversations sélectionnées" %}.
</p>
Expand Down
2 changes: 1 addition & 1 deletion templates/mp/post/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h3>{% trans "Actions" %}</h3>
<ul>
<li>
<a href="#add-participant" class="open-modal">{% trans "Ajouter un membre" %}</a>
<form action="{% url "mp-edit-participant" topic.pk topic.slug %}" method="post" id="add-participant" class="modal modal-flex">
<form action="{% url "mp:edit-participant" topic.pk topic.slug %}" method="post" id="add-participant" class="modal modal-flex">
<p>
{% trans "Vous allez rajouter un nouveau membre dans la conversation privée" %}.
</p>
Expand Down
6 changes: 3 additions & 3 deletions templates/mp/post/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{% endif %}

{% captureas form_action %}
{% url "private-posts-new" topic.pk topic.slug %}
{% url "mp:answer" topic.pk topic.slug %}
{% endcaptureas %}

{% include "misc/message_form.html" with member=user text=form.text.value %}
Expand All @@ -55,11 +55,11 @@
<div class="content-wrapper">
{% for message in posts %}
{% captureas edit_link %}
{% url "private-posts-edit" topic.pk topic.slug message.pk %}
{% url "mp:post-edit" message.pk %}
{% endcaptureas %}

{% captureas cite_link %}
{% url "private-posts-new" topic.pk topic.slug %}?cite={{ message.pk }}
{% url "mp:answer" topic.pk topic.slug %}?cite={{ message.pk }}
{% endcaptureas %}

{% include "misc/message.part.html" with can_hide=False is_mp=True %}
Expand Down
14 changes: 7 additions & 7 deletions templates/mp/topic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@
{% for message in posts %}
{% if not topic.one_participant_remaining %}
{% captureas edit_link %}
{% url "private-posts-edit" topic.pk topic.slug message.pk %}
{% url "mp:post-edit" message.pk %}
{% endcaptureas %}

{% captureas cite_link %}
{% url "private-posts-new" topic.pk topic.slug %}?cite={{ message.pk }}
{% url "mp:answer" topic.pk topic.slug %}?cite={{ message.pk }}
{% endcaptureas %}
{% endif %}

{% captureas unread_link %}
{% url "private-post-unread" %}?message={{ message.pk }}
{% url "mp:post-unread" message.pk %}
{% endcaptureas %}

{% if forloop.first and page_obj.number > 1 %}
Expand All @@ -94,7 +94,7 @@


{% captureas form_action %}
{% url "private-posts-new" topic.pk topic.slug %}
{% url "mp:answer" topic.pk topic.slug %}
{% endcaptureas %}

{% include "misc/message_form.html" with member=user %}
Expand All @@ -111,7 +111,7 @@ <h3>{% trans "Actions" %}</h3>
<a href="#add-participant" class="open-modal ico-after more blue">
{% trans "Ajouter un membre" %}
</a>
<form action="{% url "mp-edit-participant" topic.pk topic.slug %}" method="post" id="add-participant" class="modal modal-flex">
<form action="{% url "mp:edit-participant" topic.pk topic.slug %}" method="post" id="add-participant" class="modal modal-flex">
<p>
{% trans "Vous allez rajouter un nouveau membre dans la conversation privée." %}
</p>
Expand All @@ -128,7 +128,7 @@ <h3>{% trans "Actions" %}</h3>
</li>

<li>
<a href="{% url "mp-edit-topic" topic.pk topic.slug %}" class="ico-after edit blue">
<a href="{% url "mp:edit" topic.pk topic.slug %}" class="ico-after edit blue">
{% trans "Éditer la conversation" %}
</a>
</li>
Expand All @@ -138,7 +138,7 @@ <h3>{% trans "Actions" %}</h3>
<a href="#leave-conversation" class="open-modal ico-after cross blue">
{% trans "Quitter la conversation" %}
</a>
<form action="{% url "mp-delete" topic.pk topic.slug %}" method="post" id="leave-conversation" class="modal modal-flex">
<form action="{% url "mp:leave" topic.pk topic.slug %}" method="post" id="leave-conversation" class="modal modal-flex">
<p>
{% trans "Attention, vous vous apprêtez à quitter définitivement cette conversation." %}
</p>
Expand Down
2 changes: 1 addition & 1 deletion templates/tutorialv2/view/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ <h3>{{ content.is_opinion|yesno:_("Modération,Validation") }}</h3>
</li>
{% endif %}
<li>
<a href="{% url 'mp-new' %}?{% for username in content.authors.all %}&amp;username={{ username }}{% endfor %}"
<a href="{% url "mp:create" %}?{% for username in content.authors.all %}&amp;username={{ username }}{% endfor %}"
class="ico-after cite blue"
>
{% trans "Envoyer un MP" %}
Expand Down
45 changes: 0 additions & 45 deletions zds/mp/commons.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from datetime import datetime

from django.views.generic.detail import SingleObjectMixin
from django.http import Http404
from django.shortcuts import get_object_or_404

from zds.mp.models import PrivateTopicRead, PrivatePost
from zds.utils.templatetags.emarkdown import emarkdown
from zds.mp import signals


class LeavePrivateTopic:
Expand Down Expand Up @@ -37,42 +31,3 @@ def perform_update(self, instance, data, hat=None):
instance.update = datetime.now()
instance.save()
return instance

@staticmethod
def perform_unread_private_post(post, user):
"""
Mark the private post as unread. If it is in first position, the whole topic is marked as unread.
"""
# mark the previous post as read
try:
previous_post = PrivatePost.objects.get(
privatetopic=post.privatetopic, position_in_topic=post.position_in_topic - 1
)
# update the record, if it exists
try:
topic = PrivateTopicRead.objects.get(privatetopic=post.privatetopic, user=user)
topic.privatepost = previous_post
# no existing record to update, create a new record
except PrivateTopicRead.DoesNotExist:
topic = PrivateTopicRead(privatepost=previous_post, privatetopic=post.privatetopic, user=user)
topic.save()
# no previous post to mark as read, remove the topic from read list instead
except PrivatePost.DoesNotExist:
try:
topic = PrivateTopicRead.objects.get(privatetopic=post.privatetopic, user=user)
topic.delete()
except PrivateTopicRead.DoesNotExist: # record already removed, nothing to do
pass

signals.message_unread.send(sender=post.privatetopic.__class__, instance=post, user=user)


class SinglePrivatePostObjectMixin(SingleObjectMixin):
object = None

def get_object(self, queryset=None):
try:
post_pk = int(self.request.GET.get("message"))
except (KeyError, ValueError, TypeError):
raise Http404
return get_object_or_404(PrivatePost, pk=post_pk)
2 changes: 1 addition & 1 deletion zds/mp/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class PrivatePostForm(forms.Form):
def __init__(self, topic, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_action = reverse("private-posts-new", args=[topic.pk, topic.slug()])
self.helper.form_action = reverse("mp:answer", args=[topic.pk, topic.slug()])
self.helper.form_method = "post"

self.helper.layout = Layout(
Expand Down
2 changes: 1 addition & 1 deletion zds/mp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def get_absolute_url(self):
:return: PrivateTopic object URL
:rtype: str
"""
return reverse("private-posts-list", args=[self.pk, self.slug()])
return reverse("mp:view", args=[self.pk, self.slug()])

def slug(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion zds/mp/tests/tests_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def setUp(self):
self.post2 = PrivatePostFactory(privatetopic=self.topic1, author=self.user2, position_in_topic=2)

def test_get_absolute_url(self):
url = reverse("private-posts-list", args=[self.topic1.pk, self.topic1.slug()])
url = reverse("mp:view", args=[self.topic1.pk, self.topic1.slug()])

self.assertEqual(self.topic1.get_absolute_url(), url)

Expand Down
6 changes: 3 additions & 3 deletions zds/mp/tests/tests_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def setUp(self):

def test_new_mp_email(self):
response = self.client.post(
reverse("mp-new"),
reverse("mp:create"),
{
"participants": self.user2.username
+ ", "
Expand Down Expand Up @@ -78,7 +78,7 @@ def test_answer_mp_email(self):

# Create a MP
self.client.post(
reverse("mp-new"),
reverse("mp:create"),
{
"participants": self.user2.username
+ ", "
Expand All @@ -101,7 +101,7 @@ def test_answer_mp_email(self):
# Add an answer
topic1 = PrivateTopic.objects.get()
self.client.post(
reverse("private-posts-new", args=[topic1.pk, topic1.slug]),
reverse("mp:answer", args=[topic1.pk, topic1.slug()]),
{"text": "answer", "last_post": topic1.last_message.pk},
follow=True,
)
Expand Down
Loading

0 comments on commit cb1c64c

Please sign in to comment.