예제 #1
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
예제 #2
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
예제 #3
0
        db.synonym('_text', map_column=True),
        'comments':
        db.relation(Comment,
                    backref='post',
                    primaryjoin=posts.c.post_id == comments.c.post_id,
                    order_by=[db.asc(comments.c.pub_date)],
                    lazy=False,
                    cascade='all, delete, delete-orphan'),
        'links':
        db.relation(PostLink,
                    backref='post',
                    cascade='all, delete, delete-orphan'),
        'categories':
        db.relation(Category,
                    secondary=post_categories,
                    lazy=False,
                    order_by=[db.asc(categories.c.name)]),
        'tags':
        db.relation(Tag,
                    secondary=post_tags,
                    lazy=False,
                    order_by=[tags.c.name]),
        '_comment_count':
        db.column_property(db.select(
            [db.func.count(comments.c.comment_id)],
            (comments.c.post_id == posts.c.post_id) &
            (comments.c.status == COMMENT_MODERATED)).label('comment_count'),
                           deferred=True)
    },
    order_by=posts.c.pub_date.desc())
예제 #4
0
파일: __init__.py 프로젝트: jace/zine-main
 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
예제 #5
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