def save(self, *args, **kwargs): # It is vital to track the changes of the parent associated with a forum in order to # maintain counters up-to-date and to trigger other operations such as permissions updates. old_instance = None if self.pk: old_instance = self.__class__._default_manager.get(pk=self.pk) # Update the slug field self.slug = slugify(force_text('{}-{}'.format(self.name, self.condominium.id)), allow_unicode=True) # Do the save super(AbstractForum, self).save(*args, **kwargs) # If any change has been made to the forum parent, trigger the update of the counters if old_instance and old_instance.parent != self.parent: self.update_trackers() # The previous parent trackers should also be updated if old_instance.parent: old_parent = old_instance.parent old_parent.refresh_from_db() old_parent.update_trackers() # Trigger the 'forum_moved' signal signals.forum_moved.send(sender=self, previous_parent=old_instance.parent)
class ForumFactory(factory.DjangoModelFactory): name = faker.text(max_nb_chars=150) slug = factory.LazyAttribute(lambda t: slugify(t.name)) # Link forum specific link = faker.uri() class Meta: model = Forum
class TopicFactory(factory.DjangoModelFactory): forum = factory.SubFactory(ForumFactory) poster = factory.SubFactory(UserFactory) status = Topic.STATUS_CHOICES.topic_unlocked subject = factory.LazyAttribute(lambda t: faker.text(max_nb_chars=200)) slug = factory.LazyAttribute(lambda t: slugify(t.subject)) class Meta: model = Topic
def save(self, *args, **kwargs): # It is vital to track the changes of the forum associated with a topic in order to # maintain counters up-to-date. old_instance = None if self.pk: old_instance = self.__class__._default_manager.get(pk=self.pk) # Update the slug field self.slug = slugify(force_text(self.subject)) # Do the save super(AbstractTopic, self).save(*args, **kwargs) # If any change has been made to the parent forum, trigger the update of the counters if old_instance and old_instance.forum != self.forum: self.update_trackers() # The previous parent forum counters should also be updated if old_instance.forum: old_forum = refresh(old_instance.forum) old_forum.update_trackers()
def save(self, *args, **kwargs): # It is vital to track the changes of the parent associated with a forum in order to # maintain counters up-to-date and to trigger other operations such as permissions updates. old_instance = None if self.pk: old_instance = self.__class__._default_manager.get(pk=self.pk) # Update the slug field self.slug = slugify(force_text(self.name)) # Do the save super(AbstractForum, self).save(*args, **kwargs) # If any change has been made to the forum parent, trigger the update of the counters if old_instance and old_instance.parent != self.parent: self.update_trackers() # The previous parent trackers should also be updated if old_instance.parent: old_parent = refresh(old_instance.parent) old_parent.update_trackers() # Trigger the 'forum_moved' signal signals.forum_moved.send(sender=self, previous_parent=old_instance.parent)