Micolog 添加评论回复邮件通知功能
转载来自: demoslam
架了Micolog之后,发现评论功能比较简单,就根据HouKai的文章增加了Reply的功能(没有添加引用的功能,感觉不是很实用,还容易把页面拖的不整洁)。WordPress有个评论回复邮件通知的功能插件,于是想想也该给Micolog加个这个功能。
首先在相应主题的comments.html文件中在添加评论邮件通知的checkbox,位置可以随便定,感觉放在submit按钮之后会比较好:
<p>
<input name="submit" type="submit" id="submit" tabindex="6" value="Submit Comment" />
<input name="reply_notify_mail" id="reply_notify_mail" tabindex="5" checked="checked"
style="width: auto;" type="checkbox" />
<label for="reply_notify_mail">Notify me if there is a reply</label>
</p>
接着在blog.py中Post_comment类中添加处理客户端POST数据中的邮件定制信息:
# 大概在248行的位置,添加reply_notify_mail的几行
key=self.param('key')
content=self.param('comment')
replynotify=self.param('reply_notify_mail')
reply_notify_mail=True
if replynotify != 'on':
reply_notify_mail=False
# 大概在295行的位置,添加reply_notify_mail的一行
else:
comment=Comment(author=name,
content=content.replace('^~',
"<img src="../static/images/emotions/icon_" alt="" />'),
email=email,
reply_notify_mail=reply_notify_mail,
entry=Entry.get(key))
然后在model.py中添加评论回复通知功能:
if g_blog.comment_notify_mail and g_blog.owner:#and not users.is_current_user_admin()
sbody=sbody%(self.entry.title,self.author,self.email,self.weburl,self.content,
g_blog.baseurl+"/"+self.entry.link+"#comment-"+str(self.key().id()))
mail.send_mail_to_admins(g_blog.owner.email(),'Comments on:'
+self.entry.title, sbody,reply_to=self.email)
logging.info('send %s . entry: %s'%(g_blog.owner.email(),self.entry.title))
# 大概在515行的位置,从这里开始添加功能
replyComments = re.findall(r'@[\S]+[:]', self.content)
if len(replyComments)!=0:
originAuthor=[a[1:-1] for a in replyComments]
commentQuery=Comment.all().filter('entry =', self.entry)
.filter('author =', originAuthor[0]).order('-date')
commentGet=commentQuery.get()
emailInfo=commentGet.email
notifyEnable=commentGet.reply_notify_mail
if notifyEnable and g_blog.comment_notify_mail
and g_blog.owner and mail.is_email_valid(emailInfo):
emailBody=ebody%(originAuthor[0],self.entry.title,self.author,self.weburl,
self.content,g_blog.baseurl+"/"
+self.entry.link+"#comment-"+str(self.key().id()))
message=mail.EmailMessage(sender=g_blog.owner.email(),
subject="Reply on your post:"+self.entry.title)
message.to=emailInfo
message.body=emailBody
message.send()
# 大概在460行的位置添加数据库中表示是否定制邮件通知的数据元:
author=db.StringProperty()
email=db.EmailProperty()
reply_notify_mail=db.BooleanProperty(default=True) <---添加这一句
weburl=db.URLProperty()
之后在index.yaml添加查询用的index,这个比较关键,当时前面order('-date') gae总是报错,就是没有index的缘故:
# 重新添加一个Comment的查询index
- kind: Comment
properties:
- name: entry
- name: author
- name: date
direction: desc
添加完毕后,博客程序便会根据被回复人在当前文章最新的回复状态来判断是否发送邮件通知。
参考:Email notification enhancement for micolog
P.S. “喜欢本文?现在就把它分享到 Twitter 或者通过RSS关注本站的更新 ^ O ^ 。” — by edikud @ 09-10-20 - 22:48。转载请注明:来自eDIKUD'S Blog
Tag(s): mail
@edikud:
test 评论回复邮件通知功能
@nefull:

只留言,不要回复,每天看一眼
这个主题很炫啊!
@jude:
多来看一看啊。。。
好像主题更眩了
输入名字的地方有点隐蔽啊...
@vvonder:
用JQ隐蔽了。。点这个修改 edit info?
主题越来越好看啦,呵呵
very good! 特效真多!
@houkai:

这个比较实用 改天加上试试
感谢博主的无私奉献
阳朔酒店