def __init__(self, request): from django.conf import settings self.request = request self.app_root = get_app_setting('APP_ROOT_FOLDER') self.shared_media_url = get_app_setting('SHARED_MEDIA_URL') self.app_media_url = settings.MEDIA_URL self.url_config = settings.ROOT_URLCONF
def _build_google_analytics_code(self): """ Create the JavaScript code to enable Google Analytics tracking for the page, using a settings value to get the account ID. """ ga_id = get_app_setting("GOOGLE_ANALYTICS_ID") markup = "" if ga_id: script_blocks = ( ( "var ga_js_host = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");", "document.write(unescape(\"%3Cscript src='\" + ga_js_host + \"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));" ), ( "try {", "var page_tracker = _gat._get_tracker(\"%s\");" % ga_id, "page_tracker._track_pageview();", "} catch(err) {}" ) ) markup = "\n".join([ "<script type=\"text/javascript\">%s</script>" % "".join(block) for block in script_blocks ]) return mark_safe(markup)
def make_shared_media_url(path): """ Return the media path passed as `path` as an absolute URL rooted in the shared media folder. """ if not path.startswith("http"): path = os.path.join(get_app_setting('SHARED_MEDIA_URL'), path) return path
def new_view(*args, **kwargs): # If the current application supports secure connections, strip any # port information and change the protocol on the URL. request = args[0] if not request.is_secure() and get_app_setting('SUPPORTS_HTTPS'): return HttpResponseRedirect( re.sub(r'\:\d+\/', r'/', request.build_absolute_uri().replace('http://', 'https://'))) else: return view_function(*args, **kwargs)
def make_url_absolute(url, secure=False): """ Return the absolute version of the either relative or absolute URL provided as `url`. If the optional `secure` parameter is True and the current site supports making HTTPS connections, a secure version of the URL will be returned. """ url = urlparse.urljoin("//%s" % Site.objects.get_current().domain, url) url_parts = list(urlparse.urlparse(url)) url_parts[0] = "http%s" % ("s" * int(secure and get_app_setting("SUPPORTS_HTTPS"))) return urlparse.urlunparse(url_parts)
def _build_javascript_globals(self): """Provide certain settings and paths as JavaScript globals.""" self._js_vars = { 'widgets': {} } self._js_settings_vars = { 'app_name': get_app_setting('APPLICATION_NAME'), 'app_root': self.app_root, 'media_url': self.app_media_url, 'shared_media_url': self.shared_media_url }
def new_view(*args, **kwargs): # If the current application supports secure connections, strip any # port information and change the protocol on the URL. request = args[0] if not request.is_secure() and get_app_setting('SUPPORTS_HTTPS'): return HttpResponseRedirect( re.sub( r'\:\d+\/', r'/', request.build_absolute_uri().replace( 'http://', 'https://'))) else: return view_function(*args, **kwargs)
def make_url_absolute(url, secure=False): """ Return the absolute version of the either relative or absolute URL provided as `url`. If the optional `secure` parameter is True and the current site supports making HTTPS connections, a secure version of the URL will be returned. """ url = urlparse.urljoin("//%s" % Site.objects.get_current().domain, url) url_parts = list(urlparse.urlparse(url)) url_parts[0] = "http%s" % ( "s" * int(secure and get_app_setting('SUPPORTS_HTTPS'))) return urlparse.urlunparse(url_parts)
def email_support(): """Return a link to email the support address specified in the settings.""" return mark_safe(u'<a href="mailto:%s">%s</a>' % (get_app_setting('SUPPORT_EMAIL_ADDRESS'), get_app_setting('SUPPORT_EMAIL_NAME')))
class SharedMedia: js = ('core/js/libs/ckeditor/ckeditor.js', get_app_setting('RTE_CONFIG_FILE'), 'core/js/widgets/rich_text.js')
def email_support(): """Return a link to email the support address specified in the settings.""" return mark_safe(u'<a href="mailto:%s">%s</a>' % ( get_app_setting('SUPPORT_EMAIL_ADDRESS'), get_app_setting('SUPPORT_EMAIL_NAME') ))
from cilcdjango.core.util import get_app_setting import os UPLOADED_FILES_DIRECTORY = "media_libraries" ADD_MEDIA_FORM_AUTO_ID = "id_media_%s" ADD_GROUP_FORM_AUTO_ID = "id_group_%s" MEDIA_PLAYER_URL = "flash/jwplayer/player.swf" MEDIA_URL = os.path.join(get_app_setting('SHARED_MEDIA_URL'), 'medialibrary')