Skip to content

Commit

Permalink
Ajoute des événements pour la gestion des billets
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud-D committed May 15, 2021
1 parent d2ce8df commit cc6110e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
33 changes: 31 additions & 2 deletions zds/tutorialv2/models/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@


# Map signals to event types
from zds.tutorialv2.views.validations_opinions import PublishOpinion, UnpublishOpinion

types = {
# Author management
signals.author_added: "author_added",
Expand Down Expand Up @@ -65,6 +67,9 @@
signals.help_modified: "help_modified",
# JSFiddle management
signals.jsfiddle_modified: "jsfiddle_modified",
# Opinion publication management
signals.opinion_published: "opinion_published",
signals.opinion_unpublished: "opinion_unpublished",
}


Expand Down Expand Up @@ -227,6 +232,18 @@ def describe_jsfiddle_modified(event):
)


def describe_opinion_published(event):
return _('<a href="{}">{}</a> a publié le billet.').format(
reverse("member-detail", args=[event.performer.username]), event.performer
)


def describe_opinion_unpublished(event):
return _('<a href="{}">{}</a> a dépublié le billet.').format(
reverse("member-detail", args=[event.performer.username]), event.performer
)


# Map event types to descriptors
descriptors = {
"author_added": describe_author_added,
Expand All @@ -247,6 +264,8 @@ def describe_jsfiddle_modified(event):
"suggestion_removed": describe_suggestion_removed,
"help_modified": describe_help_modified,
"jsfiddle_modified": describe_jsfiddle_modified,
"opinion_published": describe_opinion_published,
"opinion_unpublished": describe_opinion_unpublished,
}


Expand Down Expand Up @@ -322,7 +341,7 @@ def record_event_suggestion_management(sender, performer, signal, content, **_):


@receiver(signals.help_modified, sender=ChangeHelp)
def record_help_management(sender, performer, signal, content, **_):
def record_event_help_management(sender, performer, signal, content, **_):
Event(
performer=performer,
type=types[signal],
Expand All @@ -331,7 +350,17 @@ def record_help_management(sender, performer, signal, content, **_):


@receiver(signals.jsfiddle_modified, sender=ActivateJSFiddleInContent)
def record_jsfiddle_management(sender, performer, signal, content, **_):
def record_event_jsfiddle_management(sender, performer, signal, content, **_):
Event(
performer=performer,
type=types[signal],
content=content,
).save()


@receiver(signals.opinion_published, sender=PublishOpinion)
@receiver(signals.opinion_unpublished, sender=UnpublishOpinion)
def record_event_opinion_publication_management(sender, performer, signal, content, **_):
Event(
performer=performer,
type=types[signal],
Expand Down
5 changes: 5 additions & 0 deletions zds/tutorialv2/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@
# JSFiddle management
# For the signal below, the arguments "performer" and "content" shall be provided.
jsfiddle_modified = Signal()

# Opinion publication management
# For the signals below, the arguments "performer" and "content" shall be provided.
opinion_published = Signal()
opinion_unpublished = Signal()
4 changes: 4 additions & 0 deletions zds/tutorialv2/views/validations_opinions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from zds.gallery.models import Gallery
from zds.member.decorator import LoggedWithReadWriteHability, LoginRequiredMixin, PermissionRequiredMixin
from zds.tutorialv2 import signals
from zds.tutorialv2.forms import (
PublicationForm,
RevokeValidationForm,
Expand Down Expand Up @@ -75,6 +76,7 @@ def form_valid(self, form):
)
notify_update(db_object, is_update, form.cleaned_data.get("is_major", False))

signals.opinion_published.send(sender=self.__class__, performer=self.request.user, content=self.object)
messages.success(self.request, _("Le contenu a bien été publié."))
self.success_url = published.get_absolute_url_online()

Expand Down Expand Up @@ -142,6 +144,8 @@ def form_valid(self, form):
no_notification_for=[self.request.user],
)

signals.opinion_unpublished.send(sender=self.__class__, performer=self.request.user, content=self.object)

messages.success(self.request, _("Le contenu a bien été dépublié."))
self.success_url = self.versioned_object.get_absolute_url()

Expand Down

0 comments on commit cc6110e

Please sign in to comment.