from django.conf import settings
from django.core.files.storage import default_storage

from pretix.base.i18n import LazyI18nString
from pretix.base.settings import GlobalSettingsObject

from .signals import footer_link, html_head


def contextprocessor(request):
    """
    Adds data to all template contexts
    """
    if request.path.startswith('/control'):
        return {}

    ctx = {
        'css_file': None,
        'DEBUG': settings.DEBUG,
    }
    _html_head = []
    _footer = []

    if hasattr(request, 'event'):
        pretix_settings = request.event.settings
    elif hasattr(request, 'organizer'):
        pretix_settings = request.organizer.settings
    else:
        pretix_settings = GlobalSettingsObject().settings

    text = str(pretix_settings.get('footer_text', as_type=LazyI18nString))
    link = str(pretix_settings.get('footer_link', as_type=LazyI18nString))

    if text:
        if link:
            _footer.append({'url': link, 'label': text})
        else:
            ctx['footer_text'] = text

    if hasattr(request, 'event'):
        for receiver, response in html_head.send(request.event, request=request):
            _html_head.append(response)
        for receiver, response in footer_link.send(request.event, request=request):
            _footer.append(response)

        if request.event.settings.presale_css_file:
            ctx['css_file'] = default_storage.url(request.event.settings.presale_css_file)
        ctx['event_logo'] = request.event.settings.get('logo_image', as_type=str, default='')[7:]
        ctx['event'] = request.event

    ctx['html_head'] = "".join(_html_head)
    ctx['footer'] = _footer
    ctx['site_url'] = settings.SITE_URL

    return ctx

@@ -746,20 +746,16 @@
  text = 
-str(
 pretix_s
@@ -804,17 +804,16 @@
 nString)
-)
 %0A    lin
@@ -820,12 +820,8 @@
 k = 
-str(
 pret
@@ -874,17 +874,16 @@
 nString)
-)
 %0A%0A    if
@@ -941,20 +941,25 @@
 %7B'url': 
+str(
 link
+)
 , 'label
@@ -961,20 +961,25 @@
 label': 
+str(
 text
+)
 %7D)%0A     
@@ -1020,20 +1020,25 @@
 ext'%5D = 
+str(
 text
+)
 %0A%0A    if

Fix "None" in global footer