示例#1
0
        """
        if not hasattr(self, '_number'):
            self._number = list(
                self.season.timeslot_set.values_list('pk', flat=True)).index(
                    self.pk) + 1
        return self._number

    @classmethod
    def make_foreign_key(cls):
        """
        Shortcut for creating a field that links to a timeslot, given
        the source model's metadata class.

        """
        kwargs = {}
        if hasattr(settings, 'TIMESLOT_DB_FKEY_COLUMN'):
            kwargs['db_column'] = settings.TIMESLOT_DB_FKEY_COLUMN
        return models.ForeignKey(
            cls, help_text='The timeslot associated with this item.', **kwargs)


TimeslotTextMetadata = TextMetadata.make_model(
    Timeslot,
    'schedule',
    'TimeslotTextMetadata',
    getattr(settings, 'TIMESLOT_TEXT_METADATA_DB_TABLE', None),
    getattr(settings, 'TIMESLOT_TEXT_METADATA_DB_ID_COLUMN', None),
    fkey=Timeslot.make_foreign_key(),
)
示例#2
0
        """
        # Show rules take precedence
        block_matches = self.blockshowrule_set.order_by(
            '-block__priority').only('block')
        try:
            block = block_matches[0].block
        except IndexError:
            block = None
        return block


ShowTextMetadata = TextMetadata.make_model(
    Show,
    'schedule',
    'ShowTextMetadata',
    getattr(settings, 'SHOW_TEXT_METADATA_DB_TABLE', None),
    getattr(settings, 'SHOW_TEXT_METADATA_DB_ID_COLUMN', None),
    fkey=Show.make_foreign_key(),
)

ShowImageMetadata = ImageMetadata.make_model(
    Show,
    'schedule',
    'ShowImageMetadata',
    getattr(settings, 'SHOW_IMAGE_METADATA_DB_TABLE', None),
    getattr(settings, 'SHOW_IMAGE_METADATA_DB_ID_COLUMN', None),
    fkey=Show.make_foreign_key(),
)

