def update(uid, post_data, update_time=False): ''' update the infor. ''' title = post_data['title'].strip() if len(title) < 2: return False cnt_html = tools.markdown2html(post_data['cnt_md']) try: if update_time: entry2 = TabPost.update( date=datetime.now(), time_create=tools.timestamp()).where(TabPost.uid == uid) entry2.execute() except: pass cur_rec = MPost.get_by_uid(uid) entry = TabPost.update( title=title, user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md'].strip()), memo=post_data['memo'] if 'memo' in post_data else '', cnt_html=cnt_html, logo=post_data['logo'], order=post_data['order'] if 'order' in post_data else '', 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(TabPost.uid == uid) entry.execute()
def modify_meta(uid, data_dic, extinfo=None): ''' 手工修改的。 :param uid: :param data_dic: :return: ''' if extinfo is None: extinfo = {} 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 = TabPost.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'], memo=data_dic['memo'] if 'memo' in data_dic else '', logo=data_dic['logo'], order=data_dic['order'], cnt_html=tools.markdown2html(data_dic['cnt_md']), valid=data_dic['valid'] ).where(TabPost.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 = TabPost.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'], memo=data_dic['memo'] if 'memo' in data_dic else '', 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(TabPost.uid == uid) entry.execute() else: return MPost.add_meta(uid, data_dic, extinfo) return uid
def update(uid, post_data, update_time=True): ''' 参数 `update_time` , 是否更新时间。对于导入的数据,有时不需要更新。 ''' title = post_data['title'].strip() if len(title) < 2: return False cnt_html = tools.markdown2html(post_data['cnt_md']) # try: # if update_time: # entry2 = TabPost.update( # date=datetime.now(), # time_create=tools.timestamp() # ).where(TabPost.uid == uid) # entry2.execute() # except: # pass cur_rec = MPost.get_by_uid(uid) if update_time: entry = TabPost.update( title=title, user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape( post_data['cnt_md'].strip()), memo=post_data['memo'] if 'memo' in post_data else '', cnt_html=cnt_html, logo=post_data['logo'], order=post_data['order'] if 'order' in post_data else '', 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=post_data.get('valid', 1)).where(TabPost.uid == uid) else: entry = TabPost.update( title=title, user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape( post_data['cnt_md'].strip()), memo=post_data['memo'] if 'memo' in post_data else '', cnt_html=cnt_html, logo=post_data['logo'], order=post_data['order'] if 'order' in post_data else '', 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, valid=post_data.get('valid', 1)).where(TabPost.uid == uid) entry.execute()
def modify_meta(uid, data_dic, extinfo=None): ''' update meta of the rec. ''' if extinfo is None: extinfo = {} 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] cur_extinfo['def_editor_name'] = data_dic['user_name'].strip() entry = TabPost.update( title=title, # user_name=data_dic['user_name'], keywords='', time_update=tools.timestamp(), date=datetime.now(), cnt_md=data_dic['cnt_md'], memo=data_dic['memo'] if 'memo' in data_dic else '', 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(TabPost.uid == uid) entry.execute() else: return MPost.add_meta(uid, data_dic, extinfo) return uid
def update_order(uid, order): ''' Update the order of the posts. ''' entry = TabPost.update( order=order ).where(TabPost.uid == uid) entry.execute()
def __update_kind(uid, kind): ''' update the kind of post. ''' entry = TabPost.update(kind=kind, ).where(TabPost.uid == uid) entry.execute() return True
def __update_rating(uid, rating): ''' Update the rating for post. ''' entry = TabPost.update( rating=rating ).where(TabPost.uid == uid) entry.execute()
def __update_keywords(uid, inkeywords): ''' :param uid: :param inkeywords: :return: ''' entry = TabPost.update(keywords=inkeywords).where(TabPost.uid == uid) entry.execute()
def __update_rating(uid, rating): ''' :param uid: :param rating: :return: ''' entry = TabPost.update(rating=rating).where(TabPost.uid == uid) entry.execute()
def update_jsonb(uid, extinfo): cur_extinfo = MPost.get_by_uid(uid).extinfo for key in extinfo: cur_extinfo[key] = extinfo[key] entry = TabPost.update( extinfo=cur_extinfo, ).where(TabPost.uid == uid) entry.execute() return uid
def __update_view_count(uid): ''' ''' entry = TabPost.update(view_count=TabPost.view_count + 1).where(TabPost.uid == uid) try: entry.execute() return True except: return False
def update_cnt(uid, post_data): ''' update content. ''' entry = TabPost.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(TabPost.uid == uid) entry.execute()
def __update_view_count(uid): ''' ''' entry = TabPost.update(view_count=TabPost.view_count + 1).where(TabPost.uid == uid) try: entry.execute() return True except Exception as err: print(repr(err)) return False
def update_valid(uid): ''' update valid ''' entry = TabPost.update(valid=0).where(TabPost.uid == uid) try: entry.execute() return True except: return False
def modify_init(uid, data_dic): ''' update when init. ''' postinfo = MPost.get_by_uid(uid) entry = TabPost.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(TabPost.uid == uid) entry.execute() return uid
def nullify(uid): ''' 使无效 ''' entry = TabPost.update(valid=0).where(TabPost.uid == uid) try: entry.execute() return True except Exception as err: print(repr(err)) return False
def nullify(uid): ''' 使无效 ''' entry = TabPost.update( valid=0 ).where(TabPost.uid == uid) try: entry.execute() return True except: return False
def update_order(uid, order): entry = TabPost.update( order=order ).where(TabPost.uid == uid) entry.execute()
def __update_keywords(uid, inkeywords): ''' Update with keywords. ''' entry = TabPost.update(keywords=inkeywords).where(TabPost.uid == uid) entry.execute()
def update_field(uid, post_id=None): if post_id: entry = TabPost.update(uid=post_id).where(TabPost.uid == uid) entry.execute()