def del_fs_reply(userid, rid, **ps): db = getconn() reply = db.get( u"SELECT tid, oldfilename FROM herzog_reply" " WHERE rid=%s", rid) if not reply: raise HZActionError('No such reply') if not reply.oldfilename: logger.warning( "Try delete a no oldfilename file, userid=%s, fromhost=%s, reply=%s", userid, request.remote_addr, reply) return True topic = db.get(u"SELECT boardname FROM herzog_topic" " WHERE tid=%s", reply.tid) if not topic: raise HZActionError('No such topic') r = getclient().do_del(board=topic.boardname, file=reply.oldfilename) if 'error' in r: if r['emsg'] == u"文件不存在, 删除失败": if (isowner_topic(userid, tid)): warning( "Delete a no exists file, filename=%s, userid=% [%s], fromhost=%s", topic.oldfilename, authed, request.remote_addr, topic) return True raise HZActionError(r['emsg']) return True
def update2fs(userid, tid, title, content, **ps): db = getconn() topic = db.get(u"SELECT boardname, oldfilename FROM herzog_topic" " WHERE tid=%s", tid) if not topic : raise HZActionError('No such topic') r = getclient().do_edit(board=topic.boardname, title=title.encode('utf8'), text=content.encode('utf8'), file=topic.oldfilename) if r.has_key('error') : raise HZActionError(r['emsg']) return True
def norepeatvote(userid, tid=None, rid=None, **ps): if tid : if getconn().get( u"SELECT tid FROM herzog_topicship" " WHERE userid=%s AND tid=%s AND (flag & %s >0)", userid, tid, flag.UPVOTE) : raise HZActionError("No vote again") else : if getconn().get( u"SELECT rid FROM herzog_replyship" " WHERE userid=%s AND rid=%s AND (flag & %s >0)", userid, rid, flag.UPVOTE) : raise HZActionError('No vote again') return True
def save_reply_to_fs(userid, tid, content, fromaddr, **ps): origin = getconn().get(u"SELECT boardname, oldfilename, title, content," " owner FROM herzog_topic WHERE tid=%s", tid) if not origin : raise HZActionError("No such topic") content = fixtext(content + quote(origin.content, origin.owner)) print content ret = getclient().do_snd(board=origin.boardname, title=quote_title(origin.title).encode('utf8'), text=content, refile=origin.oldfilename) if 'error' in ret : raise HZActionError(ret['emsg']) g._filename = ret['filename'] return True
def save_topic_to_fs(userid, boardname, title, content, fromaddr, **ps) : ret = getclient().do_snd(board=boardname, title=title.encode('utf8'), text=content.encode('utf8')) if 'error' in ret : raise HZActionError(ret['emsg']) g._filename = ret['filename'] return True
def save_comment_to_fs(userid, replyid, content, fromaddr, **ps): db = getconn() origin = db.get(u"SELECT tid, oldfilename, content, owner" " FROM herzog_reply WHERE rid=%s", replyid) if not origin : raise HZActionError("ReplyError: No such post") content = content + quote(origin.content, origin.owner) torigin = db.get(u"SELECT boardname, title FROM herzog_topic" " WHERE tid=%s", origin.tid) if not torigin : raise Precondition("ReplyError:No such topic") ret = getclient().do_snd(board=torigin.boardname, title=quote_title(torigin.title).encode('utf8'), text=content.encode('utf8'), refile=origin.oldfilename) if 'error' in ret : raise HZActionError(u'Cannot save post. [%s]' % ret['emsg']) g._filename = ret['filename'] return True
def update2fs_reply(userid, rid, content, **ps) : db = getconn() reply = db.get(u"SELECT tid, oldfilename FROM herzog_reply" " WHERE rid=%s", rid) if not reply : raise HZActionError('No such reply') topic = db.get(u"SELECT boardname FROM herzog_topic" " WHERE tid=%s", reply.tid) if not topic : raise HZActionError("No such topic") header, _, quote, tail = getfspost(topic.boardname, reply.oldfilename) r = getclient().do_edit(board=topic.boardname, title=header['title'].decode('gbk').encode('utf8'), text=content.encode('utf8'), file=reply.oldfilename) if r.has_key('error') : raise HZActionError(r['emsg']) return True
def unvote(userid, tid=None, rid=None, **ps): if flagdown(userid, flag.UPVOTE, tid=tid, rid=rid) is False : raise HZActionError("Have not vote it") db = getconn() if tid : db.execute(u"UPDATE herzog_topic SET upvote=upvote-1" " WHERE tid=%s", tid) else : db.execute(u"UPDATE herzog_reply SET upvote=upvote-1" " WHERE rid=%s", rid) return dict()
def comment(userid, replyid, content, fromaddr, time=None, fromapp='', *ps) : if time is None : time = dt.now() db = getconn() reply = db.get("SELECT tid, brid FROM herzog_reply WHERE rid=%s", replyid) if not reply : raise HZActionError("No such topic") rid = db.execute(u"INSERT INTO herzog_reply" " (tid, brid, replyid, owner, lastupdate," " fromaddr, content) VALUES" " (%s, %s, %s, %s, %s, %s, %s)", reply.tid, reply.brid, replyid, userid, time, fromaddr, content) db.execute(u"UPDATE herzog_topic SET lastcomment=%s WHERE tid=%s", time, reply.tid) return dict(rid=rid, tid=reply.tid)
def unstar(userid, tid=None, rid=None, **ps): if flagdown(userid, flag.STAR, tid=tid, rid=rid) is False : raise HZActionError("Have not star it") return dict()
def comment_reply_exists(replyid, **ps) : reply = getconn().get(u"SELECT rid FROM herzog_reply WHERE rid=%s", replyid) if not reply : raise HZActionError("No such reply") return True
def reply_topic_exists(tid, **ps) : topic = getconn().get(u"SELECT tid FROM herzog_topic WHERE tid=%s", tid) if not topic : raise HZActionError("No such topic") return True