def test_auto_slug(self): name = 'The Metro Denver Regional Equity Atlas' project = Project() project.save() project_translation = ProjectTranslation(name=name, project=project) project_translation.save() self.assertEqual(project.slug, slugify(name))
def test_auto_slug(self): name = 'Mile High Connects' organization = Organization() organization.save() organization_translation = OrganizationTranslation(name=name, organization=organization) organization_translation.save() self.assertEqual(organization.slug, slugify(name))
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: instance.organization.slug = slugify(instance.name) instance.organization.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: instance.project.slug = slugify(instance.name) instance.project.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: instance.story.slug = slugify(instance.title) instance.story.save() except Story.DoesNotExist: # Instance doesn't have a related story. # Encountered this when loading fixture pass
def save(self, *args, **kwargs): if not self.slug: self.slug = slugify(SLUG_TRANSLITERATOR(self.name))[:50] super(CategoryTranslationBase, self).save(*args, **kwargs)
def clean_slug(self): if self.instance is None or not ALLOW_SLUG_CHANGE: self.cleaned_data['slug'] = slugify(self.cleaned_data['name']) return self.cleaned_data['slug'][:50]