<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>.gitignore</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -4,3 +4,8 @@ from django.conf import settings
 MEDIA_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'media')
 MEDIA_PREFIX = getattr(settings, 'MOBILEADMIN_MEDIA_PREFIX', '/mobileadmin_media/')
 MEDIA_REGEX = r'^%s(?P&lt;path&gt;.*)$' % MEDIA_PREFIX.lstrip('/')
+
+COOKIE_AGE = getattr(settings, 'MOBILEADMIN_COOKIE_AGE', settings.SESSION_COOKIE_AGE)
+
+# A string like &quot;.lawrence.com&quot;, or None for standard domain cookie.
+COOKIE_DOMAIN = getattr(settings, 'MOBILEADMIN_COOKIE_DOMAIN', settings.SESSION_COOKIE_DOMAIN)</diff>
      <filename>mobileadmin/conf/settings.py</filename>
    </modified>
    <modified>
      <diff>@@ -47,3 +47,43 @@ function tabSwitcher(tabLabels) {
         $(&quot;_&quot;+label).addEventListener(&quot;click&quot;, toggle, false);
     }
 }
+
+function getElementsByClassName(className, tag, elm){
+    var testClass = new RegExp(&quot;(^|\\s)&quot; + className + &quot;(\\s|$)&quot;);
+    var tag = tag || &quot;*&quot;;
+    var elm = elm || document;
+    var elements = (tag == &quot;*&quot; &amp;&amp; elm.all)? elm.all : elm.getElementsByTagName(tag);
+    var returnElements = [];
+    var current;
+    var length = elements.length;
+    for(var i=0; i&lt;length; i++){
+        current = elements[i];
+        if(testClass.test(current.className)){
+            returnElements.push(current);
+        }   
+    }
+    return returnElements;
+}
+
+function createCookie(value, age, path, secure) {
+    var cookie = &quot;mobileadmin=&quot;+escape(value);
+    var date = new Date();
+    date.setTime(date.getTime()+(age*1000));
+    cookie += &quot;; expires=&quot;+date.toGMTString();
+    cookie += &quot;; path=/&quot; + path;
+    if (secure)
+        cookie += &quot;; secure&quot;;
+    document.cookie = cookie;
+}
+
+function toggle(age, path, secure) {
+    var toggle_link = $('mobileadmin_toggle');
+}
+
+var toggle_link = document.createElement('a');
+toggle_link.setAttribute('href','');
+var toggle_link_text = document.createTextNode(&quot;toggle&quot;)
+toggle_link.appendChild(toggle_link_text);
+var user_tools = getElementsByClassName('user-tools');
+alert(user_tools);
+user_tools[0].appendChild(toggle_link);</diff>
      <filename>mobileadmin/media/js/base.js</filename>
    </modified>
    <modified>
      <diff>@@ -5,10 +5,16 @@ This is used later on to load special mobile-admin templates.
 
 &quot;&quot;&quot;
 
-import os, re
-from django.core.urlresolvers import reverse, NoReverseMatch
+import os
+import re
+import time
 from django.conf import settings
+from django.utils.http import cookie_date
 from django.utils.cache import patch_vary_headers
+from django.core.urlresolvers import reverse, NoReverseMatch
+from django.template import Template, Context
+from django.utils.encoding import force_unicode
+from mobileadmin.conf.settings import COOKIE_AGE, COOKIE_DOMAIN
 
 try:
     from threading import local
@@ -16,9 +22,27 @@ except ImportError:
     from django.utils._threading_local import local
 _thread_locals = local()
 
-safari_regex = re.compile(r'AppleWebKit/.*Mobile/')
-blackbarry_regex = re.compile(r'^BlackBerry')
-opera_mini_regex = re.compile(r'[Oo]pera [Mm]ini')
+safari = re.compile(r'AppleWebKit/.*Mobile/')
+blackbarry = re.compile(r'^BlackBerry')
+opera_mini = re.compile(r'[Oo]pera [Mm]ini')
+
+TOGGLE_TEMPLATE = &quot;&quot;&quot;\
+&lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;
+    $('toggle').addEventListener('click', function() {
+        toggle('on', {{ age }}, '{{ admin_url }}', {{ secure|yesno:&quot;true,false&quot; }});
+    }, false);
+&lt;/script&gt;
+&quot;&quot;&quot;
+
+def is_valid_user_agent(user_agent):
+    &quot;&quot;&quot;
+    Checks if the given user agent string matches one of the valid user agents.
+    &quot;&quot;&quot;
+    valid_user_agents = (safari, blackbarry, opera_mini)
+    for regex in valid_user_agents:
+        if regex.search(user_agent) is not None:
+            return True
+    return False
 
 def normalize_slashes(path):
     &quot;&quot;&quot;