ShowPodcastLink = PodcastLink.make_model(
    Show,
    def make_foreign_key(cls):
        """
        Shortcut for creating a field that links to a season, given
        the source model's metadata class.

        """
        kwargs = {}
        if hasattr(settings, 'SEASON_DB_FKEY_COLUMN'):
            kwargs['db_column'] = settings.SEASON_DB_FKEY_COLUMN
        return models.ForeignKey(
            cls,
            help_text='The season associated with this item.',
            **kwargs
        )


SeasonTextMetadata = TextMetadata.make_model(
    Season,
    'schedule',
    'SeasonTextMetadata',
    getattr(
        settings, 'SEASON_TEXT_METADATA_DB_TABLE',
        None
    ),
    getattr(
        settings, 'SEASON_TEXT_METADATA_DB_ID_COLUMN',
        None
    ),
    fkey=Season.make_foreign_key(),
)
            #if block_show_matches.exists():
            #block = block_show_matches[0]
            #else:
            block = None
        else:
            block = show_block
        return block

    @classmethod
    def make_foreign_key(cls):
        """
        Shortcut for creating a field that links to a season, given
        the source model's metadata class.

        """
        kwargs = {}
        if hasattr(settings, 'SEASON_DB_FKEY_COLUMN'):
            kwargs['db_column'] = settings.SEASON_DB_FKEY_COLUMN
        return models.ForeignKey(
            cls, help_text='The season associated with this item.', **kwargs)


SeasonTextMetadata = TextMetadata.make_model(
    Season,
    'schedule',
    'SeasonTextMetadata',
    getattr(settings, 'SEASON_TEXT_METADATA_DB_TABLE', None),
    getattr(settings, 'SEASON_TEXT_METADATA_DB_ID_COLUMN', None),
    fkey=Season.make_foreign_key(),
)
        """
        # Show rules take precedence
        block_matches = self.blockshowrule_set.order_by(
            '-block__priority'
        ).only('block')
        try:
            block = block_matches[0].block
        except IndexError:
            block = None
        return block


ShowTextMetadata = TextMetadata.make_model(
    Show,
    'schedule',
    'ShowTextMetadata',
    getattr(settings, 'SHOW_TEXT_METADATA_DB_TABLE', None),
    getattr(settings, 'SHOW_TEXT_METADATA_DB_ID_COLUMN', None),
    fkey=Show.make_foreign_key(),
)


ShowImageMetadata = ImageMetadata.make_model(
    Show,
    'schedule',
    'ShowImageMetadata',
    getattr(settings, 'SHOW_IMAGE_METADATA_DB_TABLE', None),
    getattr(settings, 'SHOW_IMAGE_METADATA_DB_ID_COLUMN', None),
    fkey=Show.make_foreign_key(),
)

    def make_foreign_key(cls):
        """
        Shortcut for creating a field that links to a timeslot, given
        the source model's metadata class.

        """
        kwargs = {}
        if hasattr(settings, 'TIMESLOT_DB_FKEY_COLUMN'):
            kwargs['db_column'] = settings.TIMESLOT_DB_FKEY_COLUMN
        return models.ForeignKey(
            cls,
            help_text='The timeslot associated with this item.',
            **kwargs
        )


TimeslotTextMetadata = TextMetadata.make_model(
    Timeslot,
    'schedule',
    'TimeslotTextMetadata',
    getattr(
        settings, 'TIMESLOT_TEXT_METADATA_DB_TABLE',
        None
    ),
    getattr(
        settings, 'TIMESLOT_TEXT_METADATA_DB_ID_COLUMN',
        None
    ),
    fkey=Timeslot.make_foreign_key(),
)
示例#7
0
            )
        return models.ForeignKey(
            cls,
            help_text='The grid associated with this item.',
            **_FKEY_KWARGS
        )

    class Meta(Type.Meta):
        if hasattr(settings, 'GRID_BLOCK_DB_TABLE'):
            db_table = getattr(settings, 'GRID_BLOCK_DB_TABLE')
        app_label = 'grid'

GridBlockTextMetadata = TextMetadata.make_model(
    GridBlock,
    'grid',
    'GridBlockTextMetadata',
    getattr(settings, 'GRID_BLOCK_TEXT_METADATA_DB_TABLE', None),
    getattr(settings, 'GRID_BLOCK_TEXT_METADATA_DB_ID_COLUMN', None),
    fkey=GridBlock.make_foreign_key()
)


class Grid(Type):
    """
    An object representing a grid of `GridBlock`s.

    """

    width = models.IntegerField(
        default=3,
        help_text='The maximum width, in multiples of one standard'
        'block, that this grid will allow.'
示例#8
0
            **_FKEY_KWARGS
        )

    class Meta:
        if hasattr(settings, 'PODCAST_CHANNEL_DB_TABLE'):
            db_table = settings.PODCAST_CHANNEL_DB_TABLE
        app_label = 'uryplayer'


PodcastChannelTextMetadata = TextMetadata.make_model(
    PodcastChannel,
    'uryplayer',
    'PodcastChannelTextMetadata',
    getattr(
        settings, 'PODCAST_CHANNEL_TEXT_METADATA_DB_TABLE',
        None
    ),
    getattr(
        settings, 'PODCAST_CHANNEL_TEXT_METADATA_DB_ID_COLUMN',
        None
    ),
    fkey=PodcastChannel.make_foreign_key(),
)


class PodcastChannelTextMetadataRule(models.Model):
    """A matching rule that matches any podcast whose textual
    metadata contains or is the given string.

    """

    class Meta:
    class Meta(object):
        if hasattr(settings, 'PACKAGE_DB_TABLE'):
            db_table = settings.PACKAGE_DB_TABLE

        app_label = 'metadata'
        ordering = ('-weight',)


PackageTextMetadata = TextMetadata.make_model(
    Package,
    'metadata',
    'PackageTextMetadata',
    getattr(
        settings, 'PACKAGE_TEXT_METADATA_DB_TABLE',
        None
    ),
    getattr(
        settings, 'PACKAGE_TEXT_METADATA_DB_ID_COLUMN',
        None
    ),
    fkey=Package.make_foreign_key(),
)


PackageImageMetadata = ImageMetadata.make_model(
    Package,
    'metadata',
    'PackageImageMetadata',
    getattr(
        settings, 'PACKAGE_IMAGE_METADATA_DB_TABLE',
        None