示例#1
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]
示例#2
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]
示例#3
0
def create_or_login(response):

    openid = response.identity_url

    user, authenticated = \
        User.query.authenticate_openid(response.email, openid)

    next_url = session.pop('next', None)

    if user is None:
        session['openid'] = openid

        username = response.fullname or response.nickname
        if username:
            username = slugify(username.replace("-", "_"))

        return redirect(
            url_for("openid.signup",
                    next=next_url,
                    name=username,
                    email=response.email))

    if authenticated:

        session.permanent = True

        identity_changed.send(current_app._get_current_object(),
                              identity=Identity(user.id))

        flash(_("Welcome back, %%s") % user.username, "success")

        if next_url is None:
            next_url = url_for('user.posts', username=user.username)

        return redirect(next_url)

    # user already exists, so login and attach openid
    session['openid'] = openid

    flash(
        _("You already have an account with us. "
          "Please login with your email address so your "
          "OpenID can be attached to your user account"), "success")

    return redirect(url_for('account.login', login=response.email))
示例#4
0
def create_or_login(response):

    openid = response.identity_url

    user, authenticated = \
        User.query.authenticate_openid(response.email, openid)

    next_url = session.pop('next', None)

    if user is None:
        session['openid'] = openid

        username = response.fullname or response.nickname
        if username:
            username = slugify(username.replace("-", "_"))

        return redirect(url_for("openid.signup",
                                next=next_url,
                                name=username,
                                email=response.email))

    if authenticated:

        session.permanent = True

        identity_changed.send(current_app._get_current_object(),
                              identity=Identity(user.id))

        flash(_("Welcome back, %%s") % user.username, "success")

        if next_url is None:
            next_url = url_for('user.posts', username=user.username)

        return redirect(next_url)

    # user already exists, so login and attach openid
    session['openid'] = openid

    flash(_("You already have an account with us. "
            "Please login with your email address so your "
            "OpenID can be attached to your user account"), "success")

    return redirect(url_for('account.login',
                            login=response.email))
示例#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)

            if self not in tag_obj.posts:
                tag_obj.posts.append(self)
示例#6
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)

            if self not in tag_obj.posts:
                tag_obj.posts.append(self)
示例#7
0
    def test_slugify(self):

        assert slugify("hello, this is a test") == "hello-this-is-a-test"
示例#8
0
 def _set_name(self, name):
     self._name = name.lower().strip()
     self.slug = slugify(name)
示例#9
0
 def slug(self):
     return slugify(self.title or '')[:80]
示例#10
0
 def _set_name(self, name):
     self._name = name.lower().strip()
     self.slug = slugify(name)
示例#11
0
 def slug(self):
     return slugify(self.title or '')[:80]
示例#12
0
    def test_slugify(self):

        assert slugify("hello, this is a test") == "hello-this-is-a-test"