@@ -64,15 +88,17 @@ class MobileAdminMiddleware:
     &quot;&quot;&quot;
     def process_request(self, request):
         user_agent = request.META.get('HTTP_USER_AGENT', '')
+        cookie = request.COOKIES.get('mobileadmin')
+        toggle = request.GET.get('mobileadmin')
+        use_mobileadmin = True
         if 'django.contrib.admin' in settings.INSTALLED_APPS:
             try:
-                admin_url = normalize_slashes(reverse('django.contrib.admin.views.main.index'))
+                admin_url = normalize_slashes(
+                    reverse('django.contrib.admin.views.main.index'))
             except NoReverseMatch:
                 admin_url = None
-            if admin_url is not None and \
-                (safari_regex.search(user_agent) is not None or \
-                     opera_mini_regex.search(user_agent) is not None or \
-                     blackbarry_regex.search(user_agent) is not None ) and \
+            if use_mobileadmin and admin_url is not None and \
+                is_valid_user_agent(user_agent) and \
                 normalize_slashes(request.path).startswith(admin_url):
                 set_thread_var('use_mobile_templates', True)
             else:
@@ -80,6 +106,22 @@ class MobileAdminMiddleware:
             return None
 
     def process_response(self, request, response):
-        if get_thread_var('use_mobile_templates') is not None:
-            patch_vary_headers(response, ('User-Agent',))
+        try:
+            admin_url = normalize_slashes(
+                reverse('django.contrib.admin.views.main.index'))
+        except NoReverseMatch:
+            admin_url = None
+        if admin_url is None or \
+            'text/html' not in response['Content-Type'] or \
+            request.is_ajax() or \
+            response.status_code != 200:
+            return response
+        content = Template(TOGGLE_TEMPLATE).render(Context({
+            'age': COOKIE_AGE,
+            'admin_url': admin_url,
+            'secure': request.is_secure(),
+            'path': request.get_full_path(),
+        }))
+        old_content = response.content
+        response.content = force_unicode(old_content).replace('&lt;/body&gt;', content)
         return response</diff>
      <filename>mobileadmin/middleware.py</filename>
    </modified>
    <modified>
      <diff>@@ -15,7 +15,7 @@
         &lt;h1&gt;&lt;a href=&quot;{% get_admin_root %}&quot;&gt;Django&lt;/a&gt;&lt;/h1&gt;
         {% block tools %}
         {% if user.is_authenticated and user.is_staff %}
-        &lt;div class=&quot;user-tools float-right&quot;&gt;
+        &lt;div class=&quot;user-tools&quot;&gt;
             &lt;a href=&quot;{% get_admin_root %}logout/&quot;&gt;{% trans &quot;Logout&quot; %}&lt;/a&gt;
             &lt;a href=&quot;{% get_admin_root %}password_change/&quot;&gt;{% trans 'Change password' %}&lt;/a&gt;
         &lt;/div&gt;</diff>
      <filename>mobileadmin/templates/admin/base.html</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>9e84c7f252065c9680cf1ea20825210796443b54</id>
    </parent>
  </parents>
  <author>
    <name>leidel</name>
    <email>leidel@4ed3a04f-053e-0410-b24d-b35526dee1fc</email>
  </author>
  <url>http://github.com/jezdez/django-mobileadmin/commit/cd9fc6d7f228b16f555a45024339f0be6fe597a2</url>
  <id>cd9fc6d7f228b16f555a45024339f0be6fe597a2</id>
  <committed-date>2008-09-06T04:14:34-07:00</committed-date>
  <authored-date>2008-09-06T04:14:34-07:00</authored-date>
  <message>added some smaller refactorings and other changes

git-svn-id: https://django-mobileadmin.googlecode.com/svn/trunk@32 4ed3a04f-053e-0410-b24d-b35526dee1fc</message>
  <tree>045362e3edfef1cff572d4a71765dc587db293c1</tree>
  <committer>
    <name>leidel</name>
    <email>leidel@4ed3a04f-053e-0410-b24d-b35526dee1fc</email>
  </committer>
</commit>
