码迷,mamicode.com
首页 > 其他好文 > 详细

解决xadmin下设置“use_bootswatch = True”无效的问题

时间:2017-09-08 13:20:05      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:node   dump   accept   except   print   esc   exception   osc   header   

环境:
python 2.7
django 1.9
xadmin采用源代码的方式引入到项目中

 

1.安装requests

pip install requests


2./xadmin/plugins/themes.py 引入requests

import requests


3.修改block_top_navmenu方法:

    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},
        ]
        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:
                    flag = False
                    if flag:
                        h = httplib2.Http()
                        resp, content = h.request("http://bootswatch.com/api/3.json", GET, ‘‘,
                                                  headers={"Accept": "application/json",
                                                           "User-Agent": self.request.META[HTTP_USER_AGENT]})
                        watch_themes = json.loads(content)[themes]
                    else:
                        content = requests.get("https://bootswatch.com/api/3.json")
                        watch_themes = json.loads(content.text)[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}))

参考网址:https://my.oschina.net/u/2396236/blog/1083251

解决xadmin下设置“use_bootswatch = True”无效的问题

标签:node   dump   accept   except   print   esc   exception   osc   header   

原文地址:http://www.cnblogs.com/draculaqk/p/7493816.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!