修复micolog的一个bug:Entry.publish函数
我错了,大家千万不要被我误导,尤其对houkai同学深表抱歉!我没有仔细看代码,随手改了一下,结果引入了bug,其实原来的基础上加了entrycount已经是正确的了,附上代码
[code lang='python' style='vs']
def publish(self,newval=True):
if newval:
if not self.is_saved():
self.save()
if not self.is_wp:
self.post_id=self.key().id()
#fix for old version
if not self.postname:
self.setpostname(self.slug)
vals={'year':self.date.year,'month':str(self.date.month).zfill(2),'day':self.date.day,
'postname':self.postname,'post_id':self.post_id}
if self.entrytype=='page':
if self.slug:
self.link=self.postname
else:
self.link='?p=%(post_id)s'%vals
else:
if self.slug:
self.link=self.slug
else:
self.link=g_blog.link_format.strip()%vals
if (not self.published) and (self.entrytype == 'post'):
g_blog.entrycount+=1
self.published=True
g_blog.save()
self.save()
else:
self.published=False
if self.published:
g_blog.entrycount-=1
g_blog.save()
self.save()
self.removecache()
if g_blog.sitemap_ping:
[/code]
唉,惨,打算不天天折腾这个了,还是开始研究mysql吧
今天发现iNove主题的page.html的三个js没有标明type,导致评论出现问题,追查问题的过程中,在测试环境中,又发现添加页面后,总是无法在主页上显示。顺手修正了这个python代码中的bug:
model.py中,Entry的publish函数,观察最前面5行,只是做了将Entry存储的功能,如果再调用publish函数之前没有设置publish状态为true,就不会降文章设置到发布状态。修正办法也简单,在那个if语句上面添加一行:
self.published = True
---------------------------------------------------------------
本站作品根据创作共同协议进行授权, 转载时请务必以超链接形式标明文章原始出处
原文地址:http://www.mirecle.com/2009/09/21/repair-micologu002639s-a-bug-entry-publish-function.html
---------------------------------------------------------------