def create_user(post_data): ''' Create the user. The code used if `False`. 11: standsfor invalid username. 21: standsfor invalide E-mail. 91: standsfor unkown reson. ''' out_dic = {'success': False, 'code': '00'} if not tools.check_username_valid(post_data['user_name']): out_dic['code'] = '11' return out_dic if not tools.check_email_valid(post_data['user_email']): out_dic['code'] = '21' return out_dic try: TabMember.create(uid=tools.get_uuid(), user_name=post_data['user_name'], user_pass=tools.md5(post_data['user_pass']), user_email=post_data['user_email'], role=post_data.get('role', '1000'), time_create=tools.timestamp(), time_update=tools.timestamp(), time_reset_passwd=tools.timestamp(), time_login=tools.timestamp(), time_email=tools.timestamp()) out_dic['success'] = True except: out_dic['code'] = '91' return out_dic
def add_meta(uid, data_dic, extinfo=None): if extinfo is None: extinfo = {} if len(uid) < 4: return False title = data_dic['title'].strip() if len(title) < 2: return False TabPost.create( uid=uid, title=title, keywords='', time_create=tools.timestamp(), time_update=tools.timestamp(), create_time=tools.timestamp(), date=datetime.now(), cnt_md=data_dic['cnt_md'].strip(), memo=data_dic['memo'] if 'memo' in data_dic else '', logo=data_dic['logo'].strip(), order=data_dic['order'] if 'order' in data_dic else '', cnt_html=tools.markdown2html(data_dic['cnt_md']), view_count=0, extinfo=extinfo, user_name=data_dic['user_name'], valid=data_dic['valid'] if 'valid' in data_dic else 1, kind=data_dic['kind'], ) return uid
def insert_data(self, post_data): title = post_data['title'].strip() if len(title) < 2: return False uu = self.get_by_wiki(title) if uu: self.update(uu.uid, post_data) return cnt_html = tools.markdown2html(post_data['cnt_md']) entry = self.tab.create( # No page slug should startswith '_' uid=post_data['uid'] if 'uid' in post_data else '_' + tools.get_uu8d(), title=title, date=datetime.datetime.now(), cnt_html=cnt_html, time_create=post_data['time_create'] if 'time_craete' in post_data else tools.timestamp(), user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md']), time_update=tools.timestamp(), view_count=1, kind=post_data['kind'] if 'kind' in post_data else '1', ) return (entry.uid)
def __create_rec(*args, **kwargs): ''' Create the record. ''' uid = args[0] kind = args[1] post_data = kwargs['post_data'] try: TabWiki.create( uid=uid, title=post_data['title'].strip(), date=datetime.datetime.now(), cnt_html=tools.markdown2html(post_data['cnt_md']), time_create=tools.timestamp(), user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md']), time_update=tools.timestamp(), view_count=1, kind=kind, # 1 for wiki, 2 for page ) return True except Exception as err: print(repr(err)) return False
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 create_post(post_uid, post_data): ''' create the post. ''' title = post_data['title'].strip() if len(title) < 2: return False cur_rec = MPost.get_by_uid(post_uid) if cur_rec: return False entry = TabPost.create( title=title, date=datetime.now(), cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md'].strip()), cnt_html=tools.markdown2html(post_data['cnt_md']), uid=post_uid, time_create=(post_data['time_create'] if 'time_create' in post_data else tools.timestamp()), time_update=(post_data['time_update'] if 'time_update' in post_data else tools.timestamp()), user_name=post_data['user_name'], view_count=post_data['view_count'] if 'view_count' in post_data else 1, logo=post_data['logo'], memo=post_data['memo'] if 'memo' in post_data else '', order=post_data['order'] if 'order' in post_data else '', keywords=post_data['keywords'] if 'keywords' in post_data else '', extinfo=post_data['extinfo'] if 'extinfo' in post_data else {}, kind=post_data['kind'] if 'kind' in post_data else '1', valid=1) return entry.uid
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 insert_data(self, id_post, post_data): title = post_data['title'].strip() if len(title) < 2: return False cur_rec = self.get_by_id(id_post) if cur_rec: return (False) entry = g_Post.create( title=title, date=datetime.datetime.now(), cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md']), cnt_html=tools.markdown2html(post_data['cnt_md']), uid=id_post, time_create=post_data['time_create'] if 'time_create' in post_data else tools.timestamp(), time_update=post_data['time_update'] if 'time_update' in post_data else tools.timestamp(), user_name=post_data['user_name'], view_count=post_data['view_count'] if 'view_count' in post_data else 1, logo=post_data['logo'], keywords=post_data['keywords'] if 'keywords' in post_data else '', extinfo=post_data['extinfo'] if 'extinfo' in post_data else {}, kind=post_data['kind'] if 'kind' in post_data else '1', valid=1, ) return (entry.uid)
def create_user(post_data): out_dic = {'success': False, 'code': '00'} if tools.check_username_valid(post_data['user_name']): pass else: out_dic['code'] = '11' return out_dic if tools.check_email_valid(post_data['user_email']): pass else: out_dic['code'] = '21' return out_dic if 'role' in post_data: role = post_data['role'] else: role = '1000' TabMember.create(uid=tools.get_uuid(), user_name=post_data['user_name'], user_pass=tools.md5(post_data['user_pass']), user_email=post_data['user_email'], role=role, time_create=tools.timestamp(), time_update=tools.timestamp(), time_reset_passwd=tools.timestamp(), time_login=tools.timestamp(), time_email=tools.timestamp()) out_dic['success'] = True return out_dic
def add_meta(uid, data_dic, extinfo={}): if len(uid) < 4: return False title = data_dic['title'].strip() if len(title) < 2: return False g_Post.create( uid=uid, title=title, keywords=','.join( [x.strip() for x in data_dic['keywords'].split(',')]), time_create=tools.timestamp(), time_update=tools.timestamp(), create_time=tools.timestamp(), date=datetime.now(), cnt_md=data_dic['cnt_md'].strip(), logo=data_dic['logo'].strip(), cnt_html=tools.markdown2html(data_dic['cnt_md']), view_count=0, extinfo=extinfo, user_name=data_dic['user_name'], valid=data_dic['valid'] if 'valid' in data_dic else 1, kind=data_dic['kind'], ) 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: ############################## 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 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: # ToDo: should not do this. Not for 's' if DB_CFG['kind'] == 's': 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'], 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_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 create_user(post_data, extinfo=None): ''' Create the user. The code used if `False`. 11: invalid username. 21: invalide E-mail. 31: E-mail exists.. 91: unkown reason. ''' out_dic = {'success': False, 'code': '00'} if post_data['user_name'].startswith('_'): ''' the user_name startwith with ``_``, ONLY used for inner, not for login. ''' pass elif not tools.check_username_valid(post_data['user_name']): out_dic['code'] = '11' return out_dic if not tools.check_email_valid(post_data['user_email']): out_dic['code'] = '21' return out_dic if MUser.get_by_email(post_data['user_email']): out_dic['code'] = '31' return out_dic if extinfo is None: extinfo = {} try: TabMember.create( uid=tools.get_uuid(), user_name=post_data['user_name'], user_pass=tools.md5(post_data['user_pass']), user_email=post_data['user_email'], role='1000', # ‘1000' as default role. time_create=tools.timestamp(), time_update=tools.timestamp(), time_reset_passwd=tools.timestamp(), time_login=tools.timestamp(), time_email=tools.timestamp(), extinfo=extinfo, ) out_dic['success'] = True except Exception as err: print(repr(err)) out_dic['code'] = '91' return out_dic
def reset_password(self): ''' Do reset password :return: ''' post_data = self.get_post_data() if 'email' in post_data: userinfo = MUser.get_by_email(post_data['email']) if tools.timestamp() - userinfo.time_reset_passwd < 70: self.set_status(400) kwd = { 'info': '两次重置密码时间应该大于1分钟', 'link': '/user/reset-password', } self.render('misc/html/404.html', kwd=kwd, userinfo=self.userinfo) return False if userinfo: timestamp = tools.timestamp() passwd = userinfo.user_pass username = userinfo.user_name hash_str = tools.md5(username + str(timestamp) + passwd) url_reset = '{0}/user/reset-passwd?u={1}&t={2}&p={3}'.format( config.SITE_CFG['site_url'], username, timestamp, hash_str) email_cnt = '''<div>请查看下面的信息,并<span style="color:red">谨慎操作</span>:</div> <div>您在"{0}"网站({1})申请了密码重置,如果确定要进行密码重置,请打开下面链接:</div> <div><a href={2}>{2}</a></div> <div>如果无法确定本信息的有效性,请忽略本邮件。</div>'''.format(config.SMTP_CFG['name'], config.SITE_CFG['site_url'], url_reset) if send_mail([userinfo.user_email], "{0}|密码重置".format(config.SMTP_CFG['name']), email_cnt): MUser.update_time_reset_passwd(username, timestamp) self.set_status(200) logger.info('password has been reset.') return True else: self.set_status(400) return False else: self.set_status(400) return False else: self.set_status(400) return False
def _copy_user(self, post_data): try: g_Member.create(uid=post_data['uid'], user_name=post_data['user_name'], user_pass=post_data['user_pass'], user_email=post_data['user_email'], role=post_data['role'], time_create=tools.timestamp(), time_update=tools.timestamp(), time_reset_passwd=tools.timestamp(), time_login=tools.timestamp(), time_email=tools.timestamp()) except: print(post_data) return True
def update_time_login(u_name): ''' Update the login time for user. ''' entry = TabMember.update(time_login=tools.timestamp()).where( TabMember.user_name == u_name) entry.execute()
def set_sendemail_time(uid): ''' Set the time that send E-mail to user. ''' entry = TabMember.update( time_email=tools.timestamp(), ).where(TabMember.uid == uid) entry.execute()
def __get_diff_recent(): ''' Generate the difference of posts. recently. ''' diff_str = '' for key in router_post: recent_posts = MPost.query_recent_edited(tools.timestamp() - TIME_LIMIT, kind=key) for recent_post in recent_posts: hist_rec = MPostHist.get_last(recent_post.uid) if hist_rec: raw_title = hist_rec.title new_title = recent_post.title infobox = diff_table(raw_title, new_title) diff_str = diff_str + ''' <h2 style="color:red;font-size:larger;font-weight:70;">TITLE: {0}</h2> '''.format(recent_post.title) + infobox infobox = diff_table(hist_rec.cnt_md, recent_post.cnt_md) diff_str = diff_str + '<h3>CONTENT:{0}</h3>'.format( recent_post.title) + infobox + '</hr>' else: continue return diff_str
def get_diff_str(*args): mpost = MPost() mposthist = MPostHist() diff_str = '' for key in router_post.keys(): recent_posts = mpost.query_recent_edited(tools.timestamp() - time_limit, kind=key) for recent_post in recent_posts: hist_rec = mposthist.get_last(recent_post.uid) if hist_rec: raw_title = hist_rec.title new_title = recent_post.title infobox = diff_table(raw_title, new_title) # infobox = test[start:end] + '</table>' # if ('diff_add' in infobox) or ('diff_chg' in infobox) or ('diff_sub' in infobox): diff_str = diff_str + '<h2 style="color:red; font-size:larger; font-weight:70;">TITLE: {0}</h2>'.format( recent_post.title) + infobox infobox = diff_table(hist_rec.cnt_md, recent_post.cnt_md) diff_str = diff_str + '<h3>CONTENT:{0}</h3>'.format( recent_post.title) + infobox + '</hr>' else: continue return diff_str
def __get_page_review(email_cnt, idx): ''' Review for pages. ''' recent_posts = MWiki.query_recent_edited(tools.timestamp() - TIME_LIMIT) for recent_post in recent_posts: hist_rec = MWikiHist.get_last(recent_post.uid) if hist_rec: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format( idx, recent_post.user_name, recent_post.title, os.path.join(SITE_CFG['site_url'], 'wiki', recent_post.title)) email_cnt = email_cnt + foo_str else: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format( idx, recent_post.user_name, recent_post.title, os.path.join(SITE_CFG['site_url'], 'wiki', recent_post.title)) email_cnt = email_cnt + foo_str idx = idx + 1 return email_cnt, idx
def __get_post_review(email_cnt, idx): ''' Review for posts. ''' for key in router_post: recent_posts = MPost.query_recent_edited(tools.timestamp() - TIME_LIMIT, kind=key) for recent_post in recent_posts: hist_rec = MPostHist.get_last(recent_post.uid) editor_name = recent_post.extinfo[ 'def_editor_name'] if 'def_editor_name' in recent_post.extinfo else recent_post.user_name if hist_rec: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format( idx, editor_name, recent_post.title, os.path.join(SITE_CFG['site_url'], router_post[key], recent_post.uid)) email_cnt = email_cnt + foo_str else: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format( idx, editor_name, recent_post.title, os.path.join(SITE_CFG['site_url'], router_post[key], recent_post.uid)) email_cnt = email_cnt + foo_str idx = idx + 1 return email_cnt, idx
def update_cnt(uid, post_data): entry = g_PostHist.update( user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md']), time_update=tools.timestamp(), ).where(g_PostHist.uid == uid) entry.execute()
def check_tag(): ''' Checking the post of error tags. ''' print('Checking tag error: ') tstr = '' idx = 1 for kind in config.router_post.keys(): posts = MPost.query_all(kind=kind, limit=20000) for post in posts: p_catinfo = None post2catinfo = MPost2Catalog.get_first_category(post.uid) if post2catinfo: catinfo = MCategory.get_by_uid(post2catinfo.tag_id) if catinfo: p_catinfo = MCategory.get_by_uid(catinfo.pid) if post.extinfo.get('def_cat_pid') and post.extinfo.get( 'gcat0') and p_catinfo: pass else: the_url0 = '{site_url}/{kind_url}/{uid}'.format( site_url=config.SITE_CFG['site_url'], kind_url=config.router_post[post.kind], uid=post.uid) the_url = '{site_url}/{kind_url}/_edit/{uid}'.format( site_url=config.SITE_CFG['site_url'], kind_url=config.router_post[post.kind], uid=post.uid) the_url2 = '{site_url}/{kind_url}/_edit_kind/{uid}'.format( site_url=config.SITE_CFG['site_url'], kind_url=config.router_post[post.kind], uid=post.uid) req = requests.get(the_url0) if req.status_code == 200: pass else: print(the_url0) tstr = tstr + DT_STR.format( idx=str(idx).zfill(2), url0=the_url0, code=req.status_code, edit_link=the_url, edit_tag_link=the_url2, ) idx = idx + 1 time_local = time.localtime(timestamp()) with open( 'xx_err_tag_{d}.html'.format( d=str(time.strftime("%Y_%m_%d", time_local))), 'w') as fileo: fileo.write(HTML_TMPL.format(cnt=tstr)) print('Checking 200 finished.')
def add_or_update(self, post_data): print(post_data) entry = e_Layout.create( uid=tools.get_uu8d(), title='', post_id=post_data['map'], user_id=post_data['user'], json=post_data['geojson'] if 'geojson' in post_data else '', lon=float(post_data['lon']), lat=float(post_data['lat']), zoom=int(post_data['zoom']), marker=int(post_data['marker']) if 'marker' in post_data else 0, time_create=tools.timestamp(), time_update=tools.timestamp(), public=1, ) print(entry)
def update_cnt(uid, post_data): entry = TabWiki.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(TabWiki.uid == uid) entry.execute()
def add_meta(uid, data_dic): if len(uid) < 4: return False userip = data_dic['userip'].strip() if len(userip) < 2: return False TabReferrer.create( uid=uid, media=data_dic['media'], terminal=data_dic['terminal'], userip=userip, # usercity=data_dic['usercity'], kind=data_dic['kind'], time_create=tools.timestamp(), time_update=tools.timestamp(), ) return uid
def create_wiki_history(raw_data, user_info): entry = TabWikiHist.create(uid=tools.get_uuid(), title=raw_data.title, wiki_id=raw_data.uid, user_name=user_info.user_name, cnt_md=raw_data.cnt_md, time_update=tools.timestamp()) return entry.uid
def create_replyid(pid, rid): uid = tools.get_uuid() TabReplyid.create( uid=uid, reply0=pid, reply1=rid, time_create=tools.timestamp(), )
def reset_password(self): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) if 'email' in post_data: userinfo = self.muser.get_by_email(post_data['email'][0]) if tools.timestamp() - userinfo.time_reset_passwd < 70: self.set_status(400) kwd = { 'info': '两次重置密码时间应该大于1分钟', } self.render('html/404.html', kwd=kwd, userinfo=self.userinfo) return False if userinfo: timestamp = tools.timestamp() passwd = userinfo.user_pass username = userinfo.user_name hash_str = tools.md5(username + str(timestamp) + passwd) url_reset = '{0}/user/reset-passwd?u={1}&t={2}&p={3}'.format( config.site_url, username, timestamp, hash_str) email_cnt = ''' <div>请查看下面的信息,并<span style="color:red">谨慎操作</span>:</div> <div>您在"{0}"网站({1})申请了密码重置,如果确定要进行密码重置,请打开下面链接:</div> <div><a href={2}>{2}</a></div> <div>如果无法确定本信息的有效性,请忽略本邮件。</div> '''.format(config.smtp_cfg['name'], config.site_url, url_reset) if send_mail([userinfo.user_email], "{0}|密码重置".format(config.smtp_cfg['name']), email_cnt): self.muser.update_time_reset_passwd(username, timestamp) self.set_status(200) return True else: self.set_status(400) return False else: self.set_status(400) return False else: self.set_status(400) return False
def reset_password(self): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) if 'email' in post_data: userinfo = self.muser.get_by_email(post_data['email'][0]) if tools.timestamp() - userinfo.reset_passwd_timestamp < 70: self.set_status(400) kwd = { 'info': '两次重置密码时间应该大于1分钟', } self.render('html/404.html', kwd=kwd, userinfo = self.userinfo) return False if userinfo: timestamp = tools.timestamp() passwd = userinfo.user_pass username = userinfo.user_name hash_str = tools.md5(username + str(timestamp) + passwd) url_reset = '{0}/user/reset-passwd?u={1}&t={2}&p={3}'.format(config.site_url, username, timestamp, hash_str) email_cnt = ''' <div>请查看下面的信息,并<span style="color:red">谨慎操作</span>:</div> <div>您在"{0}"网站({1})申请了密码重置,如果确定要进行密码重置,请打开下面链接:</div> <div><a href={2}>{2}</a></div> <div>如果无法确定本信息的有效性,请忽略本邮件。</div> '''.format(config.site_name, config.site_url, url_reset) if send_mail([userinfo.user_email], "{0}|密码重置".format(config.site_name), email_cnt): self.muser.update_reset_passwd_timestamp(username, timestamp) self.set_status(200) return True else: self.set_status(400) return False else: self.set_status(400) return False else: self.set_status(400) return False
def update_cnt(uid, post_data): ''' Update the content by ID. ''' entry = TabPostHist.update( user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md']), time_update=tools.timestamp(), ).where(TabPostHist.uid == uid) entry.execute()
def add_json(self, json_uid, user_id, geojson): current_count = e_Json.select().where(e_Json.uid == json_uid).count() if current_count > 0: cur_record = self.get_by_id(json_uid) entry = e_Json.update( json=geojson, time_update=tools.timestamp(), ).where(e_Json.uid == cur_record.uid) entry.execute() else: entry = e_Json.create( uid=json_uid, title='', # app=app_id, user_id=user_id, json=geojson, time_create=tools.timestamp(), time_update=tools.timestamp(), public=1, )
def update(self, uid, post_data): cnt_html = tools.markdown2html(post_data['cnt_md'][0]) entry = CabWiki.update( title=post_data['title'][0], date=datetime.datetime.now(), cnt_html=cnt_html, user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md'][0]), time_update=tools.timestamp(), ).where(CabWiki.uid == uid) entry.execute()
def insert_data(self, post_data): title = post_data['title'][0] uu = self.get_by_wiki(title) if uu is None: pass else: return (False) cnt_html = tools.markdown2html(post_data['cnt_md'][0]) entry = CabWiki.create( title=post_data['title'][0], date=datetime.datetime.now(), cnt_html=cnt_html, uid=tools.get_uu8d(), time_create=tools.timestamp(), user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md'][0]), time_update=tools.timestamp(), view_count=1, ) return (entry.uid)
def insert_data(self, post_data): uid = tools.get_uuid() try: CabReply.create( uid=uid, user_name=post_data['user_name'], create_user_id=post_data['user_id'], timestamp=tools.timestamp(), date=datetime.datetime.now(), cnt_md=post_data['cnt_md'][0], cnt_html=tools.markdown2html(post_data['cnt_md'][0]), vote=0, ) return (uid) except: return False
def gen_passwd(self): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) userinfo = self.muser.get_by_id(post_data['u'][0]) sub_timestamp = int(post_data['t'][0]) cur_timestamp = tools.timestamp() if cur_timestamp - sub_timestamp < 600 and cur_timestamp > sub_timestamp: pass else: kwd = { 'info': '密码重置已超时!', } self.set_status(400) self.render('html/404.html', kwd=kwd, userinfo = self.userinfo) hash_str = tools.md5(userinfo.user_name + post_data['t'][0] + userinfo.user_pass) if hash_str == post_data['p'][0]: pass else: kwd = { 'info': '密码重置验证出错!', } self.set_status(400) self.render('html/404.html', kwd=kwd, userinfo = self.userinfo,) new_passwd = tools.get_uu8d() self.muser.update_pass(userinfo.user_name, new_passwd) kwd = { 'user_name': userinfo.user_name, 'new_pass': new_passwd, } self.render('{0}/{1}/show_pass.html'.format(self.tmpl_name, self.tmpl_router), cfg = config.cfg, kwd=kwd, userinfo = self.userinfo,)
def update(self, uid, post_data, update_time=False): if 'id_spec' in post_data: id_spec = post_data['id_spec'][0] else: id_spec = 0 if 'src_type' in post_data and post_data['src_type'][0] == '1': cnt_html = tools.rst2html(post_data['cnt_md'][0]) else: cnt_html = tools.markdown2html(post_data['cnt_md'][0]) if update_time: entry = CabReply.update( title=post_data['title'][0], date=datetime.datetime.now(), cnt_html=cnt_html, user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md'][0]), time_update=tools.timestamp(), id_spec=id_spec, logo=post_data['logo'][0], keywords=post_data['keywords'][0], src_type=post_data['src_type'][0] if ('src_type' in post_data) else 0 ).where(CabReply.uid == uid) else: entry = CabReply.update( title=post_data['title'][0], cnt_html=cnt_html, user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md'][0]), id_spec=id_spec, logo=post_data['logo'][0], keywords=post_data['keywords'][0], src_type=post_data['src_type'][0] if ('src_type' in post_data) else 0 ).where(CabReply.uid == uid) entry.execute()