Example #1
0
        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, [
        media.c.reviewed == True,
        media.c.encoded == True,
        media.c.publishable == True,
        media.c.publish_on <= datetime.now(),
Example #2
0
                           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(
        _mtm_count_property('media_count', media_categories),
        _mtm_count_property('media_count_published', media_categories, [
            media.c.reviewed == True,
            media.c.encoded == True,
Example #3
0
    'author': composite(Author, media.c.author_name, media.c.author_email),
    'rating': composite(Rating, media.c.rating_sum, media.c.rating_votes),
    'files': relation(MediaFile, backref='media', order_by=media_files.c.position.asc(), passive_deletes=True),
    'tags': relation(Tag, secondary=media_tags, backref='media', collection_class=TagList),
    'topics': relation(Topic, secondary=media_topics, backref='media', collection_class=TopicList),
    'comments': relation(Comment, secondary=media_comments, backref=backref('media', uselist=False),
        extension=CommentTypeExtension('media'), single_parent=True, passive_deletes=True),
})

# Add comment_count, comment_count_published, ... column properties to Media
_media_mapper.add_properties(_properties_dict_from_labels(
    comment_count_property('comment_count', media_comments),
    comment_count_property('comment_count_published', media_comments, status_where(
        comments.c.status, include='publish', exclude='trash'
    )),
    comment_count_property('comment_count_unreviewed', media_comments, status_where(
        comments.c.status, include='unreviewed', exclude='trash'
    )),
    comment_count_property('comment_count_trash', media_comments, status_where(
        comments.c.status, include='trash'
    )),
))

# 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(
    tag_count_property('media_count', media_tags, status_where(
        media.c.status, exclude='trash'
    )),
    tag_count_property('published_media_count', media_tags, status_where(
        media.c.status, include='publish', exclude='trash'
    )),
Example #4
0
            ).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(
        _mtm_count_property("media_count", media_categories),
        _mtm_count_property(
            "media_count_published",
Example #5
0
                    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, [
        media.c.reviewed == True,
        media.c.encoded == True,
        media.c.publishable == True,