def save(self, *args, **kwargs): # -------------------------------------------------------------------- # Update the audit timestamps. # -------------------------------------------------------------------- if not self.id: self.created = timezone.now() self.updated = timezone.now() # -------------------------------------------------------------------- # -------------------------------------------------------------------- # Always update the slug and version UUID. # -------------------------------------------------------------------- unique_slugify(instance = self, value = self.title, slug_field_name = 'slug') self.version = uuid.uuid4().hex # -------------------------------------------------------------------- # -------------------------------------------------------------------- # The description gets rendered into description_rendered, and # assumes it is formatted as Markdown. # -------------------------------------------------------------------- markdowner = markdown2.Markdown(extras = ["cuddled-lists", "smarty-pants"]) self.description_rendered = markdowner.convert(self.description) # -------------------------------------------------------------------- super(Guide, self).save(*args, **kwargs)
def get_slug_from_title(self, title): """Used for tests and views. Turn a title into a slug. We prefer to call unique_slugify below in the save() handler. !!AI this is too hacky, revise the unique_slugify() function.""" any_account = User.objects.all()[0].get_profile() temporary_guide = Guide(title = title, location = "this is a location", description = "this is a description", owner = any_account) unique_slugify(instance = temporary_guide, value = title, slug_field_name = 'slug') slug = temporary_guide.slug return slug