Esempio n. 1
0
 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()
Esempio n. 2
0
 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
Esempio n. 3
0
 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
Esempio n. 4
0
 def rename(self, name, slug=None):
     slug = utils.slugify(name if not slug else slug)
     return self.update(name=name, slug=slug)
Esempio n. 5
0
 def new(cls, name, slug=None):
     slug = utils.slugify(name if not slug else slug)
     return cls.create(name=name, slug=slug)
Esempio n. 6
0
 def set_slug(self, title):
     slug = utils.slugify(title)
     if title and slug != self.slug:
         slug = self.create_slug(slug)
         self.update(slug=slug)
Esempio n. 7
0
 def get_by_name(cls, name):
     name = utils.slugify(name)
     return cls.all().filter(cls.name == name).first()
Esempio n. 8
0
 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
Esempio n. 9
0
 def get_by_name(cls, name):
     name = utils.slugify(name)
     return cls.all().filter(cls.name == name).first()
Esempio n. 10
0
 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