Beispiel #1
0
    def _validate_enable_feed(self, key, on):
        """Ensure that modifications to the enable_feed prop won't break things.

        You cannot disable the last feed-enable file of a podcast episode.
        """
        if (not on and self.media and self.media.podcast_id
            and len([f for f in self.media.files if f.enable_feed]) == 1):
            raise MediaException, ('Published podcast media requires '
                                   'at least one file be feed-enabled.')
        return on


mapper(MediaFile, media_files)

_media_mapper = mapper(Media, media, properties={
    'status': status_column_property(media.c.status),
    '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'
    )),
Beispiel #2
0
    .. warning::

        The type given here and the name of the backref passed to
        :func:`sqlalchemy.orm.relation` must match for the reverse-lookup
        to work.

    """
    def __init__(self, type):
        self.type = type

    def append(self, state, value, initiator):
        value.type = self.type
        return value

    def set(self, value, oldvalue, initiator):
        # Pretty certain this should never be called on a relation property.
        raise NotImplemented


comment_count_property = _mtm_count_property


mapper(Comment, comments, properties={
    'status': status_column_property(comments.c.status),
    'author': composite(AuthorWithIP,
        comments.c.author_name,
        comments.c.author_email,
        comments.c.author_ip),
})