V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
akira
V2EX  ›  Project Babel

对于创建节点还要设category的方式无法接受,自行修改吧

  •  
  •   akira · 2010-11-20 00:28:16 +08:00 · 5675 次点击
    这是一个创建于 4877 天前的主题,其中的信息可能已经有所发展或是发生改变。
    其实就是加几句,减几句。修改好以后,创建好的node会自动在首页导航里面出现了。不过因为没加cache,效率上会很差。

    backstage.py
    @@ -1076,6 +1076,7 @@ class BackstageNewNodeHandler(webapp.RequestHandler):
    1076 1076 node.name = node_name
    1077 1077 node.title = node_title
    1078 1078 node.title_alternative = node_title_alternative
    1079 + node.category = section_name
    1079 1080 node.put()

    main.py
    @@ -185,14 +185,11 @@ class HomeHandler(webapp.RequestHandler):
    185 185 if c is None:
    186 186 c = ''
    187 187 i = 0
    188 - if site.home_categories is not None:
    189 - categories = site.home_categories.split("\n")
    190 - else:
    191 - categories = []
    192 - for category in categories:
    193 - category = category.strip()
    188 + categoriesdb = db.GqlQuery("SELECT * FROM Section")
    189 + for cate in categoriesdb:
    190 + category = cate.name.strip()
    194 191 i = i + 1
    195 - if i == len(categories):
    192 + if i == categoriesdb.count():
    196 193 css_class = 'inner'
    197 194 else:
    198 195 css_class = 'cell'
    3 条回复    1970-01-01 08:00:00 +08:00
    chone
        1
    chone  
       2010-11-20 00:33:51 +08:00
    何必这样呢,创建以后手动的删除一下缓存就可以了。

    后台有相应功能的,为这个去掉缓存没意义
    akira
        2
    akira  
    OP
       2010-11-20 00:40:26 +08:00
    @chone 这个不是为了缓存,而是为了使新用户在开始的时候跟容易上手啦。

    再看了下代码,原来livid加的缓存代码功能对这部分也有起作用的。。所以不用我另外处理啦 :lol
    另外,在main.py里面添加一下代码,那么我们就可以直接通过调用xxx.appspot.com/flush来清除缓存了。后面里面那个清除功能反正我没搞懂怎么用。

    +class FlushHandler(webapp.RequestHandler):
    + def get(self):
    + memcache.flush_all()
    + self.redirect('/')
    +
    def main():
    application = webapp.WSGIApplication([
    ('/', HomeHandler),
    + ('/flush', FlushHandler),
    ('/recent', RecentHandler),
    chone
        3
    chone  
       2010-11-20 01:17:21 +08:00
    index_categories

    http://img.ly/2sPx
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4362 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 10:11 · PVG 18:11 · LAX 03:11 · JFK 06:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.