def get_by_slug(cls, slug=None, name=None): """ Return a post by slug """ if name and not slug: slug = utils.slugify(name) return cls.all().filter(cls.slug == slug).first()
def prepare_author(cls, author): """ Prepare the author data """ name = utils.slugify(author.name or "no-name") #url = url_for("%s:post_author" % view_name, id=author.id, name=name, _external=True) #author.url = url return author
def create_slug(cls, title): slug = None slug_counter = 0 _slug = utils.slugify(title).lower() while True: slug = _slug if slug_counter > 0: slug += str(slug_counter) slug_counter += 1 if not cls.get_by_slug(slug): break return slug
def rename(self, name, slug=None): slug = utils.slugify(name if not slug else slug) return self.update(name=name, slug=slug)
def new(cls, name, slug=None): slug = utils.slugify(name if not slug else slug) return cls.create(name=name, slug=slug)
def set_slug(self, title): slug = utils.slugify(title) if title and slug != self.slug: slug = self.create_slug(slug) self.update(slug=slug)
def get_by_name(cls, name): name = utils.slugify(name) return cls.all().filter(cls.name == name).first()
def new(cls, name, level): name = utils.slugify(name) role = cls.get_by_name(name) if not role: role = cls.create(name=name, level=level) return role