Exemplo n.º 1
0
    'comments': dynamic_loader(Comment, backref='media', query_class=CommentQuery, passive_deletes=True),
    'comment_count': column_property(
        sql.select([sql.func.count(comments.c.id)],
                   media.c.id == comments.c.media_id).label('comment_count'),
        deferred=True),
    'comment_count_published': column_property(
        sql.select([sql.func.count(comments.c.id)],
                   sql.and_(comments.c.media_id == media.c.id,
                            comments.c.publishable == True)).label('comment_count_published'),
        deferred=True),
})

# Add properties for counting how many media items have a given Tag
_tags_mapper = class_mapper(Tag, compile=False)
_tags_mapper.add_properties(_properties_dict_from_labels(
    _mtm_count_property('media_count', media_tags),
    _mtm_count_property('media_count_published', media_tags, [
        media.c.reviewed == True,
        media.c.encoded == True,
        media.c.publishable == True,
        media.c.publish_on <= datetime.now(),
        sql.or_(media.c.publish_until == None,
                media.c.publish_until >= datetime.now()),
    ]),
))

# Add properties for counting how many media items have a given Category
_categories_mapper = class_mapper(Category, compile=False)
_categories_mapper.add_properties(_properties_dict_from_labels(
    _mtm_count_property('media_count', media_categories),
    _mtm_count_property('media_count_published', media_categories, [
Exemplo n.º 2
0
        'comment_count_published': column_property(
            sql.select(
                [sql.func.count(comments.c.id)],
                sql.and_(
                    comments.c.media_id == media.c.id,
                    comments.c.publishable == True,
                )
            ).label('comment_count_published'),
            deferred=True,
        ),
})

# Add properties for counting how many media items have a given Tag
_tags_mapper = class_mapper(Tag, compile=False)
_tags_mapper.add_properties(_properties_dict_from_labels(
    _mtm_count_property('media_count', media_tags),
    _mtm_count_property('media_count_published', media_tags, [
        media.c.reviewed == True,
        media.c.encoded == True,
        media.c.publishable == True,
        media.c.publish_on <= sql.func.current_timestamp(),
        sql.or_(
            media.c.publish_until == None,
            media.c.publish_until >= sql.func.current_timestamp(),
        ),
    ]),
))

# Add properties for counting how many media items have a given Category
_categories_mapper = class_mapper(Category, compile=False)
_categories_mapper.add_properties(_properties_dict_from_labels(
Exemplo n.º 3
0
        'comment_count_published':
        column_property(
            sql.select([sql.func.count(comments.c.id)],
                       sql.and_(
                           comments.c.media_id == media.c.id,
                           comments.c.publishable == True,
                       )).label('comment_count_published'),
            deferred=True,
        ),
    })

# Add properties for counting how many media items have a given Tag
_tags_mapper = class_mapper(Tag, compile=False)
_tags_mapper.add_properties(
    _properties_dict_from_labels(
        _mtm_count_property('media_count', media_tags),
        _mtm_count_property('media_count_published', media_tags, [
            media.c.reviewed == True,
            media.c.encoded == True,
            media.c.publishable == True,
            media.c.publish_on <= sql.func.current_timestamp(),
            sql.or_(
                media.c.publish_until == None,
                media.c.publish_until >= sql.func.current_timestamp(),
            ),
        ]),
    ))

# Add properties for counting how many media items have a given Category
_categories_mapper = class_mapper(Category, compile=False)
_categories_mapper.add_properties(
Exemplo n.º 4
0
        'comment_count_published': column_property(
            sql.select(
                [sql.func.count(comments.c.id)],
                sql.and_(
                    comments.c.media_id == media.c.id,
                    comments.c.publishable == True,
                )
            ).label('comment_count_published'),
            deferred=True,
        ),
})

# Add properties for counting how many media items have a given Tag
_tags_mapper = class_mapper(Tag, compile=False)
_tags_mapper.add_properties(_properties_dict_from_labels(
    _mtm_count_property('media_count', media_tags),
    _mtm_count_property('media_count_published', media_tags, [
        media.c.reviewed == True,
        media.c.encoded == True,
        media.c.publishable == True,
        media.c.publish_on <= datetime.now(),
        sql.or_(
            media.c.publish_until == None,
            media.c.publish_until >= datetime.now(),
        ),
    ]),
))

# Add properties for counting how many media items have a given Category
_categories_mapper = class_mapper(Category, compile=False)
_categories_mapper.add_properties(_properties_dict_from_labels(