def update(self, uid, post_data, update_time=False): title = post_data['title'].strip() if len(title) < 2: return False cnt_html = tools.markdown2html(post_data['cnt_md']) try: if update_time: entry2 = g_Post.update( date=datetime.datetime.now(), time_create = tools.timestamp(), ).where(g_Post.uid == uid) entry2.execute() except: pass cur_rec = self.get_by_id(uid) entry = g_Post.update( title=title, cnt_html=cnt_html, user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md'].strip()), logo=post_data['logo'], keywords=post_data['keywords'] if 'keywords' in post_data else '', kind=post_data['kind'] if 'kind' in post_data else 1, extinfo=post_data['extinfo'] if 'extinfo' in post_data else cur_rec.extinfo, time_update= tools.timestamp(), valid=1, ).where(g_Post.uid == uid) entry.execute()
def modify_meta(uid, data_dic, extinfo={}): ''' 手工修改的。 :param uid: :param data_dic: :return: ''' title = data_dic['title'].strip() if len(title) < 2: return False cur_info = MPost.get_by_uid(uid) if cur_info: ############################## if DB_CFG['kind'] == 's': entry = g_Post.update( title=title, user_name=data_dic['user_name'], keywords='', time_create=tools.timestamp(), time_update=tools.timestamp(), date=datetime.now(), cnt_md=data_dic['cnt_md'], logo=data_dic['logo'], order=data_dic['order'], cnt_html=tools.markdown2html(data_dic['cnt_md']), valid=data_dic['valid'], ).where(g_Post.uid == uid) entry.execute() else: cur_extinfo = cur_info.extinfo # Update the extinfo, Not replace for key in extinfo: cur_extinfo[key] = extinfo[key] entry = g_Post.update( title=title, user_name=data_dic['user_name'], keywords='', time_create=tools.timestamp(), time_update=tools.timestamp(), date=datetime.now(), cnt_md=data_dic['cnt_md'], logo=data_dic['logo'], order=data_dic['order'] if 'order' in data_dic else '', cnt_html=tools.markdown2html(data_dic['cnt_md']), extinfo=cur_extinfo, valid=data_dic['valid'], ).where(g_Post.uid == uid) entry.execute() else: return MPost.add_meta(uid, data_dic, extinfo) return uid
def update_view_count_by_uid(self, uid): entry = g_Post.update(view_count=g_Post.view_count + 1).where(g_Post.uid == uid) try: entry.execute() return True except: return False
def update_jsonb(uid, extinfo): cur_extinfo = MPost.get_by_uid(uid).extinfo for key in extinfo: cur_extinfo[key] = extinfo[key] entry = g_Post.update(extinfo=cur_extinfo, ).where(g_Post.uid == uid) entry.execute() return uid
def __update_rating(uid, rating): ''' :param uid: :param rating: :return: ''' entry = g_Post.update(rating=rating).where(g_Post.uid == uid) entry.execute()
def __update_keywords(uid, inkeywords): ''' :param uid: :param inkeywords: :return: ''' entry = g_Post.update(keywords=inkeywords).where(g_Post.uid == uid) entry.execute()
def update_cnt(self, uid, post_data): entry = g_Post.update( cnt_html=tools.markdown2html(post_data['cnt_md']), user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md']), time_update = tools.timestamp(), ).where(g_Post.uid == uid) entry.execute()
def __update_kind(uid, kind): ''' update the kind of post. :param uid: :param kind: :return: ''' entry = g_Post.update(kind=kind, ).where(g_Post.uid == uid) entry.execute() return True
def __update_view_count(uid): ''' :param uid: :return: ''' entry = g_Post.update(view_count=g_Post.view_count + 1).where(g_Post.uid == uid) try: entry.execute() return True except: return False
def update_cnt(uid, post_data): ''' :param uid: :param post_data: :return: ''' entry = g_Post.update( cnt_html=tools.markdown2html(post_data['cnt_md']), user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md'].strip()), time_update=tools.timestamp(), ).where(g_Post.uid == uid) entry.execute()
def modify_init(uid, data_dic): ''' 命令行更新的 :param uid: :param data_dic: :return: ''' postinfo = MPost.get_by_uid(uid) entry = g_Post.update( time_update=tools.timestamp(), date=datetime.now(), kind=data_dic['kind'] if 'kind' in data_dic else postinfo.kind, keywords=data_dic['keywords'] if 'keywords' in data_dic else postinfo.keywords, ).where(g_Post.uid == uid) entry.execute() return uid
def modify_meta(uid, data_dic, extinfo={}): ''' 手工修改的。 :param uid: :param data_dic: :return: ''' title = data_dic['title'].strip() if len(title) < 2: return False cur_info = MPost.get_by_uid(uid) if cur_info: cur_extinfo = cur_info.extinfo # Update the extinfo, Not replace for key in extinfo: cur_extinfo[key] = extinfo[key] entry = g_Post.update( title=title, user_name=data_dic['user_name'], keywords=','.join([ x.strip() for x in data_dic['keywords'].strip().strip(',').split(',') ]), time_create=tools.timestamp(), time_update=tools.timestamp(), date=datetime.now(), cnt_md=data_dic['cnt_md'], logo=data_dic['logo'], cnt_html=tools.markdown2html(data_dic['cnt_md']), extinfo=cur_extinfo, valid=data_dic['valid'], ).where(g_Post.uid == uid) entry.execute() else: entry = MPost.add_meta(uid, data_dic, extinfo) return entry return uid
def update_kind(self, uid, kind): entry = g_Post.update( kind = kind ).where(g_Post.uid == uid) entry.execute()
def update_rating(self, uid, rating): entry = g_Post.update( rating = rating ).where(g_Post.uid == uid) entry.execute()
def update_keywords(self, uid, inkeywords): entry = g_Post.update(keywords=inkeywords).where(g_Post.uid == uid) entry.execute()
def update_order(uid, order): entry = g_Post.update( order=order ).where(g_Post.uid == uid) entry.execute()