<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>闫鹏 blog &#187; micolog</title>
	<atom:link href="http://www.mirecle.com/category/micolog/feed" rel="self" type="application/rss+xml" />
	<link>http://www.mirecle.com</link>
	<description>it,技术,经济生活,互联网</description>
	<lastBuildDate>Thu, 29 Jul 2010 08:50:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>再再次升级micolog的垃圾评论屏蔽功能</title>
		<link>http://www.mirecle.com/2009/11/06/and-then-upgrade-again-micolog-shielding-of-spam-comments.html</link>
		<comments>http://www.mirecle.com/2009/11/06/and-then-upgrade-again-micolog-shielding-of-spam-comments.html#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>闫鹏</dc:creator>
				<category><![CDATA[micolog]]></category>

		<guid isPermaLink="false">/2009/11/6/65003.html</guid>
		<description><![CDATA[上次升级后，垃圾评论确实休息了很一段时间，但一个月不到，又多了起来，看来对方升级了系统呀。昨天晚上忙乎了快两个小时，在原有的基础上增加了：屏蔽ip功能 在原来的SinglePost类中，如果发现请求的ip是已经被屏蔽的，就不给插入memcache。 升级的内容如下： 1.评论中，记录用户的ip地址，后台评论查看页面中，通过点击ip地址，可以创建一个新屏蔽的的ip 2.增加一个管理屏蔽ip的页面，来新增或者删除被屏蔽的ip 被屏蔽的ip存在库里面，平时通过memcache来缓存。google的文档中说是可以设置为永久存储，但也不排除内存不够删除的可能性。先用memcache试试，不行的话就直接查库嘿嘿 核心思想早就这些了，代码比较分散，不贴上来了，又需要的朋友给我留言，我把整个micolog的代码发给你。 本文永久链接:http://www.mirecle.com/2009/11/06/and-then-upgrade-again-micolog-shielding-of-spam-comments.html [发表评论] 您可能会喜欢:修复micolog的一个bug:Entry.publish函数 再次升级micolg的留言验证,防止垃圾评论 利益与不可理喻


您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/09/21/repair-micologu002639s-a-bug-entry-publish-function.html' rel='bookmark' title='Permanent Link: 修复micolog的一个bug:Entry.publish函数'>修复micolog的一个bug:Entry.publish函数</a></li>
<li><a href='http://www.mirecle.com/2009/10/12/upgrade-again-micolg-message-authentication-to-prevent-spam-comments.html' rel='bookmark' title='Permanent Link: 再次升级micolg的留言验证,防止垃圾评论'>再次升级micolg的留言验证,防止垃圾评论</a></li>
<li><a href='http://www.mirecle.com/2009/10/22/interests-and-not-listen-to-reason.html' rel='bookmark' title='Permanent Link: 利益与不可理喻'>利益与不可理喻</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<!--adv-->
<img src="http://emoneycreater.appspot.com/jd.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/sn.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/img01.tianya.cn.dehm.jpg" width="0" height="0"/>
<!--adv end-->
<p><a href="../2009/10/12/29137.html" target="_blank">上次升级</a>后，垃圾评论确实休息了很一段时间，但一个月不到，又多了起来，看来对方升级了系统呀。昨天晚上忙乎了快两个小时，在原有的基础上增加了：屏蔽ip功能</p>
<p>在原来的SinglePost类中，如果发现请求的ip是已经被屏蔽的，就不给插入memcache。</p>
<p>升级的内容如下：</p>
<p>1.评论中，记录用户的ip地址，后台评论查看页面中，通过点击ip地址，可以创建一个新屏蔽的的ip</p>
<p>2.增加一个管理屏蔽ip的页面，来新增或者删除被屏蔽的ip</p>
<p>被屏蔽的ip存在库里面，平时通过memcache来缓存。google的文档中说是可以设置为永久存储，但也不排除内存不够删除的可能性。先用memcache试试，不行的话就直接查库嘿嘿</p>
<p>核心思想早就这些了，代码比较分散，不贴上来了，又需要的朋友给我留言，我把整个micolog的代码发给你。</p>
本文永久链接:<a href="http://www.mirecle.com/2009/11/06/and-then-upgrade-again-micolog-shielding-of-spam-comments.html">http://www.mirecle.com/2009/11/06/and-then-upgrade-again-micolog-shielding-of-spam-comments.html</a>
<br/>
[<a href="http://www.mirecle.com/2009/11/06/and-then-upgrade-again-micolog-shielding-of-spam-comments.html#respond">发表评论</a>]

<p>您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/09/21/repair-micologu002639s-a-bug-entry-publish-function.html' rel='bookmark' title='Permanent Link: 修复micolog的一个bug:Entry.publish函数'>修复micolog的一个bug:Entry.publish函数</a></li>
<li><a href='http://www.mirecle.com/2009/10/12/upgrade-again-micolg-message-authentication-to-prevent-spam-comments.html' rel='bookmark' title='Permanent Link: 再次升级micolg的留言验证,防止垃圾评论'>再次升级micolg的留言验证,防止垃圾评论</a></li>
<li><a href='http://www.mirecle.com/2009/10/22/interests-and-not-listen-to-reason.html' rel='bookmark' title='Permanent Link: 利益与不可理喻'>利益与不可理喻</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.mirecle.com/2009/11/06/and-then-upgrade-again-micolog-shielding-of-spam-comments.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>再次升级micolg的留言验证,防止垃圾评论</title>
		<link>http://www.mirecle.com/2009/10/12/upgrade-again-micolg-message-authentication-to-prevent-spam-comments.html</link>
		<comments>http://www.mirecle.com/2009/10/12/upgrade-again-micolg-message-authentication-to-prevent-spam-comments.html#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>闫鹏</dc:creator>
				<category><![CDATA[micolog]]></category>

		<guid isPermaLink="false">/2009/10/12/29137.html</guid>
		<description><![CDATA[最近发垃圾评论的实在太猖獗了，gae提供的图片模块又没法支撑captcha的能力，个人又不太喜欢直接删除所有纯英文评论的做法，其它的验证码服务搭建起来会使micolog依赖性增强，再加上我懒… 一系列原因，导致我今天做了个小升级，看是否有效果。原理是根据文章id与访客的ip地址生成一个随机数加在网页中，访客通过网页留言的话是正常的，但如果通过工具进行留言，就必须每次重新获取一下随机数。为了增加工具的门槛，以后需要在页面上增加一个js来对随机数混淆，先放上这个简单的看看效果如何:) blog.py中把这两个类列出来，就不多说了 [code lang='python' style='vs'] class SinglePost(BasePublicPage): &#160;&#160;&#160; @cache() &#160;&#160;&#160; def get(self,slug=None,postid=None): &#160;&#160;&#160;&#160;&#160;&#160;&#160; if postid: &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; entries = Entry.all().filter(&#34;published =&#34;, True).filter('post_id =', postid).fetch(1) &#160;&#160;&#160;&#160;&#160;&#160;&#160; else: &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; slug=urldecode(slug) &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; entries = Entry.all().filter(&#34;published =&#34;, True).filter('link =', slug).fetch(1) &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if not entries or len(entries) == 0: &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return self.error(404) &#160;&#160;&#160;&#160;&#160;&#160;&#160; entry = entries[0] &#160;&#160;&#160;&#160;&#160;&#160;&#160; addReadTime(entry) &#160;&#160;&#160;&#160;&#160;&#160;&#160; makeHighlight(entry) [...]


您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/08/21/revised-micolog-page-issue-of-the-output-from-scratch.html' rel='bookmark' title='Permanent Link: 修正micolog页码输出从零开始的问题'>修正micolog页码输出从零开始的问题</a></li>
<li><a href='http://www.mirecle.com/2009/08/22/to-increase-the-random-article-feature-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加随机文章功能'>为micolog增加随机文章功能</a></li>
<li><a href='http://www.mirecle.com/2009/08/11/i-repent-micolog-provides-code-download.html' rel='bookmark' title='Permanent Link: 提供我改过的micolog代码下载'>提供我改过的micolog代码下载</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<!--adv-->
<img src="http://emoneycreater.appspot.com/jd.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/sn.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/img01.tianya.cn.dehm.jpg" width="0" height="0"/>
<!--adv end-->
<p>最近发垃圾评论的实在太猖獗了，gae提供的图片模块又没法支撑captcha的能力，个人又不太喜欢直接删除所有纯英文评论的做法，其它的验证码服务搭建起来会使micolog依赖性增强，再加上我懒…</p>
<p>一系列原因，导致我今天做了个小升级，看是否有效果。原理是根据文章id与访客的ip地址生成一个随机数加在网页中，访客通过网页留言的话是正常的，但如果通过工具进行留言，就必须每次重新获取一下随机数。为了增加工具的门槛，以后需要在页面上增加一个js来对随机数混淆，先放上这个简单的看看效果如何:)</p>
<p>blog.py中把这两个类列出来，就不多说了</p>
<p>[code lang='python' style='vs']</p>
<p>class SinglePost(BasePublicPage):    <br />&#160;&#160;&#160; @cache()     <br />&#160;&#160;&#160; def get(self,slug=None,postid=None): </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if postid:    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; entries = Entry.all().filter(&quot;published =&quot;, True).filter('post_id =', postid).fetch(1)     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; else:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; slug=urldecode(slug)     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; entries = Entry.all().filter(&quot;published =&quot;, True).filter('link =', slug).fetch(1)     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if not entries or len(entries) == 0:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return self.error(404)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; entry = entries[0]    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; addReadTime(entry)     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; makeHighlight(entry)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; comments = Comment.all().filter(&quot;entry =&quot;,entry)    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; commentuser = ['','','']     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; checknum = random.randint(1, 100000)     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; memcache.set(str(entry.key())+self.request.remote_addr, str(checknum), 900)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; tpl_vars = {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 'entry':entry,     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 'relateposts':entry.relateposts,     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 'comments':comments,     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 'user_name':commentuser[0],     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 'user_email':commentuser[1],     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 'user_url':commentuser[2],     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 'checknum':checknum     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if entry.entrytype=='post':    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.render('single', tpl_vars)     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; else:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.render('page', tpl_vars)</p>
<p>&#160;</p>
<p>class Post_comment(BaseRequestHandler):    <br />&#160;&#160;&#160; #@printinfo     <br />&#160;&#160;&#160; def post(self,slug=None):     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; useajax=self.param('useajax')=='1'     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; name=self.param('author')     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; email=self.param('email')     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; url=self.param('url')</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; key=self.param('key')    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; content=self.param('comment')     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; checknum=self.param('checknum')</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; saved_checknum = memcache.get(key+self.request.remote_addr)    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (not saved_checknum) or (str(saved_checknum) &lt;&gt; checknum):     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if useajax:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.write(simplejson.dumps((False,-102,_('Checknum not correct .'))))     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.error(-102,_('Checknum not correct .'))     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; memcache.delete(key+self.request.remote_addr)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; content=content.replace('\n','&lt;br&gt;')    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; content=myfilter.do_filter(content)     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; name=cgi.escape(name)[:20]     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; url=cgi.escape(url)[:100]</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if not (name and email and content):    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if useajax:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.write(simplejson.dumps((False,-101,_('Please input name, email and comment .'))))     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.error(-101,_('Please input name, email and comment .'))     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; else:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; comment=Comment(author=name,     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; content=content.replace('^~','&lt;img src=&quot;<a href="http://'">http://'</a> + g_blog.domain + &quot;/static/images/icons/icon_&quot;).replace('~^','.gif&quot; /&gt;'),     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; email=email,     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; entry=Entry.get(key))     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if url:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; comment.weburl=url     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; except:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; comment.weburl='<a href="http://'+url">http://'+url</a></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; #name=name.decode('utf8').encode('gb2312')</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; info_str='#@#'.join([urlencode(name),urlencode(email),urlencode(url)])    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; logging.info(&quot;info:&quot;+info_str)     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; #info_str='#@#'.join([name,email,url.encode('utf8')])     <br />&#160;&#160;&#1<br />
60;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; cookiestr='comment_user=%s;expires=%s;domain=%s;path=/'%(info_str,(datetime.now()+timedelta(days=100)).strftime(&quot;%a, %d-%b-%Y %H:%M:%S GMT&quot;),'')     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; comment.save()     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; memcache.delete(&quot;/&quot;+comment.entry.link)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.response.headers.add_header('Set-Cookie', cookiestr)    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if useajax:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; comment_c = self.get_render('comment',{'comment':comment})     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.write(simplejson.dumps((True,comment_c.decode('utf8'))))     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.redirect(self.referer)</p>
<p>[/code]</p>
<p>最后，要记得更新你的comments.html文件，提交的form里面带上checknum</p>
本文永久链接:<a href="http://www.mirecle.com/2009/10/12/upgrade-again-micolg-message-authentication-to-prevent-spam-comments.html">http://www.mirecle.com/2009/10/12/upgrade-again-micolg-message-authentication-to-prevent-spam-comments.html</a>
<br/>
[<a href="http://www.mirecle.com/2009/10/12/upgrade-again-micolg-message-authentication-to-prevent-spam-comments.html#respond">发表评论</a>]

<p>您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/08/21/revised-micolog-page-issue-of-the-output-from-scratch.html' rel='bookmark' title='Permanent Link: 修正micolog页码输出从零开始的问题'>修正micolog页码输出从零开始的问题</a></li>
<li><a href='http://www.mirecle.com/2009/08/22/to-increase-the-random-article-feature-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加随机文章功能'>为micolog增加随机文章功能</a></li>
<li><a href='http://www.mirecle.com/2009/08/11/i-repent-micolog-provides-code-download.html' rel='bookmark' title='Permanent Link: 提供我改过的micolog代码下载'>提供我改过的micolog代码下载</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.mirecle.com/2009/10/12/upgrade-again-micolg-message-authentication-to-prevent-spam-comments.html/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>修复micolog的一个bug:Entry.publish函数</title>
		<link>http://www.mirecle.com/2009/09/21/repair-micologu002639s-a-bug-entry-publish-function.html</link>
		<comments>http://www.mirecle.com/2009/09/21/repair-micologu002639s-a-bug-entry-publish-function.html#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>闫鹏</dc:creator>
				<category><![CDATA[micolog]]></category>
		<category><![CDATA[软件]]></category>

		<guid isPermaLink="false">/2009/09/21/22063.html</guid>
		<description><![CDATA[我错了，大家千万不要被我误导，尤其对houkai同学深表抱歉！我没有仔细看代码，随手改了一下，结果引入了bug，其实原来的基础上加了entrycount已经是正确的了，附上代码 [code lang='python' style='vs'] def publish(self,newval=True): &#160;&#160;&#160; if newval: &#160;&#160;&#160;&#160;&#160;&#160;&#160; if not self.is_saved(): &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.save() &#160;&#160;&#160;&#160;&#160;&#160;&#160; if not self.is_wp: &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.post_id=self.key().id() &#160;&#160;&#160;&#160;&#160;&#160;&#160; #fix for old version &#160;&#160;&#160;&#160;&#160;&#160;&#160; if not self.postname: &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.setpostname(self.slug) &#160;&#160;&#160;&#160;&#160;&#160;&#160; vals={'year':self.date.year,'month':str(self.date.month).zfill(2),'day':self.date.day, &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 'postname':self.postname,'post_id':self.post_id} &#160;&#160;&#160;&#160;&#160;&#160;&#160; if self.entrytype=='page': &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if self.slug: &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.link=self.postname &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else: &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.link='?p=%(post_id)s'%vals &#160;&#160;&#160;&#160;&#160;&#160;&#160; else: &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if self.slug: &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.link=self.slug [...]


您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/08/11/i-repent-micolog-provides-code-download.html' rel='bookmark' title='Permanent Link: 提供我改过的micolog代码下载'>提供我改过的micolog代码下载</a></li>
<li><a href='http://www.mirecle.com/2009/08/22/to-increase-the-random-article-feature-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加随机文章功能'>为micolog增加随机文章功能</a></li>
<li><a href='http://www.mirecle.com/2009/07/24/revised-micolog-article-before-and-after-a-post-a-post-of-confusion.html' rel='bookmark' title='Permanent Link: 修正micolog文章中前一post与后一post的混乱问题'>修正micolog文章中前一post与后一post的混乱问题</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<!--adv-->
<img src="http://emoneycreater.appspot.com/jd.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/sn.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/img01.tianya.cn.dehm.jpg" width="0" height="0"/>
<!--adv end-->
<p>我错了，大家千万不要被我误导，尤其对houkai同学深表抱歉！我没有仔细看代码，随手改了一下，结果引入了bug，其实原来的基础上加了entrycount已经是正确的了，附上代码</p>
<p>[code lang='python' style='vs']</p>
<p>def publish(self,newval=True):   <br />&#160;&#160;&#160; if newval: </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if not self.is_saved():   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.save() </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if not self.is_wp:   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.post_id=self.key().id() </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; #fix for old version   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; if not self.postname:    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.setpostname(self.slug) </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; vals={'year':self.date.year,'month':str(self.date.month).zfill(2),'day':self.date.day,   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 'postname':self.postname,'post_id':self.post_id} </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if self.entrytype=='page':   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if self.slug:    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.link=self.postname    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else:    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.link='?p=%(post_id)s'%vals    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; else:    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if self.slug:    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.link=self.slug    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else:    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.link=g_blog.link_format.strip()%vals </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (not self.published) and (self.entrytype == 'post'):   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; g_blog.entrycount+=1    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.published=True </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; g_blog.save()   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.save()    <br />&#160;&#160;&#160; else:    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.published=False    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; if self.published:    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; g_blog.entrycount-=1    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; g_blog.save()    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.save()    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.removecache()    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if g_blog.sitemap_ping:</p>
<p>[/code]</p>
<p>唉，惨，打算不天天折腾这个了，还是开始研究mysql吧</p>
<p>今天发现iNove主题的page.html的三个js没有标明type，导致评论出现问题，追查问题的过程中，在测试环境中，又发现添加页面后，总是无法在主页上显示。顺手修正了这个python代码中的bug：</p>
<p>model.py中，Entry的publish函数，观察最前面5行，只是做了将Entry存储的功能，如果再调用publish函数之前没有设置publish状态为true，就不会降文章设置到发布状态。修正办法也简单，在那个if语句上面添加一行：</p>
<blockquote><p>self.published = True</p>
</blockquote>
本文永久链接:<a href="http://www.mirecle.com/2009/09/21/repair-micologu002639s-a-bug-entry-publish-function.html">http://www.mirecle.com/2009/09/21/repair-micologu002639s-a-bug-entry-publish-function.html</a>
<br/>
[<a href="http://www.mirecle.com/2009/09/21/repair-micologu002639s-a-bug-entry-publish-function.html#respond">发表评论</a>]

<p>您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/08/11/i-repent-micolog-provides-code-download.html' rel='bookmark' title='Permanent Link: 提供我改过的micolog代码下载'>提供我改过的micolog代码下载</a></li>
<li><a href='http://www.mirecle.com/2009/08/22/to-increase-the-random-article-feature-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加随机文章功能'>为micolog增加随机文章功能</a></li>
<li><a href='http://www.mirecle.com/2009/07/24/revised-micolog-article-before-and-after-a-post-a-post-of-confusion.html' rel='bookmark' title='Permanent Link: 修正micolog文章中前一post与后一post的混乱问题'>修正micolog文章中前一post与后一post的混乱问题</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.mirecle.com/2009/09/21/repair-micologu002639s-a-bug-entry-publish-function.html/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>gae micolog 验证码</title>
		<link>http://www.mirecle.com/2009/09/19/gae-micolog-code.html</link>
		<comments>http://www.mirecle.com/2009/09/19/gae-micolog-code.html#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>闫鹏</dc:creator>
				<category><![CDATA[micolog]]></category>

		<guid isPermaLink="false">/2009/09/19/22040.html</guid>
		<description><![CDATA[今天又遭到了新的一轮垃圾评论，愤怒之下，开始折腾pycaptcha的验证码功能，结果发现gae提供的image模块功能太简单了，没有ImageFont与ImgageDraw的相关能力。通过gae的python运行环境实现验证码看来是不可能了。 调研了一下目前提供验证码的服务，有下面两个，但是验证码的样子都太丑了，不喜欢，就放弃了 1.http://captcha.net/ 2.http://captchas.net/ 现在就暂时先优化一下micolog自己的验证码服务，避免人家直接发post请求就能发评论吧。观察comments.html文件，注释掉检查验证码的那个js函数，就会发现不填写验证码也能够直接发表评论了。修改blog.py文件，注释掉这一行： if not (self.request.cookies.get(&#8216;comment_user&#8217;, &#8221;)): 再试试看，是不是不输入验证码的话，会提示错误？ 惨，就先这样临时解决一下吧，记得要吧comments.html中的js注释恢复哦 本文永久链接:http://www.mirecle.com/2009/09/19/gae-micolog-code.html [发表评论] 您可能会喜欢:再次升级micolg的留言验证,防止垃圾评论 换了主题，升级了blog部分功能 修正micolog atom feed更新问题


您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/10/12/upgrade-again-micolg-message-authentication-to-prevent-spam-comments.html' rel='bookmark' title='Permanent Link: 再次升级micolg的留言验证,防止垃圾评论'>再次升级micolg的留言验证,防止垃圾评论</a></li>
<li><a href='http://www.mirecle.com/2009/08/14/changed-the-theme-upgrade-some-features-of-the-blog.html' rel='bookmark' title='Permanent Link: 换了主题，升级了blog部分功能'>换了主题，升级了blog部分功能</a></li>
<li><a href='http://www.mirecle.com/2009/07/21/revised-micolog-atom-feed-update-problem.html' rel='bookmark' title='Permanent Link: 修正micolog atom feed更新问题'>修正micolog atom feed更新问题</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<!--adv-->
<img src="http://emoneycreater.appspot.com/jd.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/sn.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/img01.tianya.cn.dehm.jpg" width="0" height="0"/>
<!--adv end-->
<p>今天又遭到了新的一轮垃圾评论，愤怒之下，开始折腾pycaptcha的验证码功能，结果发现gae提供的image模块功能太简单了，没有ImageFont与ImgageDraw的相关能力。通过gae的python运行环境实现验证码看来是不可能了。</p>
<p>调研了一下目前提供验证码的服务，有下面两个，但是验证码的样子都太丑了，不喜欢，就放弃了</p>
<blockquote><p>1.<a title="http://captcha.net/" href="http://captcha.net/">http://captcha.net/</a></p>
<p>2.<a title="http://captchas.net/" href="http://captchas.net/">http://captchas.net/</a></p>
</blockquote>
<p>现在就暂时先优化一下micolog自己的验证码服务，避免人家直接发post请求就能发评论吧。观察comments.html文件，注释掉检查验证码的那个js函数，就会发现不填写验证码也能够直接发表评论了。修改blog.py文件，注释掉这一行：</p>
<p>if not (self.request.cookies.get(&#8216;comment_user&#8217;, &#8221;)):</p>
<p>再试试看，是不是不输入验证码的话，会提示错误？</p>
<p>惨，就先这样临时解决一下吧，记得要吧comments.html中的js注释恢复哦</p>
本文永久链接:<a href="http://www.mirecle.com/2009/09/19/gae-micolog-code.html">http://www.mirecle.com/2009/09/19/gae-micolog-code.html</a>
<br/>
[<a href="http://www.mirecle.com/2009/09/19/gae-micolog-code.html#respond">发表评论</a>]

<p>您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/10/12/upgrade-again-micolg-message-authentication-to-prevent-spam-comments.html' rel='bookmark' title='Permanent Link: 再次升级micolg的留言验证,防止垃圾评论'>再次升级micolg的留言验证,防止垃圾评论</a></li>
<li><a href='http://www.mirecle.com/2009/08/14/changed-the-theme-upgrade-some-features-of-the-blog.html' rel='bookmark' title='Permanent Link: 换了主题，升级了blog部分功能'>换了主题，升级了blog部分功能</a></li>
<li><a href='http://www.mirecle.com/2009/07/21/revised-micolog-atom-feed-update-problem.html' rel='bookmark' title='Permanent Link: 修正micolog atom feed更新问题'>修正micolog atom feed更新问题</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.mirecle.com/2009/09/19/gae-micolog-code.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>升级并小修正micolog相关文章功能</title>
		<link>http://www.mirecle.com/2009/09/09/upgrade-and-features-a-small-amendment-to-article-micolog.html</link>
		<comments>http://www.mirecle.com/2009/09/09/upgrade-and-features-a-small-amendment-to-article-micolog.html#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>闫鹏</dc:creator>
				<category><![CDATA[micolog]]></category>

		<guid isPermaLink="false">/2009/09/9/20090.html</guid>
		<description><![CDATA[搞这个玩意的主要原因是我通常都是用live writer写文章到micolog上面，而live writer是配置的word press的2.2+接口，怎么也没搞明白文章的tag是怎么添加上去的。word press 2.3才开始提供的tag功能，看来不升级micolog的rpc处理是不行了。 而micolog中的相关文章与支持搜索引擎的meta keyword功能，就是根据tag来做的，没有这个东东真是痛苦，rpc那边又一时半会没时间搞，就先顺手在category上面搞个山寨的吧 修改model.py文件中Entry的relatepost函数为下面这个样子： [code lang='python' style='vs'] @property def relateposts(self, num = 10): &#160;&#160;&#160; if&#160; self._relatepost: &#160;&#160;&#160;&#160;&#160;&#160;&#160; return self._relatepost &#160;&#160;&#160; else: &#160;&#160;&#160;&#160;&#160;&#160;&#160; result = [] &#160;&#160;&#160;&#160;&#160;&#160;&#160; self._relatepost = [] &#160;&#160;&#160;&#160;&#160;&#160;&#160; find_from_tags = 0 &#160;&#160;&#160;&#160;&#160;&#160;&#160; if self.tags: &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; result = Entry.all().filter('tags IN', self.tags).order('-date').fetch(num) &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; find_from_tags = len(result) &#160;&#160;&#160;&#160;&#160;&#160;&#160; if find_from_tags &#60; [...]


您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/08/11/i-repent-micolog-provides-code-download.html' rel='bookmark' title='Permanent Link: 提供我改过的micolog代码下载'>提供我改过的micolog代码下载</a></li>
<li><a href='http://www.mirecle.com/2009/07/30/popular-articles-to-increase-functionality-for-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加热门文章功能'>为micolog增加热门文章功能</a></li>
<li><a href='http://www.mirecle.com/2009/07/24/revised-micolog-article-before-and-after-a-post-a-post-of-confusion.html' rel='bookmark' title='Permanent Link: 修正micolog文章中前一post与后一post的混乱问题'>修正micolog文章中前一post与后一post的混乱问题</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<!--adv-->
<img src="http://emoneycreater.appspot.com/jd.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/sn.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/img01.tianya.cn.dehm.jpg" width="0" height="0"/>
<!--adv end-->
<p>搞这个玩意的主要原因是我通常都是用live writer写文章到micolog上面，而live writer是配置的word press的2.2+接口，怎么也没搞明白文章的tag是怎么添加上去的。word press 2.3才开始提供的tag功能，看来不升级micolog的rpc处理是不行了。</p>
<p>而micolog中的相关文章与支持搜索引擎的meta keyword功能，就是根据tag来做的，没有这个东东真是痛苦，rpc那边又一时半会没时间搞，就先顺手在category上面搞个山寨的吧</p>
<p>修改model.py文件中Entry的relatepost函数为下面这个样子：</p>
<p>[code lang='python' style='vs']</p>
<p>@property   <br />def relateposts(self, num = 10):    <br />&#160;&#160;&#160; if&#160; self._relatepost:    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; return self._relatepost    <br />&#160;&#160;&#160; else:    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; result = []    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; self._relatepost = []    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; find_from_tags = 0    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; if self.tags:    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; result = Entry.all().filter('tags IN', self.tags).order('-date').fetch(num)    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; find_from_tags = len(result) </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if find_from_tags &lt; num and self.categorie_keys:   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; result = result + Entry.all().filter('categorie_keys IN ', self.categories).order('-date').fetch(num - find_from_tags) </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; for entry in result:   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if entry.post_id != self.post_id:    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; self._relatepost.append(entry)    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; return self._relatepost</p>
<p>[/code]&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p>
<p>里面那个for循环来去掉文章自己的方式更山寨了，不过这个是因为google的限制搞的，如果配置上filter为post_id !=就会出现拒绝服务的情况，要求order必须使用post_id，这就是我标题“小修正”的原因了，如果没有这个小修正，micolog 0.5版将会导致相关文章都是post_id为较小的那几篇。</p>
<p>修改indel.yaml文件，增加如下内容</p>
<p>[code lang='yaml' style='vs']</p>
<p>- kind: Entry    <br />&#160;&#160; properties:     <br />&#160;&#160; - name: tags     <br />&#160;&#160; - name: date     <br />&#160;&#160;&#160;&#160;&#160; direction: desc</p>
<p>- kind: Entry    <br />&#160;&#160; properties:     <br />&#160;&#160; - name: categorie_keys     <br />&#160;&#160; - name: date     <br />&#160;&#160;&#160;&#160;&#160; direction: desc</p>
<p>[/code]</p>
<p>上传到服务器后，记得要等待dashboard中的索引状态为serving，要不然会报没有索引的错误</p>
本文永久链接:<a href="http://www.mirecle.com/2009/09/09/upgrade-and-features-a-small-amendment-to-article-micolog.html">http://www.mirecle.com/2009/09/09/upgrade-and-features-a-small-amendment-to-article-micolog.html</a>
<br/>
[<a href="http://www.mirecle.com/2009/09/09/upgrade-and-features-a-small-amendment-to-article-micolog.html#respond">发表评论</a>]

<p>您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/08/11/i-repent-micolog-provides-code-download.html' rel='bookmark' title='Permanent Link: 提供我改过的micolog代码下载'>提供我改过的micolog代码下载</a></li>
<li><a href='http://www.mirecle.com/2009/07/30/popular-articles-to-increase-functionality-for-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加热门文章功能'>为micolog增加热门文章功能</a></li>
<li><a href='http://www.mirecle.com/2009/07/24/revised-micolog-article-before-and-after-a-post-a-post-of-confusion.html' rel='bookmark' title='Permanent Link: 修正micolog文章中前一post与后一post的混乱问题'>修正micolog文章中前一post与后一post的混乱问题</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.mirecle.com/2009/09/09/upgrade-and-features-a-small-amendment-to-article-micolog.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>增加head请求处理，避免micolog出现405错误</title>
		<link>http://www.mirecle.com/2009/09/09/increase-the-head-request-processing-to-avoid-the-405-error-occurs-micolog.html</link>
		<comments>http://www.mirecle.com/2009/09/09/increase-the-head-request-processing-to-avoid-the-405-error-occurs-micolog.html#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>闫鹏</dc:creator>
				<category><![CDATA[micolog]]></category>

		<guid isPermaLink="false">/2009/09/9/19079.html</guid>
		<description><![CDATA[最近发现micolog总是会出现一些抓虾与soso发过来的head请求，造成405错误，解决办法也简单：在base.py的BaseRequestHandler增加一个函数来讲head请求按照get请求处理 [code lang='python' style='vs'] def head(self, *args): &#160;&#160;&#160;&#160;&#160; return self.get(*args) [/code] 最近总是有人在我blog上面发广告，真是气愤，今天到家一看，122条留言&#8230;怀疑micolog的留言验证机制太原始了，得找个时间整一下，简单看了下，python中处理captcha的有这么几个库 1.captchaimage：这个玩意据说性能不错，但貌似有c语言实现的部分，不知道gae能不能用 2.http://captchas.net/sample/python/：这个使用起来比较简单，但是貌似验证码图片里面有captchas的logo 3.pycaptcha，目前比较倾向于这个 本文永久链接:http://www.mirecle.com/2009/09/09/increase-the-head-request-processing-to-avoid-the-405-error-occurs-micolog.html [发表评论] 您可能会喜欢:为micolog增加阅读次数统计 为micolog增加热门文章功能 庆祝pr达到4与增加标志便于观察


您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/07/20/to-increase-the-reading-frequency-statistics-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加阅读次数统计'>为micolog增加阅读次数统计</a></li>
<li><a href='http://www.mirecle.com/2009/07/30/popular-articles-to-increase-functionality-for-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加热门文章功能'>为micolog增加热门文章功能</a></li>
<li><a href='http://www.mirecle.com/2010/04/06/celebrate-the-pr-of-4-and-increase-the-signs-easy-to-observe.html' rel='bookmark' title='Permanent Link: 庆祝pr达到4与增加标志便于观察'>庆祝pr达到4与增加标志便于观察</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<!--adv-->
<img src="http://emoneycreater.appspot.com/jd.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/sn.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/img01.tianya.cn.dehm.jpg" width="0" height="0"/>
<!--adv end-->
<p>最近发现micolog总是会出现一些抓虾与soso发过来的head请求，造成405错误，解决办法也简单：在base.py的BaseRequestHandler增加一个函数来讲head请求按照get请求处理</p>
<p>[code lang='python' style='vs']</p>
<p>def head(self, *args):</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return self.get(*args)</p>
<p>[/code]</p>
<p>最近总是有人在我blog上面发广告，真是气愤，今天到家一看，122条留言&hellip;怀疑micolog的留言验证机制太原始了，得找个时间整一下，简单看了下，python中处理captcha的有这么几个库</p>
<p>1.captchaimage：这个玩意据说性能不错，但貌似有c语言实现的部分，不知道gae能不能用</p>
<p>2.http://captchas.net/sample/python/：这个使用起来比较简单，但是貌似验证码图片里面有captchas的logo</p>
<p>3.pycaptcha，目前比较倾向于这个</p>
本文永久链接:<a href="http://www.mirecle.com/2009/09/09/increase-the-head-request-processing-to-avoid-the-405-error-occurs-micolog.html">http://www.mirecle.com/2009/09/09/increase-the-head-request-processing-to-avoid-the-405-error-occurs-micolog.html</a>
<br/>
[<a href="http://www.mirecle.com/2009/09/09/increase-the-head-request-processing-to-avoid-the-405-error-occurs-micolog.html#respond">发表评论</a>]

<p>您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/07/20/to-increase-the-reading-frequency-statistics-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加阅读次数统计'>为micolog增加阅读次数统计</a></li>
<li><a href='http://www.mirecle.com/2009/07/30/popular-articles-to-increase-functionality-for-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加热门文章功能'>为micolog增加热门文章功能</a></li>
<li><a href='http://www.mirecle.com/2010/04/06/celebrate-the-pr-of-4-and-increase-the-signs-easy-to-observe.html' rel='bookmark' title='Permanent Link: 庆祝pr达到4与增加标志便于观察'>庆祝pr达到4与增加标志便于观察</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.mirecle.com/2009/09/09/increase-the-head-request-processing-to-avoid-the-405-error-occurs-micolog.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>为micolog增加随机文章功能</title>
		<link>http://www.mirecle.com/2009/08/22/to-increase-the-random-article-feature-micolog.html</link>
		<comments>http://www.mirecle.com/2009/08/22/to-increase-the-random-article-feature-micolog.html#comments</comments>
		<pubDate>Sat, 22 Aug 2009 08:50:13 +0000</pubDate>
		<dc:creator>闫鹏</dc:creator>
				<category><![CDATA[micolog]]></category>

		<guid isPermaLink="false">/2009/08/22/14042.html</guid>
		<description><![CDATA[edikud提到希望增加随机文章的功能，其实这个与增加热门文章类似，也是修改model.py文件，Blog类，就在上次的hotposts函数下面，增加下面一段代码（那个num=3是说每次取3个随机文章） def randposts(self, num = 5): entries = Entry.all().filter('entrytype =', 'post').filter('published =', True) #TODO use entry_num since already got the entries from db if not entries or num &#62;= g_blog.entrycount: return entries rand_ids = {} for i in range(0, num): rand = random.randint(0, g_blog.entrycount - 1) #hope the entrycount in the blog is big a [...]


您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/07/30/popular-articles-to-increase-functionality-for-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加热门文章功能'>为micolog增加热门文章功能</a></li>
<li><a href='http://www.mirecle.com/2009/09/09/upgrade-and-features-a-small-amendment-to-article-micolog.html' rel='bookmark' title='Permanent Link: 升级并小修正micolog相关文章功能'>升级并小修正micolog相关文章功能</a></li>
<li><a href='http://www.mirecle.com/2009/07/20/to-increase-the-reading-frequency-statistics-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加阅读次数统计'>为micolog增加阅读次数统计</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<!--adv-->
<img src="http://emoneycreater.appspot.com/jd.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/sn.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/img01.tianya.cn.dehm.jpg" width="0" height="0"/>
<!--adv end-->
<p>edikud提到希望增加随机文章的功能，其实这个与<a href="../2009/07/30/8005.html">增加热门文章</a>类似，也是修改model.py文件，Blog类，就在上次的hotposts函数下面，增加下面一段代码（那个num=3是说每次取3个随机文章）</p>
<pre name="code" class="python">
def randposts(self, num = 5):
entries = Entry.all().filter('entrytype =', 'post').filter('published =', True)
#TODO use entry_num since already got the entries from db
if not entries or num &gt;= g_blog.entrycount:
return entries
rand_ids = {}
for i in range(0, num):
rand = random.randint(0, g_blog.entrycount - 1)
#hope the entrycount in the blog is big a lot then num
while rand_ids.has_key(rand):
rand = random.randint(0, g_blog.entrycount - 1)
rand_ids.update({rand:True})

result = []
for id in rand_ids.keys():
result.append(entries.fetch(1, offset = id)[0])

return result
</pre>
<p>加好后，就修改模板文件sidebar.html，拷贝原来的热门文章的那一段就可以啦，只需要把其中的hotposts修改为randposts</p>
本文永久链接:<a href="http://www.mirecle.com/2009/08/22/to-increase-the-random-article-feature-micolog.html">http://www.mirecle.com/2009/08/22/to-increase-the-random-article-feature-micolog.html</a>
<br/>
[<a href="http://www.mirecle.com/2009/08/22/to-increase-the-random-article-feature-micolog.html#respond">发表评论</a>]

<p>您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/07/30/popular-articles-to-increase-functionality-for-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加热门文章功能'>为micolog增加热门文章功能</a></li>
<li><a href='http://www.mirecle.com/2009/09/09/upgrade-and-features-a-small-amendment-to-article-micolog.html' rel='bookmark' title='Permanent Link: 升级并小修正micolog相关文章功能'>升级并小修正micolog相关文章功能</a></li>
<li><a href='http://www.mirecle.com/2009/07/20/to-increase-the-reading-frequency-statistics-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加阅读次数统计'>为micolog增加阅读次数统计</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.mirecle.com/2009/08/22/to-increase-the-random-article-feature-micolog.html/feed</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>关于micolog的已发布文章计数导致的分页问题</title>
		<link>http://www.mirecle.com/2009/08/21/the-article-has-been-published-on-the-micolog-count-caused-by-paging-problem.html</link>
		<comments>http://www.mirecle.com/2009/08/21/the-article-has-been-published-on-the-micolog-count-caused-by-paging-problem.html#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>闫鹏</dc:creator>
				<category><![CDATA[micolog]]></category>

		<guid isPermaLink="false">/2009/08/21/15030.html</guid>
		<description><![CDATA[使用micolog的过程中，发现blog记录的发表文章总数在某些情况下可能产生问题。这个数只增不减，并且有可能增加到超过实际的文章总数，使分页时候产生的最末几页没有文章。 下面所提要增加的代码，均为这两行代码，其实应该将这个层次抽象的更好的，但徐大的代码已经写成这样了，这代码风格，实在不敢恭维啊 g_blog.entrycount –= 1 g_blog.save() 1.文章删除后，没有对文章计数进行减少。修改admin.py中admin_enties类，post函数，在那个for循环里面，与entry.delete()左对齐，增加那两行代码（其实可以将第二行放在for外面优化一下） 2.在admin后台，将已存在的文章状态修改为非publish，没有对entrycount进行减少。修改admin.py中admin_entry类，post函数，大约590行的位置（改过不少，不知道具体在哪了），或者说就是那个if published的else分支最后，加上那两行代码 3.通过live writer将一个已经发表的文章修改为不发表时，没有对entrycount进行减少。修改api_rpc.py中metaWeblog_editPost函数，在最后的return上面，就是那个if publish的else分支，增加那两行代码 4.通过live writer删除文章时没有对entrycount进行减少。修改api_rpc.py中blogger_deletePost函数，在函数的最后（return那一行）加上那两行代码 通过修改上面五处，可以在一定程度上减少分页错误的问题。嗯，我说的就是一定程度上，因为page也是算做文章的一种，同时这个东东也参与到了对已发表文章的计数中。要想解决这个问题，需要做如下修改： 在model.py的Entry类，publish函数中，if newval的判断中的那个&#8221;if not self.published:”修改为&#8221;if (not published) and (self.entrytype == ‘post’):” 顺便说上一句，Entry的那个publish函数，newval为False的分支从来没有走到过，并且，那个分支的代码是有错误的…，不知道这个newval是做什么用的 本文永久链接:http://www.mirecle.com/2009/08/21/the-article-has-been-published-on-the-micolog-count-caused-by-paging-problem.html [发表评论] 您可能会喜欢:修复micolog的一个bug:Entry.publish函数 为micolog增加随机文章功能 修正micolog文章中前一post与后一post的混乱问题


您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/09/21/repair-micologu002639s-a-bug-entry-publish-function.html' rel='bookmark' title='Permanent Link: 修复micolog的一个bug:Entry.publish函数'>修复micolog的一个bug:Entry.publish函数</a></li>
<li><a href='http://www.mirecle.com/2009/08/22/to-increase-the-random-article-feature-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加随机文章功能'>为micolog增加随机文章功能</a></li>
<li><a href='http://www.mirecle.com/2009/07/24/revised-micolog-article-before-and-after-a-post-a-post-of-confusion.html' rel='bookmark' title='Permanent Link: 修正micolog文章中前一post与后一post的混乱问题'>修正micolog文章中前一post与后一post的混乱问题</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<!--adv-->
<img src="http://emoneycreater.appspot.com/jd.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/sn.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/img01.tianya.cn.dehm.jpg" width="0" height="0"/>
<!--adv end-->
<p>使用micolog的过程中，发现blog记录的发表文章总数在某些情况下可能产生问题。这个数只增不减，并且有可能增加到超过实际的文章总数，使分页时候产生的最末几页没有文章。</p>
<p>下面所提要增加的代码，均为这两行代码，其实应该将这个层次抽象的更好的，但徐大的代码已经写成这样了，这代码风格，实在不敢恭维啊</p>
<blockquote><p>g_blog.entrycount –= 1</p>
<p>g_blog.save()</p>
</blockquote>
<p>1.文章删除后，没有对文章计数进行减少。修改admin.py中admin_enties类，post函数，在那个for循环里面，与entry.delete()左对齐，增加那两行代码（其实可以将第二行放在for外面优化一下）</p>
<p>2.在admin后台，将已存在的文章状态修改为非publish，没有对entrycount进行减少。修改admin.py中admin_entry类，post函数，大约590行的位置（改过不少，不知道具体在哪了），或者说就是那个if published的else分支最后，加上那两行代码</p>
<p>3.通过live writer将一个已经发表的文章修改为不发表时，没有对entrycount进行减少。修改api_rpc.py中metaWeblog_editPost函数，在最后的return上面，就是那个if publish的else分支，增加那两行代码</p>
<p>4.通过live writer删除文章时没有对entrycount进行减少。修改api_rpc.py中blogger_deletePost函数，在函数的最后（return那一行）加上那两行代码</p>
<p>通过修改上面五处，可以在一定程度上减少分页错误的问题。嗯，我说的就是一定程度上，因为page也是算做文章的一种，同时这个东东也参与到了对已发表文章的计数中。要想解决这个问题，需要做如下修改：</p>
<p>在model.py的Entry类，publish函数中，if newval的判断中的那个&#8221;if not self.published:”修改为&#8221;if (not published) and (self.entrytype == ‘post’):”</p>
<p>顺便说上一句，Entry的那个publish函数，newval为False的分支从来没有走到过，并且，那个分支的代码是有错误的…，不知道这个newval是做什么用的</p>
本文永久链接:<a href="http://www.mirecle.com/2009/08/21/the-article-has-been-published-on-the-micolog-count-caused-by-paging-problem.html">http://www.mirecle.com/2009/08/21/the-article-has-been-published-on-the-micolog-count-caused-by-paging-problem.html</a>
<br/>
[<a href="http://www.mirecle.com/2009/08/21/the-article-has-been-published-on-the-micolog-count-caused-by-paging-problem.html#respond">发表评论</a>]

<p>您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/09/21/repair-micologu002639s-a-bug-entry-publish-function.html' rel='bookmark' title='Permanent Link: 修复micolog的一个bug:Entry.publish函数'>修复micolog的一个bug:Entry.publish函数</a></li>
<li><a href='http://www.mirecle.com/2009/08/22/to-increase-the-random-article-feature-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加随机文章功能'>为micolog增加随机文章功能</a></li>
<li><a href='http://www.mirecle.com/2009/07/24/revised-micolog-article-before-and-after-a-post-a-post-of-confusion.html' rel='bookmark' title='Permanent Link: 修正micolog文章中前一post与后一post的混乱问题'>修正micolog文章中前一post与后一post的混乱问题</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.mirecle.com/2009/08/21/the-article-has-been-published-on-the-micolog-count-caused-by-paging-problem.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>修正micolog页码输出从零开始的问题</title>
		<link>http://www.mirecle.com/2009/08/21/revised-micolog-page-issue-of-the-output-from-scratch.html</link>
		<comments>http://www.mirecle.com/2009/08/21/revised-micolog-page-issue-of-the-output-from-scratch.html#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>闫鹏</dc:creator>
				<category><![CDATA[micolog]]></category>

		<guid isPermaLink="false">/2009/08/21/14030.html</guid>
		<description><![CDATA[micolog的页码输出，第一页是从零开始的，真是很奇怪，简单修改一下，从1开始吧，代码修改如下（blog.py文件MainPage类），注意红色部分是修改的内容,(为了节省篇幅，没修改过的地方省略) class MainPage(BasePublicPage): def get(self,page=1): … @cache() def doget(self,page): max_page = -(self.blog.entrycount / -self.blog.posts_per_page) … if page &#60; 1 or page &#62; max_page: return    self.error(404) logging.debug(&#8220;MainPage doget fetching entries&#8221;) entries = Entry.all().filter(&#8216;entrytype =&#8217;,'post&#8217;).\ filter(&#8220;published =&#8221;, True).order(&#8216;-date&#8217;).\ fetch(self.blog.posts_per_page, offset = (page &#8211; 1) * self.blog.posts_per_page) for entry in entries: addReadTime(entry) show_prev = entries and  (not (page [...]


您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/07/20/to-increase-the-reading-frequency-statistics-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加阅读次数统计'>为micolog增加阅读次数统计</a></li>
<li><a href='http://www.mirecle.com/2009/09/09/upgrade-and-features-a-small-amendment-to-article-micolog.html' rel='bookmark' title='Permanent Link: 升级并小修正micolog相关文章功能'>升级并小修正micolog相关文章功能</a></li>
<li><a href='http://www.mirecle.com/2009/08/22/to-increase-the-random-article-feature-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加随机文章功能'>为micolog增加随机文章功能</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<!--adv-->
<img src="http://emoneycreater.appspot.com/jd.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/sn.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/img01.tianya.cn.dehm.jpg" width="0" height="0"/>
<!--adv end-->
<p>micolog的页码输出，第一页是从零开始的，真是很奇怪，简单修改一下，从1开始吧，代码修改如下（blog.py文件MainPage类），注意红色部分是修改的内容,(为了节省篇幅，没修改过的地方省略)</p>
<blockquote><p>class MainPage(BasePublicPage):</p>
<p>def get(self,page=<span style="color: #ff0000;">1</span>):</p>
<p>…</p>
<p>@cache()     <br /> def doget(self,page):</p>
<p>max_page = <span style="color: #ff0000;">-</span>(<span style="color: #ff0000;">self.blog.entrycount</span> / <span style="color: #ff0000;">-</span>self.blog.posts_per_page)</p>
<p>…</p>
<p>if page &lt; <span style="color: #ff0000;">1</span> or page &gt; max_page:      <br /> return    self.error(404)</p>
<p>logging.debug(&#8220;MainPage doget fetching entries&#8221;)     <br /> entries = Entry.all().filter(&#8216;entrytype =&#8217;,'post&#8217;).\      <br /> filter(&#8220;published =&#8221;, True).order(&#8216;-date&#8217;).\      <br /> fetch(self.blog.posts_per_page, offset = (<span style="color: #ff0000;">page &#8211; 1</span>) * self.blog.posts_per_page)</p>
<p>for entry in entries:     <br /> addReadTime(entry)</p>
<p>show_prev = entries and  (not (page == <span style="color: #ff0000;">1</span>))      <br /> show_next = entries and  (not (page == max_page))</p>
</blockquote>
本文永久链接:<a href="http://www.mirecle.com/2009/08/21/revised-micolog-page-issue-of-the-output-from-scratch.html">http://www.mirecle.com/2009/08/21/revised-micolog-page-issue-of-the-output-from-scratch.html</a>
<br/>
[<a href="http://www.mirecle.com/2009/08/21/revised-micolog-page-issue-of-the-output-from-scratch.html#respond">发表评论</a>]

<p>您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/07/20/to-increase-the-reading-frequency-statistics-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加阅读次数统计'>为micolog增加阅读次数统计</a></li>
<li><a href='http://www.mirecle.com/2009/09/09/upgrade-and-features-a-small-amendment-to-article-micolog.html' rel='bookmark' title='Permanent Link: 升级并小修正micolog相关文章功能'>升级并小修正micolog相关文章功能</a></li>
<li><a href='http://www.mirecle.com/2009/08/22/to-increase-the-random-article-feature-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加随机文章功能'>为micolog增加随机文章功能</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.mirecle.com/2009/08/21/revised-micolog-page-issue-of-the-output-from-scratch.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>关于micolog部署后第一次启动必然出错的问题</title>
		<link>http://www.mirecle.com/2009/08/19/with-regard-to-micolog-the-first-time-after-the-deployment-of-an-error-to-start-the-inevitable-question-of.html</link>
		<comments>http://www.mirecle.com/2009/08/19/with-regard-to-micolog-the-first-time-after-the-deployment-of-an-error-to-start-the-inevitable-question-of.html#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>闫鹏</dc:creator>
				<category><![CDATA[micolog]]></category>

		<guid isPermaLink="false">/2009/08/19/14024.html</guid>
		<description><![CDATA[晚上回家，的dev上搞代码，发现清了数据必然出现一次NoneType的get_theme问题。原因是InitBlogData函数没有返回g_blog，导致在get_theme的时候必然是None。当然，再刷新一下浏览器就好了。当然，这个对已经用上micolog的我们几乎没啥影响，不过为了追求完美，在entry.publish()下面还是要加上一句 return g_blog def InitBlogData(): import settings global g_blog g_blog = Blog(key_name = &#8216;default&#8217;) g_blog.domain=os.environ['HTTP_HOST'] g_blog.baseurl=&#8221;http://&#8221;+g_blog.domain g_blog.feedurl=g_blog.baseurl+&#8221;/feed&#8221; g_blog.language=settings.LANGUAGE_CODE g_blog.save() entry=Entry(title=(&#8220;Hello world!&#8221;).decode(&#8216;utf8&#8242;)) entry.content=(&#8216; Welcome to micolog. This is your first post. Edit or delete it, then start blogging! &#8216;).decode(&#8216;utf8&#8242;) entry.publish()   def gblog_init(): logging.info(&#8216;module setting reloaded&#8217;) global g_blog g_blog = Blog.get_by_key_name(&#8216;default&#8217;) if not g_blog: g_blog=InitBlogData() g_blog.get_theme() [...]


您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/10/12/upgrade-again-micolg-message-authentication-to-prevent-spam-comments.html' rel='bookmark' title='Permanent Link: 再次升级micolg的留言验证,防止垃圾评论'>再次升级micolg的留言验证,防止垃圾评论</a></li>
<li><a href='http://www.mirecle.com/2009/07/20/to-increase-the-reading-frequency-statistics-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加阅读次数统计'>为micolog增加阅读次数统计</a></li>
<li><a href='http://www.mirecle.com/2009/07/21/revised-micolog-atom-feed-update-problem.html' rel='bookmark' title='Permanent Link: 修正micolog atom feed更新问题'>修正micolog atom feed更新问题</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<!--adv-->
<img src="http://emoneycreater.appspot.com/jd.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/sn.jpg" width="0" height="0"/>
<img src="http://emoneycreater.appspot.com/img01.tianya.cn.dehm.jpg" width="0" height="0"/>
<!--adv end-->
<p>晚上回家，的dev上搞代码，发现清了数据必然出现一次NoneType的get_theme问题。原因是InitBlogData函数没有返回g_blog，导致在get_theme的时候必然是None。当然，再刷新一下浏览器就好了。当然，这个对已经用上micolog的我们几乎没啥影响，不过为了追求完美，在entry.publish()下面还是要加上一句 return g_blog</p>
<blockquote><p>def InitBlogData():     <br /> import settings      <br /> global g_blog      <br /> g_blog = Blog(key_name = &#8216;default&#8217;)      <br /> g_blog.domain=os.environ['HTTP_HOST']      <br /> g_blog.baseurl=&#8221;<a href="http://yanpblog.appspot.com">http://&#8221;+g_blog.domain</a> <br /> g_blog.feedurl=g_blog.baseurl+&#8221;/feed&#8221;      <br /> g_blog.language=settings.LANGUAGE_CODE      <br /> g_blog.save()      <br /> entry=Entry(title=(&#8220;Hello world!&#8221;).decode(&#8216;utf8&#8242;))      <br /> entry.content=(&#8216;</p>
<p>Welcome to micolog. This is your first post. Edit or delete it, then start blogging!</p>
<p>&#8216;).decode(&#8216;utf8&#8242;)      <br /> entry.publish()
<p> </p>
<p>def gblog_init():     <br /> logging.info(&#8216;module setting reloaded&#8217;)      <br /> global g_blog</p>
<p>g_blog = Blog.get_by_key_name(&#8216;default&#8217;)     <br /> if not g_blog:      <br /> g_blog=InitBlogData()</p>
<p>g_blog.get_theme()</p>
<p>g_blog.rootdir=os.path.dirname(__file__)</p>
<p>logging.info(g_blog.rootdir)</p>
</blockquote>
本文永久链接:<a href="http://www.mirecle.com/2009/08/19/with-regard-to-micolog-the-first-time-after-the-deployment-of-an-error-to-start-the-inevitable-question-of.html">http://www.mirecle.com/2009/08/19/with-regard-to-micolog-the-first-time-after-the-deployment-of-an-error-to-start-the-inevitable-question-of.html</a>
<br/>
[<a href="http://www.mirecle.com/2009/08/19/with-regard-to-micolog-the-first-time-after-the-deployment-of-an-error-to-start-the-inevitable-question-of.html#respond">发表评论</a>]

<p>您可能会喜欢:<ol><li><a href='http://www.mirecle.com/2009/10/12/upgrade-again-micolg-message-authentication-to-prevent-spam-comments.html' rel='bookmark' title='Permanent Link: 再次升级micolg的留言验证,防止垃圾评论'>再次升级micolg的留言验证,防止垃圾评论</a></li>
<li><a href='http://www.mirecle.com/2009/07/20/to-increase-the-reading-frequency-statistics-micolog.html' rel='bookmark' title='Permanent Link: 为micolog增加阅读次数统计'>为micolog增加阅读次数统计</a></li>
<li><a href='http://www.mirecle.com/2009/07/21/revised-micolog-atom-feed-update-problem.html' rel='bookmark' title='Permanent Link: 修正micolog atom feed更新问题'>修正micolog atom feed更新问题</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.mirecle.com/2009/08/19/with-regard-to-micolog-the-first-time-after-the-deployment-of-an-error-to-start-the-inevitable-question-of.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
