def get_thread_comment_or_both(thread_or_comment_id):
    """
    Determine if provided ID is for a thread or comment
    :param thread_or_comment_id: UUID - can be either a thread ID (in the YTP sense) or a comment ID
    :return: CommentThread object, and Comment object (if applicable)
    """
    thread = CommentThread.get(thread_or_comment_id)

    if thread:
        comment = None
    else:
        # Fallback: check for comment by id provided...
        comment = Comment.get(thread_or_comment_id)
        if comment:
            thread = CommentThread.get(comment.thread_id)

    return thread, comment
Exemplo n.º 2
0
    def post(self, id=None):
        comment = Comment()
        user = users.get_current_user()
        key_user = ndb.Key(User, user.email())
        user_details = key_user.get()
        if self.request.get("comment").strip() != "":
            comment.commenter = user_details
            comment.commentDescription = self.request.get("comment").strip()
            comment.createdAt = datetime.now()
            comment = comment.put()
            commentedPost = Post.get_by_id(int(id))
            commentedPost.comments.append(comment.get())
            commentedPost.put()
            time.sleep(0.1)
        else:
            self.add_message("Please don't enter empty string", "danger")

        if self.request.get("ad").strip() == "postDetail":
            self.redirect('/post/' + id, abort=False)
        else:
            self.redirect('/', abort=False)
Exemplo n.º 3
0
	def get(self,page):
		code=OptionSet.getValue("Akismet_code",default="")
		up=OptionSet.getValue("Akismet_Comments_v0.3",default=[])
		if type(up)!=type([]):
			up=[]
		delkey = page.param('delkey')
		rekey = page.param('rekey')
		if rekey or delkey:
			newup = []
			for i in up:
				cmtkey = i['key'][0];
				enykey = i['key'][1];
				if delkey and cmtkey==delkey:
					cm = Comment.get(cmtkey)
					db.Model.delete(cm)
				elif rekey and cmtkey==rekey:
					cm = Comment.get(cmtkey)
					eny = Entry.get(enykey)
					eny.commentcount+=1
					eny.put()
					cm.entry = eny
					db.Model.put(cm)
					self.SubmitAkismet({
						'user_agent':i['other']['user_agent'],
						'referrer':i['other']['referrer'],
						'user_ip' : cm.ip,
						'comment_type' : 'comment', 
						'comment_author' : cm.author.encode('utf-8'),
						'comment_author_email' : cm.email,
						'comment_author_url' : cm.weburl,
						'comment_content' : cm.content.encode('utf-8')
					},i['other'].get('url',''),"Ham")
				else:
					newup.append(i)
			if not len(up)==len(newup):
				OptionSet.setValue("Akismet_Comments_v0.3",newup)
			up = newup
		cmts = [(Comment.get(i['key'][0]),Entry.get(i['key'][1])) for i in up]
		comments = [u'<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td><a target="_blank" href="/%s">%s</a></td><td><a href="?delkey=%s" title="删除">删除</a> <a href="?rekey=%s" title="这不是一个垃圾评论">还原</a></td></tr>'%(i[0].date,
			i[0].author,i[0].content,i[0].email,i[0].ip,i[1].link,i[1].title,str(i[0].key()),str(i[0].key())) for i in cmts]
		comments = ''.join(comments)
		apikey = OptionSet.getValue("Akismet_code",default=self.AKISMET_default_Key)
		if len(apikey)<5:
			apikey = self.AKISMET_default_Key
		api =  AkismetManager(apikey,Blog.all()[0].baseurl)
		if not code:
			status = ''
		elif api.IsValidKey():
			status = 'True'
		else:
			status = 'False'
		return u'''<h3>Akismet</h3>
					<form action="" method="post">
					<p>Akismet Api Key:</p>
					<input name="code" style="width:400px;" value="%s"> %s
					<br />
					<p>删除一条评论并提交Spam(输入评论的ID):</p>
					<input name="spam" style="width:400px;" value="">
					<br />
					<input type="submit" value="submit">
					</form>
				  <div>
				  	<br />
				  	<h3>被过滤的评论</h3> <table class="widefat"><thead><tr><th>日期</th><th>作者</th><th>内容</th><th>电子邮件</th><th>IP地址</th><th>文章/页面</th><th style="width:15%%;">选择操作</th></tr></thead><tbody>%s </tbody></table>
				  </div>'''%(code,status,comments)
