存档

‘micolog’ 分类的存档

为micolog增加随机文章功能

2009年8月22日 29 条评论

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 >= 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

加好后,就修改模板文件sidebar.html,拷贝原来的热门文章的那一段就可以啦,只需要把其中的hotposts修改为randposts

---------------------------------------------------------------
本站作品根据创作共同协议进行授权, 转载时请务必以超链接形式标明文章原始出处
原文地址:http://www.mirecle.com/2009/08/22/to-increase-the-random-article-feature-micolog.html
---------------------------------------------------------------

分类: micolog 标签:

关于micolog的已发布文章计数导致的分页问题

2009年8月21日 1 条评论

使用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的判断中的那个”if not self.published:”修改为”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 标签:

修正micolog页码输出从零开始的问题

2009年8月21日 1 条评论

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 < 1 or page > max_page:
return    self.error(404)

logging.debug(“MainPage doget fetching entries”)
entries = Entry.all().filter(‘entrytype =’,'post’).\
filter(“published =”, True).order(‘-date’).\
fetch(self.blog.posts_per_page, offset = (page – 1) * self.blog.posts_per_page)

for entry in entries:
addReadTime(entry)

show_prev = entries and  (not (page == 1))
show_next = entries and  (not (page == max_page))

---------------------------------------------------------------
本站作品根据创作共同协议进行授权, 转载时请务必以超链接形式标明文章原始出处
原文地址:http://www.mirecle.com/2009/08/21/revised-micolog-page-issue-of-the-output-from-scratch.html
---------------------------------------------------------------

分类: micolog 标签:

关于micolog部署后第一次启动必然出错的问题

2009年8月19日 1 条评论

晚上回家,的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 = ‘default’)
g_blog.domain=os.environ['HTTP_HOST']
g_blog.baseurl=”http://”+g_blog.domain
g_blog.feedurl=g_blog.baseurl+”/feed”
g_blog.language=settings.LANGUAGE_CODE
g_blog.save()
entry=Entry(title=(“Hello world!”).decode(‘utf8′))
entry.content=(‘

Welcome to micolog. This is your first post. Edit or delete it, then start blogging!

‘).decode(‘utf8′)
entry.publish()

 

def gblog_init():
logging.info(‘module setting reloaded’)
global g_blog

g_blog = Blog.get_by_key_name(‘default’)
if not g_blog:
g_blog=InitBlogData()

g_blog.get_theme()

g_blog.rootdir=os.path.dirname(__file__)

logging.info(g_blog.rootdir)

---------------------------------------------------------------
本站作品根据创作共同协议进行授权, 转载时请务必以超链接形式标明文章原始出处
原文地址: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
---------------------------------------------------------------

分类: micolog 标签:

换了主题,升级了blog部分功能

2009年8月14日 7 条评论

好久没有搞micolog的代码了,看到大家已经更新了很多功能,我也抽时间改一下,这次主要的改动有

1.主题inove,就是WordPress的那个经典主题

2.增加qq表情评论功能

3.增加品论的引用功能

---------------------------------------------------------------
本站作品根据创作共同协议进行授权, 转载时请务必以超链接形式标明文章原始出处
原文地址:http://www.mirecle.com/2009/08/14/changed-the-theme-upgrade-some-features-of-the-blog.html
---------------------------------------------------------------

分类: micolog 标签:

提供我改过的micolog代码下载

2009年8月11日 4 条评论

最近好多童鞋发邮件问部署的问题(大多数人是index.yaml的修改问题),还有童鞋发邮件要我修改过的micolog的代码。在这里提供个我修改过的index.yaml吧,并且附上我修改过的micolog的下载地址

我改过的主要内容,请查看这个blog的micolog目录中的那些文章

index.yaml,如果你用徐老大的0.5版本,可以使用这个index.yaml(与从我这里下载的micolog是不同的,因为我修改的版本里面增加了readtime,为了不出错,这里面的index.yaml的readtime删掉了)

indexes:

# AUTOGENERATED

# This index.yaml is automatically updated whenever the dev_appserver
# detects that a new type of query is run.  If you want to manage the
# index.yaml file manually, remove the above marker line (the line
# saying “# AUTOGENERATED”).  If you want to manage some indexes
# manually, move them above the marker line.  The index.yaml file is
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.

# Unused in query history — copied from input.
#- kind: Archive
#  properties:
#  – name: date
#    direction: desc

# Used 31 times in query history.
#- kind: Comment
#  properties:
#  – name: date
#    direction: desc

# Used once in query history.
- kind: Comment
properties:
– name: entry
– name: date

# Unused in query history — copied from input.
- kind: Comment
properties:
– name: entry
– name: date
direction: desc

# Unused in query history — copied from input.
- kind: Entry
properties:
– name: categorie_keys
– name: date
direction: desc

# Unused in query history — copied from input.
#- kind: Entry
#  properties:
#  – name: date
#    direction: desc

# Used 29 times in query history.
- kind: Entry
properties:
– name: entry_parent
– name: entrytype
– name: published
– name: menu_order

# Unused in query history — copied from input.
- kind: Entry
properties:
– name: entry_type
– name: date
direction: desc

# Used 4 times in query history.
- kind: Entry
properties:
– name: entrytype
– name: date
direction: desc

# Unused in query history — copied from input.
- kind: Entry
properties:
– name: entrytype
– name: post_id

# Unused in query history — copied from input.
- kind: Entry
properties:
– name: entrytype
– name: post_id
direction: desc

# Used 11 times in query history.
- kind: Entry
properties:
– name: entrytype
– name: published
– name: date
direction: desc

- kind: Entry
properties:
– name: entrytype
– name: published
– name: date

# Unused in query history — copied from input.
- kind: Entry
properties:
– name: entrytype
– name: published
– name: slug
– name: date

# Unused in query history — copied from input.
- kind: Entry
properties:
– name: entrytype=
– name: date
direction: desc

# Unused in query history — copied from input.
#- kind: Entry
#  properties:
#  – name: post_id
#    direction: desc

# Unused in query history — copied from input.
- kind: Entry
properties:
– name: published
– name: date
direction: desc

# Unused in query history — copied from input.
- kind: Entry
properties:
– name: slug
– name: date

# Unused in query history — copied from input.
- kind: Entry
properties:
– name: tags
– name: date
direction: desc

# Unused in query history — copied from input.
- kind: Entry
properties:
– name: tags
– name: post_id
direction: desc

# Unused in query history — copied from input.
- kind: Link
properties:
– name: linktype
– name: createdate
direction: desc

# Unused in query history — copied from input.
- kind: Link
properties:
– name: linktype
– name: href

# Unused in query history — copied from input.
#- kind: Logger
#  properties:
#  – name: date
#    direction: desc

---------------------------------------------------------------
本站作品根据创作共同协议进行授权, 转载时请务必以超链接形式标明文章原始出处
原文地址:http://www.mirecle.com/2009/08/11/i-repent-micolog-provides-code-download.html
---------------------------------------------------------------

分类: micolog 标签: