def set_story_slug_on_publish(sender, instance, **kwargs): """Update a story's slug when it is published""" if instance.pk and instance.status == 'published' and instance.published is None: # Only update the slug for stories that are: # * Being published # * Have not been previously published # * Has been previously saved unique_slugify(instance, instance.title)
def set_activity_slug(sender, instance, **kwargs): try: if not instance.activity.slug: unique_slugify(instance.activity, instance.title) instance.activity.save() except Activity.DoesNotExist: # Instance doesn't have a related Activity. # Encountered this when loading fixture pass
def set_newsitem_slug(sender, instance, **kwargs): try: if not instance.news_item.slug: unique_slugify(instance.news_item, instance.title) instance.news_item.save() except NewsItem.DoesNotExist: # Instance doesn't have a related News Item. # Encountered this when loading fixture pass
def set_place_slug(sender, instance, **kwargs): """ When a Place is saved, set its Story's slug if it doesn't have one Should be connected to Place's pre_save signal. """ if not instance.slug: unique_slugify(instance, instance.name)
def forwards(self, orm): # If the layout has no slug value set or it's non-unqiue, create # a unique slug value qs = orm['storybase_story.SectionLayout'].objects.all() for layout in qs: trans = orm['storybase_story.SectionLayoutTranslation'].objects.get(layout=layout, language=settings.LANGUAGE_CODE) if not self._has_unique_slug(layout, qs): unique_slugify(layout, trans.name, queryset=orm['storybase_story.SectionLayout'].objects.all()) layout.save()
def set_project_slug(sender, instance, **kwargs): """ When an ProjectTranslation is saved, set its Project's slug if it doesn't have one Should be connected to ProjectTranslation's post_save signal. """ if not instance.project.slug: unique_slugify(instance.project, instance.name) instance.project.save()
def set_organization_slug(sender, instance, **kwargs): """ When an OrganizationTranslation is saved, set its Organization's slug if it doesn't have one Should be connected to OrganizationTranslation's post_save signal. """ if not instance.organization.slug: unique_slugify(instance.organization, instance.name) instance.organization.save()
def set_story_slug(sender, instance, **kwargs): """ When a StoryTranslation is saved, set its Story's slug if it doesn't have one Should be connected to StoryTranslation's post_save signal. """ try: if not instance.story.slug: unique_slugify(instance.story, instance.title) instance.story.save() except Story.DoesNotExist: # Instance doesn't have a related story. # Encountered this when loading fixture pass
def forwards(self, orm): # Populate the slug fields for place in orm.Place.objects.all(): unique_slugify(place, place.name) place.save()