Browse Source

Mobile theme support #121

Ralfp 12 years ago
parent
commit
face4e6920
3 changed files with 24 additions and 0 deletions
  1. 6 0
      deployment/settings.py
  2. 12 0
      misago/middleware/theme.py
  3. 6 0
      misago/settings_base.py

+ 6 - 0
deployment/settings.py

@@ -137,6 +137,12 @@ INSTALLED_THEMES = (
     'admin', # Admin theme always last
 )
 
+# Enable mobile subdomain for mobile stuff
+MOBILE_SUBDOMAIN = ''
+
+# Templates used by mobile version
+MOBILE_TEMPLATES = ''
+
 # Python dotted path to the WSGI application used by Django's runserver.
 WSGI_APPLICATION = 'deployment.wsgi.application'
 

+ 12 - 0
misago/middleware/theme.py

@@ -1,3 +1,4 @@
+from urlparse import urlparse
 from django.conf import settings
 from django.core.cache import cache
 from misago.theme import Theme
@@ -7,3 +8,14 @@ class ThemeMiddleware(object):
         if not settings.INSTALLED_THEMES:
             raise ValueError('There are no themes installed!')
         request.theme = Theme(settings.INSTALLED_THEMES[0])
+
+        if settings.MOBILE_SUBDOMAIN and settings.MOBILE_TEMPLATES:
+            if settings.MOBILE_SUBDOMAIN == '*':
+                request.theme = Theme(settings.MOBILE_TEMPLATES)
+            else:
+                mobile_domain = '%s.%s/' % (settings.MOBILE_SUBDOMAIN, urlparse(settings.BOARD_ADDRESS).netloc)
+                current_domain = '%s.%s/' % (settings.MOBILE_SUBDOMAIN, urlparse(request.META.get('HTTP_HOST')).netloc)
+                
+                if current_domain == mobile_domain:
+                    request.theme = Theme(settings.MOBILE_TEMPLATES)
+                    

+ 6 - 0
misago/settings_base.py

@@ -10,6 +10,12 @@ ALLOWED_HOSTS = ['*']
 # Leave this setting empty
 ADMIN_PATH = ''
 
+# Enable mobile subdomain for mobile stuff
+MOBILE_SUBDOMAIN = ''
+
+# Templates used by mobile version
+MOBILE_TEMPLATES = ''
+
 # Default format of Misago generated HTML
 OUTPUT_FORMAT = 'html5'