forked from madre/devops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobile.py
30 lines (22 loc) · 904 Bytes
/
mobile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#coding:utf-8
from xadmin.sites import site
from xadmin.views import BaseAdminPlugin, CommAdminView
class MobilePlugin(BaseAdminPlugin):
def _test_mobile(self):
try:
return self.request.META['HTTP_USER_AGENT'].find('Android') >= 0 or \
self.request.META['HTTP_USER_AGENT'].find('iPhone') >= 0
except Exception:
return False
def init_request(self, *args, **kwargs):
return self._test_mobile()
def get_context(self, context):
#context['base_template'] = 'xadmin/base_mobile.html'
context['is_mob'] = True
return context
# Media
# def get_media(self, media):
# return media + self.vendor('xadmin.mobile.css', )
def block_extrahead(self, context, nodes):
nodes.append('<script>window.__admin_ismobile__ = true;</script>')
site.register_plugin(MobilePlugin, CommAdminView)