ing

Micolog 添加评论回复邮件通知功能

09-10-20 @ Dae /
转载来自: 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

或者通过RSS关注本站的更新 ^ O ^ 。” — by edikud @ 09-10-20 - 22:48。

转载请注明:来自eDIKUD'S Blog

Tag(s): mail  
  • QQ书签
  • Del.icio.us
  • 百度收藏
  • Google
  • 饭否
  • FriendFeed
点击查看》》 暧昧文章 / 相关文章 / 热评文章

13 Comments Contributed by Visitors
  1. edikud / 03:33@2009-10-20 / Reply / Quote 1
    edikud
  2. nefull / 03:39@2009-10-20 / Reply / Quote 2
    nefull

    test 评论回复邮件通知功能

  3. nefull / 03:43@2009-10-20 / Reply / Quote 3
    nefull
  4. TaoGOGO / 12:30@2009-10-21 / Reply / Quote 4
    TaoGOGO

    只留言,不要回复,每天看一眼

  5. jude / 16:35@2009-10-21 / Reply / Quote 5
    jude

    这个主题很炫啊!

  6. edikud / 18:53@2009-10-21 / Reply / Quote 6
    edikud

    @jude:
    多来看一看啊。。。

  7. vvonder / 20:11@2009-10-21 / Reply / Quote 7
    vvonder

    好像主题更眩了 输入名字的地方有点隐蔽啊...

  8. edikud / 20:16@2009-10-21 / Reply / Quote 8
    edikud

    @vvonder:
    用JQ隐蔽了。。点这个修改 edit info?

  9. 云在天边 / 13:49@2009-10-22 / Reply / Quote 9
    云在天边

    主题越来越好看啦,呵呵

  10. houkai / 10:14@2009-10-23 / Reply / Quote 10
    houkai

    very good! 特效真多!

  11. edikud / 12:28@2009-10-23 / Reply / Quote 11
    edikud
  12. Adam / 21:21@2009-10-25 / Reply / Quote 12
    Adam

    这个比较实用 改天加上试试

  13. 阳朔住宿 / 13:57@2009-12-02 / Reply / Quote 13
    阳朔住宿

    感谢博主的无私奉献 阳朔酒店

Leave Comments Here...

:) lol 8) :-o evil :( wink :-| :-x twisted 8-O :-P oops idea :-D cry :-? ?

(required)

(required)

随您

(Ctrl+Enter)

Please calculate 1+10

  • 本站不会泄露您的邮件地址,敬请放心.
  • 支持常用 HTML 代码调用.
  • 仅当某人针对您的评论做出回应时,您才会收到由本站发出的通知信件.
  • 如您希望以相同方式通知某位网友,请点击 Reply 按钮,或自行输入@对方名字.
  • 允许在评论中贴的代码如下:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .
  • 鼠标移植评论中的 @someone 区域即可自动显示 someone 的评论内容.