models.py 1.47 KB
Newer Older
1 2 3 4 5
"""
Models for contentserver
"""

from config_models.models import ConfigurationModel
6
from django.db.models.fields import PositiveIntegerField, TextField
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29


class CourseAssetCacheTtlConfig(ConfigurationModel):
    """Configuration for the TTL of course assets."""

    class Meta(object):
        app_label = 'contentserver'

    cache_ttl = PositiveIntegerField(
        default=0,
        help_text="The time, in seconds, to report that a course asset is allowed to be cached for."
    )

    @classmethod
    def get_cache_ttl(cls):
        """Gets the cache TTL for course assets, if present"""
        return cls.current().cache_ttl

    def __repr__(self):
        return '<CourseAssetCacheTtlConfig(cache_ttl={})>'.format(self.get_cache_ttl())

    def __unicode__(self):
        return unicode(repr(self))
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52


class CdnUserAgentsConfig(ConfigurationModel):
    """Configuration for the user agents we expect to see from CDNs."""

    class Meta(object):
        app_label = 'contentserver'

    cdn_user_agents = TextField(
        default='Amazon CloudFront',
        help_text="A newline-separated list of user agents that should be considered CDNs."
    )

    @classmethod
    def get_cdn_user_agents(cls):
        """Gets the list of CDN user agents, if present"""
        return cls.current().cdn_user_agents

    def __repr__(self):
        return '<WhitelistedCdnConfig(cdn_user_agents={})>'.format(self.get_cdn_user_agents())

    def __unicode__(self):
        return unicode(repr(self))