def updateTag(postRequest): ''' description: set tag attribution input: dict - post request output: 0 ''' # 后端验证 pattern = r'^\w+$' if not re.match(pattern, postRequest["newenglish"]): return 1 if postRequest['english'] != postRequest['newenglish'] and db.exist_db( "tags", {'english': postRequest["newenglish"]}) == True: return 2 chinese = postRequest['chinese'] postRequest['english'] = postRequest['newenglish'] # 删除前端传入的其他参数 keyList = ['english', 'img', 'class'] postRequest = dict((key, postRequest[key] if key in postRequest else "") for key in keyList) db.update_db("tags", postRequest, {'chinese': chinese}) return 0
def updateComment(postRequest): cid = postRequest['id'] keyList = ['sendemail', 'show', 'ad'] postRequest = dict((key, postRequest[key] if key in postRequest else "") for key in keyList) db.update_db("comments", postRequest, {'id': cid}) return 0
def subtractTag(chinese): ''' description: tag num subtract 1 input: tag id(chinese) output: 0 ''' if db.exist_db("tags", {"chinese": chinese}) == True: cnt = db.query_db('select cnt from tags where chinese="{}"', chinese, one=True)['cnt'] cnt = str(int(cnt) - 1) db.update_db("tags", {'cnt': cnt}, {'chinese': chinese}) if int(cnt) <= 0: deleteTag(chinese)
def updateFriends(postRequest): oldname = postRequest['oldname'] if not re.match(r'^[0-9]+$', postRequest['idx']): return 1 if oldname != postRequest['name'] and db.exist_db( "friends", {'name': postRequest['name']}) == True: return 2 keyList = ['url', 'name', 'idx'] postRequest = dict((key, postRequest[key] if key in postRequest else "") for key in keyList) db.update_db("friends", postRequest, {'name': oldname}) return 0
def setSite(postRequest): current_app.logger.debug(postRequest) siteConfig = getSiteConfigDict() password = siteConfig['password'] sid = postRequest['sid'] value = postRequest['value'] if sid == 'password' and password != value: import hashlib value = hashlib.md5(value.encode()).hexdigest() db.update_db("siteConfig", {"value": value}, {"sid": sid}) return 0
def updateGood(postRequest): # 后端验证 pattern = [r'^[0-9]{4}-[0-9]{2}-[0-9]{2}$', r'^[0-9]+$'] if not (re.match(pattern[0], postRequest["time"]) and re.match(pattern[1], postRequest['value1'])): return 1 gid = postRequest['gid'] keyList = ["name", "abstruct", "time", "img", "value1", "value2", "value3", "value4", "value5", "show"] postRequest = dict( (key, postRequest[key] if key in postRequest else "")for key in keyList) db.update_db("goods", postRequest, {'gid': gid}) return 0
def updatePage(postRequest): current_app.logger.debug(postRequest) oldurl = postRequest['oldurl'] url = postRequest['url'] if url != oldurl and db.exist_db('pages', {'url': url}): # 重复url return 1 if not (re.match(r'^[0-9]+$', postRequest["idx"])): return 2 keyList = ['url', 'title', 'idx', 'show'] postRequest = dict((key, postRequest[key] if key in postRequest else "") for key in keyList) db.update_db("pages", postRequest, {'url': oldurl}) return 0
def addTag(chinese): ''' description: tag num plus 1 input: tag id(chinese) output: 0 ''' if db.exist_db("tags", {"chinese": chinese}) == True: cnt = db.query_db('select cnt from tags where chinese="{}"', chinese, one=True)['cnt'] cnt = str(int(cnt) + 1) db.update_db("tags", {'cnt': cnt}, {'chinese': chinese}) else: db.insert_db( "tags", { "chinese": chinese, "english": encode(chinese), "cnt": "1", "img": "", "class": "" }) return 0
def updatePost(postRequest): current_app.logger.debug(postRequest) oldurl = postRequest["oldurl"] # 后端验证 pattern = [ r'^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$', r'^[0-9]+$', r'^[\w\-\.,@?^=%&:~\+#]+(?:\/[\w\-\.,@?^=%&:~\+#]+)*$' ] if not (re.match(pattern[0], postRequest["time"]) and re.match(pattern[0], postRequest["updatetime"]) and re.match(pattern[1], postRequest["view"]) and re.match(pattern[2], postRequest["url"])): return 1 if oldurl != postRequest['url'] and db.exist_db( "posts", {'url': postRequest["url"]}) == True: return 2 if postRequest['tags'] == '': postRequest['tags'] = '无标签' from OBlog.markdown import render_markdown import json from ..search.main import getKeywords postRequest['html'] = render_markdown(postRequest['raw']) postRequest['keywords'] = postRequest['tags'] + \ getKeywords(postRequest['title'] + postRequest['raw']) # postRequest['searchdict1'] = json.dumps( # getCntDict(postRequest["title"] + " " + postRequest['tags'])) # postRequest['searchdict2'] = json.dumps( # getCntDict(postRequest['abstruct'] + " " + postRequest["raw"])) postRequest['searchdict1'] = postRequest['searchdict2'] = "" # 更新标签 from ..tags.main import getTagsOfPost, tagSplit, addTag, subtractTag oldtags = getTagsOfPost(oldurl) newtags = tagSplit(postRequest['tags']) alltags = set(oldtags + newtags) for tag in alltags: if tag in oldtags and tag not in newtags: subtractTag(tag) elif tag not in oldtags and tag in newtags: addTag(tag) if oldurl != postRequest['url']: # update comments from ..comments.main import updateCommentUrl updateCommentUrl({ 'url': 'post/' + postRequest['url'], 'oldurl': 'post/' + oldurl }) # 去除前导零 postRequest["view"] = str(int(postRequest["view"])) # 删除前端传入的其他参数 keyList = [ 'url', 'title', 'time', 'updatetime', 'view', 'tags', 'abstruct', 'raw', 'html', 'keywords', 'searchdict1', 'searchdict2', 'published', 'img' ] postRequest = dict((key, postRequest[key] if key in postRequest else "") for key in keyList) db.update_db("posts", postRequest, {'url': oldurl}) return 0
def updateCommentUrl(postRequest): db.update_db("comments", {'url': postRequest['url']}, { 'url': postRequest['oldurl']}) return 0