Skip to content

Commit

Permalink
Supprime les demandes de mise en avant lors de la dépublication des c…
Browse files Browse the repository at this point in the history
…ontenus
  • Loading branch information
Situphen committed Jul 20, 2024
1 parent 745ae7e commit 7ff0b7f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion zds/featured/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

from zds.featured.models import FeaturedRequested
from zds.forum.models import Topic
from zds.tutorialv2.models.database import PublishableContent
from zds.tutorialv2.models.database import PublishableContent, PublishedContent


@receiver(pre_delete, sender=PublishableContent)
@receiver(pre_delete, sender=PublishedContent)
@receiver(pre_delete, sender=Topic)
def remove_requested_featured_at_content_object_deletion(sender, instance, **kwargs):
if isinstance(instance, PublishedContent):
sender = PublishableContent
instance = instance.content
try:
FeaturedRequested.objects.get(
content_type=ContentType.objects.get_for_model(sender), object_id=instance.pk
Expand Down
9 changes: 7 additions & 2 deletions zds/featured/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from zds.featured.models import FeaturedResource, FeaturedMessage, FeaturedRequested
from zds.forum.tests.factories import ForumCategoryFactory, ForumFactory, TopicFactory
from zds.gallery.tests.factories import GalleryFactory, ImageFactory
from zds.tutorialv2.publication_utils import unpublish_content
from zds.tutorialv2.tests.factories import PublishedContentFactory
from zds.tutorialv2.tests import TutorialTestMixin, override_for_contents

Expand Down Expand Up @@ -488,10 +489,14 @@ def test_success_list_with_deleted_content(self):
# request for the topic and the content to be featured
FeaturedRequested.objects.toogle_request(topic, author)
FeaturedRequested.objects.toogle_request(tutorial, author)
count = FeaturedRequested.objects.count()

# delete both this topic and this content
# delete the topic and unpublish the content
topic.delete()
tutorial.delete()
unpublish_content(tutorial)

# check that the FeaturedRequested objects have been deleted
self.assertEqual(FeaturedRequested.objects.count(), count - 2)

# check that the page listing the requests still works
staff = StaffProfileFactory()
Expand Down

0 comments on commit 7ff0b7f

Please sign in to comment.