Ejemplo n.º 1
0
Archivo: blog.py Proyecto: ajaxj/fkmv
 def validate_slug(self, field):
     if len(field.data) > 50:
         raise ValidationError, gettext("Slug must be less than 50 characters")
     slug = slugify(field.data) if field.data else slugify(self.title.data)[:50]
     posts = Post.query.filter_by(slug=slug)
     if self.post:
         posts = posts.filter(db.not_(Post.id==self.post.id))
     if posts.count():
         error = gettext("This slug is taken") if field.data else gettext("Slug is required")
         raise ValidationError, error
Ejemplo n.º 2
0
 def validate_slug(self, field):
     if len(field.data) > 50:
         raise ValidationError, gettext(
             "Slug must be less than 50 characters")
     slug = slugify(field.data) if field.data else slugify(
         self.title.data)[:50]
     posts = Post.query.filter_by(slug=slug)
     if self.post:
         posts = posts.filter(db.not_(Post.id == self.post.id))
     if posts.count():
         error = gettext("This slug is taken") if field.data else gettext(
             "Slug is required")
         raise ValidationError, error
Ejemplo n.º 3
0
 def linked_taglist(self):
     """
     Returns the tags in the original order and format, 
     with link to tag page
     """
     return [(tag, url_for('frontend.tag',
                           slug=slugify(tag))) \
             for tag in self.taglist]
Ejemplo n.º 4
0
 def linked_taglist(self):
     """
     Returns the tags in the original order and format,
     with link to tag page
     """
     return [(tag, url_for('frontend.tag',
                           slug=slugify(tag))) \
             for tag in self.taglist]
Ejemplo n.º 5
0
    def _set_tags(self, tags):

        self._tags = tags

        if self.id:
            # ensure existing tag references are removed
            d = db.delete(post_tags, post_tags.c.post_id==self.id)
            db.engine.execute(d)

        for tag in set(self.taglist):

            slug = slugify(tag)

            tag_obj = Tag.query.filter(Tag.slug==slug).first()
            if tag_obj is None:
                tag_obj = Tag(name=tag, slug=slug)
                db.session.add(tag_obj)

            tag_obj.posts.append(self)
Ejemplo n.º 6
0
Archivo: blog.py Proyecto: yhyan/www
 def _set_name(self, name):
     self._name = name.lower().strip()
     self.slug = slugify(name)
Ejemplo n.º 7
0
Archivo: blog.py Proyecto: yhyan/www
 def linked_taglist(self):
     tags = filter(None, [Tag.query.get(tag) for tag in self.taglist])
     return [(tag.name, route.url_for('tag', slugify(tag.slug))) \
                 for tag in tags]
Ejemplo n.º 8
0
 def _set_name(self, name):
     self._name = name.lower().strip()
     self.slug = slugify(name)
Ejemplo n.º 9
0
 def linked_taglist(self):
     return [(tag, route.url_for('tag', slugify(tag))) \
                 for tag in self.taglist]
Ejemplo n.º 10
0
 def _set_slug(self, slug):
     if slug:
         self._slug = slugify(slug)
Ejemplo n.º 11
0
 def _set_title(self, title):
     self._title = title.lower().strip()
     if self.slug is None:
         self.slug = slugify(title)[:50]