第三百九十七节,Django+Xadmin打造上线标准的在线教育平台—其他插件使用说,主题本地化设置
第三百九十七节,Django+Xadmin打造上线标准的在线教育平台—其他插件使用说,主题本地化设置
主题设置是在xadmin\plugins\themes.py这个文件
默认xadmin是通过下面这个json文件来动态加载的。所以我们可以到它加载的json文件里下载好主题
themes.py修改方式
#coding:utf-8
from __future__ import print_function
import httplib2
from django.template import loader
from django.core.cache import cache
from django.utils import six
from django.utils.translation import ugettext as _
from xadmin.sites import site
from xadmin.models import UserSettings
from xadmin.views import BaseAdminPlugin, BaseAdminView
from xadmin.util import static, json
import six
if six.PY2:
import urllib
else:
import urllib.parse THEME_CACHE_KEY = 'xadmin_themes' class ThemePlugin(BaseAdminPlugin): enable_themes = False
# {'name': 'Blank Theme', 'description': '...', 'css': 'http://...', 'thumbnail': '...'}
user_themes = None
use_bootswatch = False
default_theme = static('xadmin/css/themes/bootstrap-xadmin.css')
bootstrap2_theme = static('xadmin/css/themes/bootstrap-theme.css') # 将主题本地化,下载好主题设置下载好的主题样式文件
Solar_theme = static("xadmin/css/themes/Solar_theme.css")
Cerulean_theme = static("xadmin/css/themes/Cerulean_theme.css")
Cosmo_theme = static("xadmin/css/themes/Cosmo_theme.css")
Cyborg_theme = static("xadmin/css/themes/Cyborg_theme.css")
Darkly_theme = static("xadmin/css/themes/Darkly_theme.css")
Flatly_theme = static("xadmin/css/themes/Flatly_theme.css")
Journal_theme = static("xadmin/css/themes/Journal_theme.css")
Lumen_theme = static("xadmin/css/themes/Lumen_theme.css")
Paper_theme = static("xadmin/css/themes/Paper_theme.css")
Readable_theme = static("xadmin/css/themes/Readable_theme.css")
Sandstone_theme = static("xadmin/css/themes/Sandstone_theme.css")
Simplex_theme = static("xadmin/css/themes/Simplex_theme.css")
Slate_theme = static("xadmin/css/themes/Slate_theme.css")
Spacelab_theme = static("xadmin/css/themes/Spacelab_theme.css")
Superhero_theme = static("xadmin/css/themes/Superhero_theme.css")
United_theme = static("xadmin/css/themes/United_theme.css") def init_request(self, *args, **kwargs):
return self.enable_themes def _get_theme(self):
if self.user:
try:
return UserSettings.objects.get(user=self.user, key="site-theme").value
except Exception:
pass
if '_theme' in self.request.COOKIES:
if six.PY2:
func = urllib.unquote
else:
func = urllib.parse.unquote
return func(self.request.COOKIES['_theme'])
return self.default_theme def get_context(self, context):
context['site_theme'] = self._get_theme()
return context # Media
def get_media(self, media):
return media + self.vendor('jquery-ui-effect.js', 'xadmin.plugin.themes.js') # Block Views
def block_top_navmenu(self, context, nodes): themes = [
{'name': _(u"Default"), 'description': _(u"Default bootstrap theme"), 'css': self.default_theme},
# {'name': _(u"Bootstrap2"), 'description': _(u"Bootstrap 2.x theme"), 'css': self.bootstrap2_theme}, # 设置主题静态加载样式
{'name': _(u"深绿"), 'description': _(u"深绿"), 'css': self.Solar_theme},
{'name': _(u"天蓝"), 'description': _(u"天蓝"), 'css': self.Cerulean_theme},
{'name': _(u"蓝黑"), 'description': _(u"蓝黑"), 'css': self.Cosmo_theme},
{'name': _(u"黑色"), 'description': _(u"黑色"), 'css': self.Cyborg_theme},
{'name': _(u"绿黑"), 'description': _(u"绿黑"), 'css': self.Darkly_theme},
{'name': _(u"绿蓝"), 'description': _(u"绿蓝"), 'css': self.Flatly_theme},
{'name': _(u"粉红"), 'description': _(u"粉红"), 'css': self.Journal_theme},
{'name': _(u"白色"), 'description': _(u"白色"), 'css': self.Lumen_theme},
{'name': _(u"深蓝"), 'description': _(u"深蓝"), 'css': self.Paper_theme},
{'name': _(u"白蓝"), 'description': _(u"白蓝"), 'css': self.Readable_theme},
{'name': _(u"草绿"), 'description': _(u"草绿"), 'css': self.Sandstone_theme},
{'name': _(u"红色"), 'description': _(u"红色"), 'css': self.Simplex_theme},
{'name': _(u"灰黑"), 'description': _(u"灰黑"), 'css': self.Slate_theme},
{'name': _(u"灰蓝"), 'description': _(u"灰蓝"), 'css': self.Spacelab_theme},
{'name': _(u"深灰"), 'description': _(u"深灰"), 'css': self.Superhero_theme},
{'name': _(u"橙色"), 'description': _(u"橙色"), 'css': self.United_theme},
] select_css = context.get('site_theme', self.default_theme) if self.user_themes:
themes.extend(self.user_themes) if self.use_bootswatch:
ex_themes = cache.get(THEME_CACHE_KEY)
if ex_themes:
themes.extend(json.loads(ex_themes))
else:
ex_themes = []
try:
pass # 默认xadmin是通过下面这个json文件来动态加载的,将它注释掉将不会动态加载主题 # h = httplib2.Http()
# resp, content = h.request("https://bootswatch.com/api/3.json", 'GET', '',
# headers={"Accept": "application/json", "User-Agent": self.request.META['HTTP_USER_AGENT']})
# if six.PY3:
# content = content.decode()
# watch_themes = json.loads(content)['themes']
# ex_themes.extend([
# {'name': t['name'], 'description': t['description'],
# 'css': t['cssMin'], 'thumbnail': t['thumbnail']}
# for t in watch_themes])
except Exception as e:
print(e) cache.set(THEME_CACHE_KEY, json.dumps(ex_themes), 24 * 3600)
themes.extend(ex_themes) nodes.append(loader.render_to_string('xadmin/blocks/comm.top.theme.html', {'themes': themes, 'select_css': select_css})) site.register_plugin(ThemePlugin, BaseAdminView)
第三百九十七节,Django+Xadmin打造上线标准的在线教育平台—其他插件使用说,主题本地化设置的更多相关文章
- 第三百九十二节,Django+Xadmin打造上线标准的在线教育平台—sql注入攻击,xss攻击,csrf攻击
第三百九十二节,Django+Xadmin打造上线标准的在线教育平台—sql注入攻击,xss攻击,csrf攻击 sql注入攻击 也就是黑客通过表单提交的地方,在表单里输入了sql语句,就是通过SQL语 ...
- 第三百九十八节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署CentOS6.5系统环境设置
第三百九十八节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署CentOS6.5系统环境设置 1.Linux安装配置 注意事项: 虚拟机网卡桥接模式 不要拨VPN 如果,网络怎么都 ...
- 第三百九十三节,Django+Xadmin打造上线标准的在线教育平台—Xadmin后台进阶开发配置
第三百九十三节,Django+Xadmin打造上线标准的在线教育平台—Xadmin后台进阶开发配置 设置后台某个字段的排序规则 在当前APP里的adminx.py文件里的数据表管理器里设置 order ...
- 第三百八十二节,Django+Xadmin打造上线标准的在线教育平台—xadmin管理员详情页面布局,导航图标设置
第三百八十二节,Django+Xadmin打造上线标准的在线教育平台—xadmin进阶 1.后台管理员详情页面布局 后台管理员详情页面,区块是可以拖动的,而且分为了很多个区块 这个页面的布局在xadm ...
- 第三百九十六节,Django+Xadmin打造上线标准的在线教育平台—其他插件使用说,自定义列表页上传插件
第三百九十六节,Django+Xadmin打造上线标准的在线教育平台—其他插件使用说,自定义列表页上传插件 设置后台列表页面字段统计 在当前APP里的adminx.py文件里的数据表管理器里设置 ag ...
- 第三百九十九节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署CentOS6.5安装mysql5.6
第三百九十九节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署CentOS6.5安装mysql5.6 1.检测系统是否已经安装过mysql或其依赖,若已装过要先将其删除,否则第4步 ...
- 第三百九十一节,Django+Xadmin打造上线标准的在线教育平台—404,403,500页面配置
第三百九十一节,Django+Xadmin打造上线标准的在线教育平台—404,403,500页面配置 路由映射在全局也就是根目录里的urls.py里配置404路由映射 注意:不是写在urlpatter ...
- 第三百八十九节,Django+Xadmin打造上线标准的在线教育平台—列表筛选结合分页
第三百八十九节,Django+Xadmin打造上线标准的在线教育平台—列表筛选结合分页 根据用户的筛选条件来结合分页 实现原理就是,当用户点击一个筛选条件时,通过get请求方式传参将筛选的id或者值, ...
- 第三百八十七节,Django+Xadmin打造上线标准的在线教育平台—网站上传资源的配置与显示
第三百八十七节,Django+Xadmin打造上线标准的在线教育平台—网站上传资源的配置与显示 首先了解一下static静态文件与上传资源的区别,static静态文件里面一般防止的我们网站样式的文件, ...
随机推荐
- Python3练习题系列(08)——代码阅读方法及字典跳转表理解
问题:分析下面代码 cities['_find'] = find_city city_found = cities['_find'](cities, state) 分析过程: 一个函数也可以作为一个变 ...
- C++ 指针悬挂和赋值操作符的重载,拷贝构造函数实现
指针悬挂: 问题:使用new申请的内存内存空间无法访问,也无法释放. 原因:直接对指向new申请的存储空间的指针变量进行赋值修改 后果:失去了原来的地址,原来的空间无法访问也无法释放,造成内存泄漏 还 ...
- fatal error C1083: 无法打开编译器生成的文件:“../../build/vs71/release/lib_json\json_value.asm”: No such file or directory
修改生成静态库文件的工程的属性:路径为:菜单---项目--属性---配置属性---c/c++---输出文件---汇编程序输出:无列表
- 通过html页面打开Android本地的app
http://www.cnblogs.com/yejiurui/p/3413796.html 一.通过html页面打开Android本地的app 1.首先在编写一个简单的html页面 <html ...
- pkg-config命令的Makefile.am
举例:通过Makefile调用pkg-config命令. pkg-config - Return metainformation about installed libraries (为了使用lib库 ...
- IOPS计算
Device Type IOPS 7,200 rpm SATA drives HDD ~75-100 IOPS[2] 10,000 rpm SATA drives HDD ~125-150 IOPS[ ...
- Quality of Service 0, 1 & 2
来自:http://www.hivemq.com/blog/mqtt-essentials-part-6-mqtt-quality-of-service-levels Quality of Servi ...
- Ubuntu18.04的网络管理netplan和防火墙ufw
Netplan Ubuntu18.04使用的网络管理是netplan, 配置文件在/etc/netplan/下 刚安装完成的配置是这样的 刚安装完成的配置是这样的 network: ethernets ...
- ASIHttpRequest请求HTTPS
一种方法 ASIHTTPRequest *request = [ASIHTTPRequestrequestWithURL:[NSURLURLWithString:bodyString]]; [requ ...
- logstash数据处理示例
#test {"time":1504752032399,"date":"2017-09-08 12:00:00","str&quo ...