mobile.py 904 B

123456789101112131415161718192021222324252627282930
  1. #coding:utf-8
  2. from xadmin.sites import site
  3. from xadmin.views import BaseAdminPlugin, CommAdminView
  4. class MobilePlugin(BaseAdminPlugin):
  5. def _test_mobile(self):
  6. try:
  7. return self.request.META['HTTP_USER_AGENT'].find('Android') >= 0 or \
  8. self.request.META['HTTP_USER_AGENT'].find('iPhone') >= 0
  9. except Exception:
  10. return False
  11. def init_request(self, *args, **kwargs):
  12. return self._test_mobile()
  13. def get_context(self, context):
  14. #context['base_template'] = 'xadmin/base_mobile.html'
  15. context['is_mob'] = True
  16. return context
  17. # Media
  18. # def get_media(self, media):
  19. # return media + self.vendor('xadmin.mobile.css', )
  20. def block_extrahead(self, context, nodes):
  21. nodes.append('<script>window.__admin_ismobile__ = true;</script>')
  22. site.register_plugin(MobilePlugin, CommAdminView)