Exemplo n.º 1
0
def register_redirect(original, new_url):
    """Register a new redirect.  Also an old one that may still exist."""
    original = _strip_url(original)
    db.execute(redirects.delete(original=original))
    db.execute(redirects.insert(), dict(
        original=original,
        new=_strip_url(new_url)
    ))
Exemplo n.º 2
0
def lookup_redirect(url):
    """Looks up a redirect.  If there is not redirect for the given URL,
    the return value is `None`.
    """
    row = db.execute(
        redirects.select(redirects.c.original == _strip_url(url))).fetchone()
    if row:
        return make_external_url(row.new)
Exemplo n.º 3
0
def lookup_redirect(url):
    """Looks up a redirect.  If there is not redirect for the given URL,
    the return value is `None`.
    """
    row = db.execute(redirects.select(
        redirects.c.original == _strip_url(url)
    )).fetchone()
    if row:
        return make_external_url(row.new)
Exemplo n.º 4
0
 def requires_moderation(self):
     """This is `True` if the comment requires moderation with the
     current moderation settings.  This does not check if the comment
     is already moderated.
     """
     if not self.anonymous:
         return False
     moderate = get_application().cfg['moderate_comments']
     if moderate == MODERATE_ALL:
         return True
     elif moderate == MODERATE_NONE:
         return False
     return db.execute(
         comments.select(
             (comments.c.author == self._author)
             & (comments.c.email == self._email)
             & (comments.c.status == COMMENT_MODERATED))).fetchone() is None
Exemplo n.º 5
0
 def requires_moderation(self):
     """This is `True` if the comment requires moderation with the
     current moderation settings.  This does not check if the comment
     is already moderated.
     """
     if not self.anonymous:
         return False
     moderate = get_application().cfg['moderate_comments']
     if moderate == MODERATE_ALL:
         return True
     elif moderate == MODERATE_NONE:
         return False
     return db.execute(comments.select(
         (comments.c.author == self._author) &
         (comments.c.email == self._email) &
         (comments.c.status == COMMENT_MODERATED)
     )).fetchone() is None
Exemplo n.º 6
0
    def get_cloud(self, max=None, ignore_privileges=False):
        """Get a categorycloud."""
        # XXX: ignore_privileges is currently ignored and no privilege
        # checking is performed.  As a matter of fact only published posts
        # appear in the cloud.

        # get a query
        pt = post_tags.c
        p = posts.c
        t = tags.c

        q = ((pt.tag_id == t.tag_id) & (pt.post_id == p.post_id) &
             (p.status == STATUS_PUBLISHED) &
             (p.pub_date <= datetime.utcnow()))

        s = db.select([
            t.tag_id, t.slug, t.name,
            db.func.count(p.post_id).label('s_count')
        ],
                      q,
                      group_by=[t.slug, t.name,
                                t.tag_id]).alias('post_count_query').c

        options = {'order_by': [db.asc(s.s_count)]}
        if max is not None:
            options['limit'] = max

        # the label statement circumvents a bug for sqlite3 on windows
        # see #65
        q = db.select([s.tag_id, s.slug, s.name,
                       s.s_count.label('s_count')], **options)

        items = [{
            'id': row.tag_id,
            'slug': row.slug,
            'name': row.name,
            'count': row.s_count,
            'size': 100 + log(row.s_count or 1) * 20
        } for row in db.execute(q)]

        items.sort(key=lambda x: x['name'].lower())
        return items
Exemplo n.º 7
0
    def get_cloud(self, max=None, ignore_privileges=False):
        """Get a categorycloud."""
        # XXX: ignore_privileges is currently ignored and no privilege
        # checking is performed.  As a matter of fact only published posts
        # appear in the cloud.

        # get a query
        pt = post_tags.c
        p = posts.c
        t = tags.c

        q = ((pt.tag_id == t.tag_id) &
             (pt.post_id == p.post_id) &
             (p.status == STATUS_PUBLISHED) &
             (p.pub_date <= datetime.utcnow()))

        s = db.select(
            [t.tag_id, t.slug, t.name,
             db.func.count(p.post_id).label('s_count')],
            q, group_by=[t.slug, t.name, t.tag_id]).alias('post_count_query').c

        options = {'order_by': [db.asc(s.s_count)]}
        if max is not None:
            options['limit'] = max

        # the label statement circumvents a bug for sqlite3 on windows
        # see #65
        q = db.select([s.tag_id, s.slug, s.name, s.s_count.label('s_count')],
                      **options)

        items = [{
            'id':       row.tag_id,
            'slug':     row.slug,
            'name':     row.name,
            'count':    row.s_count,
            'size':     100 + log(row.s_count or 1) * 20
        } for row in db.execute(q)]

        items.sort(key=lambda x: x['name'].lower())
        return items
Exemplo n.º 8
0
 def __setstate__(self, d):
     self.__dict__ = d
     uids = set(x.uid for x in db.execute(db.select([posts.c.uid])))
     for post in self.posts:
         post.already_imported = post.uid in uids
Exemplo n.º 9
0
def get_redirect_map():
    """Return a dict of all redirects."""
    return dict((row.original, make_external_url(row.new)) for row in
                db.execute(redirects.select()))
Exemplo n.º 10
0
def unregister_redirect(url):
    """Unregister a redirect."""
    rv = db.execute(redirects.delete(redirects.c.original == _strip_url(url)))
    if not rv.rowcount:
        raise ValueError('no such URL')
Exemplo n.º 11
0
 def __setstate__(self, d):
     self.__dict__ = d
     uids = set(x.uid for x in db.execute(db.select([posts.c.uid])))
     for post in self.posts:
         post.already_imported = post.uid in uids
Exemplo n.º 12
0
def get_redirect_map():
    """Return a dict of all redirects."""
    return dict((row.original, make_external_url(row.new))
                for row in db.execute(redirects.select()))
Exemplo n.º 13
0
def unregister_redirect(url):
    """Unregister a redirect."""
    rv = db.execute(redirects.delete(redirects.c.original == _strip_url(url)))
    if not rv.rowcount:
        raise ValueError('no such URL')
Exemplo n.º 14
0
def register_redirect(original, new_url):
    """Register a new redirect.  Also an old one that may still exist."""
    original = _strip_url(original)
    db.execute(redirects.delete(original=original))
    db.execute(redirects.insert(),
               dict(original=original, new=_strip_url(new_url)))