コード例 #1
0
ファイル: models.py プロジェクト: rockyburt/Rezine
    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
ファイル: models.py プロジェクト: rockyburt/Rezine
    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
コード例 #3
0
ファイル: __init__.py プロジェクト: rockyburt/Rezine
 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
コード例 #4
0
ファイル: __init__.py プロジェクト: rockyburt/Rezine
 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