第三百九十七节,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打造上线标准的在线教育平台—其他插件使用说,主题本地化设置的更多相关文章

  1. 第三百九十二节,Django+Xadmin打造上线标准的在线教育平台—sql注入攻击,xss攻击,csrf攻击

    第三百九十二节,Django+Xadmin打造上线标准的在线教育平台—sql注入攻击,xss攻击,csrf攻击 sql注入攻击 也就是黑客通过表单提交的地方,在表单里输入了sql语句,就是通过SQL语 ...

  2. 第三百九十八节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署CentOS6.5系统环境设置

    第三百九十八节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署CentOS6.5系统环境设置 1.Linux安装配置 注意事项: 虚拟机网卡桥接模式 不要拨VPN 如果,网络怎么都 ...

  3. 第三百九十三节,Django+Xadmin打造上线标准的在线教育平台—Xadmin后台进阶开发配置

    第三百九十三节,Django+Xadmin打造上线标准的在线教育平台—Xadmin后台进阶开发配置 设置后台某个字段的排序规则 在当前APP里的adminx.py文件里的数据表管理器里设置 order ...

  4. 第三百八十二节,Django+Xadmin打造上线标准的在线教育平台—xadmin管理员详情页面布局,导航图标设置

    第三百八十二节,Django+Xadmin打造上线标准的在线教育平台—xadmin进阶 1.后台管理员详情页面布局 后台管理员详情页面,区块是可以拖动的,而且分为了很多个区块 这个页面的布局在xadm ...

  5. 第三百九十六节,Django+Xadmin打造上线标准的在线教育平台—其他插件使用说,自定义列表页上传插件

    第三百九十六节,Django+Xadmin打造上线标准的在线教育平台—其他插件使用说,自定义列表页上传插件 设置后台列表页面字段统计 在当前APP里的adminx.py文件里的数据表管理器里设置 ag ...

  6. 第三百九十九节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署CentOS6.5安装mysql5.6

    第三百九十九节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署CentOS6.5安装mysql5.6 1.检测系统是否已经安装过mysql或其依赖,若已装过要先将其删除,否则第4步 ...

  7. 第三百九十一节,Django+Xadmin打造上线标准的在线教育平台—404,403,500页面配置

    第三百九十一节,Django+Xadmin打造上线标准的在线教育平台—404,403,500页面配置 路由映射在全局也就是根目录里的urls.py里配置404路由映射 注意:不是写在urlpatter ...

  8. 第三百八十九节,Django+Xadmin打造上线标准的在线教育平台—列表筛选结合分页

    第三百八十九节,Django+Xadmin打造上线标准的在线教育平台—列表筛选结合分页 根据用户的筛选条件来结合分页 实现原理就是,当用户点击一个筛选条件时,通过get请求方式传参将筛选的id或者值, ...

  9. 第三百八十七节,Django+Xadmin打造上线标准的在线教育平台—网站上传资源的配置与显示

    第三百八十七节,Django+Xadmin打造上线标准的在线教育平台—网站上传资源的配置与显示 首先了解一下static静态文件与上传资源的区别,static静态文件里面一般防止的我们网站样式的文件, ...

随机推荐

  1. loj#2071. 「JSOI2016」最佳团体

    题目链接 loj#2071. 「JSOI2016」最佳团体 题解 树形dp强行01分规 代码 #include<cstdio> #include<cstring> #inclu ...

  2. Bzoj5332: [Sdoi2018]旧试题

    国际惯例的题面首先我们进行一些相对显然的数学变化.解释一下第二行的那个变形,如果一个数是ijk的因数,那么它一定能被分解成三部分分别是i,j,k的因数.我们钦定一个质数只能在三部分的一个中出现.如果一 ...

  3. 洛谷.4115.Qtree4/BZOJ.1095.[ZJOI2007]Hide捉迷藏(动态点分治 Heap)

    题目链接 洛谷 SPOJ BZOJ1095(简化版) 将每次Solve的重心root连起来,会形成一个深度为logn的树,就叫它点分树吧.. 我们对每个root维护两个东西: 它管辖的子树中所有白点到 ...

  4. 使用 SHOW STATUS 查看mysql 服务器状态信息

    在LAMP架构的网站开发过程中,有些时候我们需要了解MySQL的服务器状态信息,譬如当前MySQL启动后的运行时间,当前MySQL的客户端会话连接数,当前MySQL服务器执行的慢查询数,当前MySQL ...

  5. spring cloud:Edgware.RELEASE版本hystrix超时新坑

    升级到Edgware.RELEASE发现,zuul中不管如何设置hystrix的超时时间均不起作用,仍然是默认的1000ms.  降回低版本后正常,但是低版本的fallback方法中,又拿不到详细异常 ...

  6. nohup和disown

    Many system administrators make a practice of using GNU Screen or tmux to manage jobs running in the ...

  7. Activex控件的IObjectSafety接口问题

    我的05年做流氓插件的时候,就注意到了这个问题,只要注册表加入 类似的就可以  HKEY_CLASSES_ROOT\Component    Categories\{7DD95801-9882-11C ...

  8. android:View的setTag和getTag

    Adapter 有个getView方法,可以使用setTag把查找的view缓存起来方便多次重用 public View getView(int position, View convertView, ...

  9. 在Objective-C 中使用字符生成NSArray、NSDictionary、NSNumber

    @符号不仅可以生成字符串,还可以生成其他数据类型如NSArray.NSDictionary和NSNumber,是一种简洁快速的用法. // NSArray array = [NSArray array ...

  10. ArcGIS Pro 获得工具的个数

    import arcgisscripting import string; gp = arcgisscripting.create(9.3); ##多少个工具箱 toolboxes = gp.list ...