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
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
properties={ 'id': comments.c.comment_id, 'text': db.synonym('_text', map_column=True), 'author': db.synonym('_author', map_column=True), 'email': db.synonym('_email', map_column=True), 'www': db.synonym('_www', map_column=True), 'children': db.relation( Comment, primaryjoin=comments.c.parent_id == comments.c.comment_id, order_by=[db.asc(comments.c.pub_date)], backref=db.backref( 'parent', remote_side=[comments.c.comment_id], primaryjoin=comments.c.parent_id == comments.c.comment_id), lazy=True) }, order_by=comments.c.pub_date.desc()) db.mapper(PostLink, post_links, properties={ 'id': post_links.c.link_id, }) db.mapper(Tag, tags, properties={ 'id': tags.c.tag_id,
db.mapper(Comment, db.join(comments, texts), properties={ 'id': comments.c.comment_id, 'text_id': [comments.c.text_id, texts.c.text_id], '_text': texts.c.text, 'text': db.synonym('_text'), '_author': comments.c.author, 'author': db.synonym('_author'), '_email': comments.c.email, 'email': db.synonym('_email'), '_www': comments.c.www, 'www': db.synonym('_www'), '_status': comments.c.status, 'status': db.synonym('_status'), 'children': db.relation(Comment, primaryjoin=comments.c.parent_id == comments.c.comment_id, order_by=[db.asc(comments.c.pub_date)], backref=db.backref('parent', remote_side=[comments.c.comment_id], primaryjoin=comments.c.parent_id == comments.c.comment_id), lazy=True ) }, order_by=comments.c.pub_date.desc(), primary_key=[comments.c.comment_id]) db.mapper(PostLink, post_links, properties={ 'id': post_links.c.link_id, }) db.mapper(Tag, tags, properties={ 'id': tags.c.tag_id, 'posts': db.dynamic_loader(Post, secondary=post_tags, query_class=PostQuery) }, order_by=tags.c.name) db.mapper(Post, db.join(posts, texts), properties={