Exemplo n.º 4
0
    def get(self, page):
        code = OptionSet.getValue("Akismet_code", default="")
        up = OptionSet.getValue("Akismet_Comments_v0.3", default=[])
        rm = OptionSet.getValue("Akismet_AutoRemove", False)
        if type(up) != type([]):
            up = []
        delkey = page.param("delkey")
        rekey = page.param("rekey")
        if rekey or delkey:
            newup = []
            for i in up:
                cmtkey = i["key"][0]
                enykey = i["key"][1]
                if delkey and cmtkey == delkey:
                    cm = Comment.get(cmtkey)
                    db.Model.delete(cm)
                elif rekey and cmtkey == rekey:
                    cm = Comment.get(cmtkey)
                    eny = Entry.get(enykey)
                    eny.commentcount += 1
                    eny.put()
                    cm.entry = eny
                    db.Model.put(cm)
                    self.SubmitAkismet(
                        {
                            "user_agent": i["other"]["user_agent"],
                            "referrer": i["other"]["referrer"],
                            "user_ip": cm.ip,
                            "comment_type": "comment",
                            "comment_author": cm.author.encode("utf-8"),
                            "comment_author_email": cm.email,
                            "comment_author_url": cm.weburl,
                            "comment_content": cm.content.encode("utf-8"),
                        },
                        i["other"].get("url", ""),
                        "Ham",
                    )
                else:
                    newup.append(i)
            if not len(up) == len(newup):
                OptionSet.setValue("Akismet_Comments_v0.3", newup)
            up = newup
        cmts = [(Comment.get(i["key"][0]), Entry.get(i["key"][1])) for i in up]
        comments = [
            u'<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td><a target="_blank" href="/%s">%s</a></td><td><a href="?delkey=%s" title="删除">删除</a> <a href="?rekey=%s" title="这不是一个垃圾评论">还原</a></td></tr>'
            % (
                i[0].date,
                i[0].author,
                i[0].content,
                i[0].email,
                i[0].ip,
                i[1].link,
                i[1].title,
                str(i[0].key()),
                str(i[0].key()),
            )
            for i in cmts
            if i is not None and i[0] is not None
        ]
        comments = "".join(comments)
        apikey = OptionSet.getValue("Akismet_code", default=self.AKISMET_default_Key)
        if len(apikey) < 5:
            apikey = self.AKISMET_default_Key
        api = AkismetManager(apikey, Blog.all()[0].baseurl)
        if not code:
            status = ""
        elif api.IsValidKey():
            status = "True"
        else:
            status = "False"
        if rm == True:
            rmchecked = 'checked="checked"'
        else:
            rmchecked = ""
        return u"""<h3>Akismet</h3>
					<form action="" method="post">
					<p>Akismet Api Key:</p>
					<input name="code" style="width:400px;" value="%s"> %s
					<br />
					<p>自动删除检测到的垃圾评论:
					<input type="checkbox" name="autorm" value="1" %s></p>
					<p>删除一条正常的评论并提交Spam(输入评论的ID):</p>
					<input name="spam" style="width:400px;" value="">
					<br />
					<input type="submit" value="submit">
					</form>
				  <div>
				  	<br />
				  	<h3>被过滤的评论</h3> <table class="widefat"><thead><tr><th>日期</th><th>作者</th><th>内容</th><th>电子邮件</th><th>IP地址</th><th>文章/页面</th><th style="width:15%%;">选择操作</th></tr></thead><tbody>%s </tbody></table>
				  </div>""" % (
            code,
            status,
            rmchecked,
            comments,
        )