A base URL can now be configured which is, potentially, prepended to an asset URL. This allows a CDN, or caching server, to front static asset requests, taking load off of the contentstore and speeding up page load times. Asset URL generation respects locked vs unlocked assets, and will not generate links to locked assets that would traverse a CDN (even though the authorization component of the contentserver middleware wouldn't allow those links to work anyways).
30 lines
805 B
Python
30 lines
805 B
Python
"""
|
|
Models for static_replace
|
|
"""
|
|
|
|
from django.db.models.fields import TextField
|
|
from config_models.models import ConfigurationModel
|
|
|
|
|
|
class AssetBaseUrlConfig(ConfigurationModel):
|
|
"""Configuration for the base URL used for static assets."""
|
|
|
|
class Meta(object):
|
|
app_label = 'static_replace'
|
|
|
|
base_url = TextField(
|
|
blank=True,
|
|
help_text="The alternative hostname to serve static assets from. Should be in the form of hostname[:port]."
|
|
)
|
|
|
|
@classmethod
|
|
def get_base_url(cls):
|
|
"""Gets the base URL to use for serving static assets, if present"""
|
|
return cls.current().base_url
|
|
|
|
def __repr__(self):
|
|
return '<AssetBaseUrlConfig(base_url={})>'.format(self.get_base_url())
|
|
|
|
def __unicode__(self):
|
|
return unicode(repr(self))
|