Example #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)
    ))
Example #2
0
 def delete_user(self):
     """Deletes the user."""
     if self.data['action'] == 'reassign':
         db.execute(posts.update(posts.c.author_id == self.user.id), dict(
             author_id=self.data['reassign_to'].id
         ))
     #! plugins can use this to react to user deletes.  They can't stop
     #! the deleting of the user but they can delete information in
     #! their own tables so that the database is consistent afterwards.
     #! Additional to the user object the form data is submitted.
     emit_event('before-user-deleted', self.user, self.data)
     db.delete(self.user)
Example #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)
Example #4
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)
Example #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
Example #6
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
Example #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
Example #8
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.slug, t.name,
             db.func.count(p.post_id).label('s_count')],
            q,
            group_by=[t.slug, t.name]).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.slug, s.name, s.s_count.label('s_count')], **options)

        items = [{
            '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
Example #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()))
Example #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')
Example #11
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)))
Example #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()))
Example #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')
Example #14
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
Example #15
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