_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
31
13.1k
language
stringclasses
1 value
meta_information
dict
q5000
MPostHist.create_post_history
train
def create_post_history(raw_data): ''' Create the history of certain post. ''' uid = tools.get_uuid() TabPostHist.create( uid=uid, title=raw_data.title, post_id=raw_data.uid,
python
{ "resource": "" }
q5001
ListHandler.ajax_list_catalog
train
def ajax_list_catalog(self, catid): ''' Get posts of certain catid. In Json. 根据分类ID(catid)获取 该分类下 post 的相关信息,返回Json格式
python
{ "resource": "" }
q5002
ListHandler.ajax_kindcat_arr
train
def ajax_kindcat_arr(self, kind_sig): ''' Get the sub category. 根据kind值(kind_sig)获取相应分类,返回Json格式
python
{ "resource": "" }
q5003
ListHandler.list_catalog
train
def list_catalog(self, cat_slug, **kwargs): ''' listing the posts via category 根据分类(cat_slug)显示分类列表 ''' post_data = self.get_post_data() tag = post_data.get('tag', '') def get_pager_idx(): ''' Get the pager index. ''' cur_p = kwargs.get('cur_p') the_num = int(cur_p) if cur_p else 1 the_num = 1 if the_num < 1 else the_num return the_num current_page_num = get_pager_idx() cat_rec = MCategory.get_by_slug(cat_slug) if not cat_rec: return False num_of_cat = MPost2Catalog.count_of_certain_category(cat_rec.uid, tag=tag) page_num = int(num_of_cat / CMS_CFG['list_num']) + 1 cat_name = cat_rec.name kwd = {'cat_name': cat_name, 'cat_slug': cat_slug, 'title': cat_name, 'router': router_post[cat_rec.kind], 'current_page': current_page_num, 'kind': cat_rec.kind, 'tag': tag} # Todo: review the following codes. if self.order:
python
{ "resource": "" }
q5004
send_mail
train
def send_mail(to_list, sub, content, cc=None): ''' Sending email via Python. ''' sender = SMTP_CFG['name'] + "<" + SMTP_CFG['user'] + ">" msg = MIMEText(content, _subtype='html', _charset='utf-8') msg['Subject'] = sub msg['From'] = sender msg['To'] = ";".join(to_list) if cc: msg['cc'] = ';'.join(cc) try: # Using SMTP_SSL. The
python
{ "resource": "" }
q5005
PostAjaxHandler.viewinfo
train
def viewinfo(self, postinfo): ''' View the info ''' out_json = { 'uid': postinfo.uid,
python
{ "resource": "" }
q5006
PostAjaxHandler.count_plus
train
def count_plus(self, uid): ''' Ajax request, that the view count will plus 1. ''' self.set_header("Content-Type", "application/json") output = { # ToDo: Test the following codes. # MPost.__update_view_count_by_uid(uid) else 0,
python
{ "resource": "" }
q5007
PostAjaxHandler.p_recent
train
def p_recent(self, kind, cur_p='', with_catalog=True, with_date=True): ''' List posts that recent edited, partially. ''' if cur_p == '': current_page_number = 1 else: current_page_number = int(cur_p) current_page_number = 1 if current_page_number < 1 else current_page_number pager_num = int(MPost.total_number(kind) / CMS_CFG['list_num']) kwd = { 'pager': '', 'title': 'Recent posts.',
python
{ "resource": "" }
q5008
PostAjaxHandler.j_delete
train
def j_delete(self, *args): ''' Delete the post, but return the JSON. ''' uid = args[0] current_infor = MPost.get_by_uid(uid) tslug = MCategory.get_by_uid(current_infor.extinfo['def_cat_uid']) is_deleted = MPost.delete(uid) MCategory.update_count(current_infor.extinfo['def_cat_uid']) if is_deleted: output = { 'del_info': 1, 'cat_slug': tslug.slug,
python
{ "resource": "" }
q5009
run_init_tables
train
def run_init_tables(*args): ''' Run to init tables. ''' print('--') create_table(TabPost) create_table(TabTag) create_table(TabMember) create_table(TabWiki) create_table(TabLink) create_table(TabEntity) create_table(TabPostHist) create_table(TabWikiHist) create_table(TabCollect)
python
{ "resource": "" }
q5010
gen_whoosh_database
train
def gen_whoosh_database(kind_arr, post_type): ''' kind_arr, define the `type` except Post, Page, Wiki post_type, define the templates for different kind. ''' SITE_CFG['LANG'] = SITE_CFG.get('LANG', 'zh') # Using jieba lib for Chinese. if SITE_CFG['LANG'] == 'zh' and ChineseAnalyzer: schema = Schema(title=TEXT(stored=True, analyzer=ChineseAnalyzer()), catid=TEXT(stored=True), type=TEXT(stored=True), link=ID(unique=True, stored=True), content=TEXT(stored=True, analyzer=ChineseAnalyzer())) else: schema = Schema(title=TEXT(stored=True, analyzer=StemmingAnalyzer()), catid=TEXT(stored=True), type=TEXT(stored=True), link=ID(unique=True, stored=True), content=TEXT(stored=True, analyzer=StemmingAnalyzer())) whoosh_db = 'database/whoosh' if os.path.exists(whoosh_db): create_idx = open_dir(whoosh_db)
python
{ "resource": "" }
q5011
PublishHandler.view_class2
train
def view_class2(self, fatherid=''): ''' Publishing from 2ed range category. ''' if self.is_admin(): pass else: return False kwd = {'class1str': self.format_class2(fatherid), 'parentid': '0',
python
{ "resource": "" }
q5012
MEvaluation.app_evaluation_count
train
def app_evaluation_count(app_id, value=1): ''' Get the Evalution sum. ''' return TabEvaluation.select().where(
python
{ "resource": "" }
q5013
MEvaluation.get_by_signature
train
def get_by_signature(user_id, app_id): ''' get by user ID, and app ID. ''' try: return TabEvaluation.get(
python
{ "resource": "" }
q5014
MEvaluation.add_or_update
train
def add_or_update(user_id, app_id, value): ''' Editing evaluation. ''' rec = MEvaluation.get_by_signature(user_id, app_id) if rec: entry = TabEvaluation.update(
python
{ "resource": "" }
q5015
PageAjaxHandler.view
train
def view(self, rec): ''' view the post. ''' out_json = { 'uid': rec.uid,
python
{ "resource": "" }
q5016
PageAjaxHandler.j_count_plus
train
def j_count_plus(self, slug): ''' plus count via ajax.
python
{ "resource": "" }
q5017
PageAjaxHandler.p_list
train
def p_list(self, kind, cur_p='', ): ''' List the post . ''' if cur_p == '': current_page_number = 1 else: current_page_number = int(cur_p) current_page_number = 1 if current_page_number < 1 else current_page_number pager_num = int(MWiki.total_number(kind) / CMS_CFG['list_num']) kwd = { 'pager': '', 'title': 'Recent pages.', 'kind': kind, 'current_page': current_page_number,
python
{ "resource": "" }
q5018
MUser.set_sendemail_time
train
def set_sendemail_time(uid): ''' Set the time that send E-mail to user. ''' entry = TabMember.update(
python
{ "resource": "" }
q5019
MUser.check_user
train
def check_user(user_id, u_pass): ''' Checking the password by user's ID. ''' user_count = TabMember.select().where(TabMember.uid == user_id).count() if user_count == 0: return -1
python
{ "resource": "" }
q5020
MUser.check_user_by_name
train
def check_user_by_name(user_name, u_pass): ''' Checking the password by user's name. ''' the_query = TabMember.select().where(TabMember.user_name == user_name) if the_query.count() == 0: return -1
python
{ "resource": "" }
q5021
MUser.update_pass
train
def update_pass(user_id, newpass): ''' Update the password of a user. ''' out_dic = {'success': False, 'code': '00'}
python
{ "resource": "" }
q5022
MUser.update_time_reset_passwd
train
def update_time_reset_passwd(user_name, the_time): ''' Update the time when user reset passwd. ''' entry = TabMember.update( time_reset_passwd=the_time,
python
{ "resource": "" }
q5023
MUser.update_role
train
def update_role(u_name, newprivilege): ''' Update the role of the usr. ''' entry = TabMember.update(
python
{ "resource": "" }
q5024
MUser.update_time_login
train
def update_time_login(u_name): ''' Update the login time for user. ''' entry = TabMember.update( time_login=tools.timestamp()
python
{ "resource": "" }
q5025
MUser.delete_by_user_name
train
def delete_by_user_name(user_name): ''' Delete user in the database by `user_name`. ''' try: del_count = TabMember.delete().where(TabMember.user_name == user_name)
python
{ "resource": "" }
q5026
MUser.delete
train
def delete(user_id): ''' Delele the user in the database by `user_id`. ''' try: del_count = TabMember.delete().where(TabMember.uid == user_id)
python
{ "resource": "" }
q5027
get_meta
train
def get_meta(catid, sig): ''' Get metadata of dataset via ID. ''' meta_base = './static/dataset_list' if os.path.exists(meta_base): pass else: return False pp_data = {'logo': '', 'kind': '9'} for wroot, wdirs, wfiles in os.walk(meta_base): for wdir in wdirs: if wdir.lower().endswith(sig): # Got the dataset of certain ID. ds_base = pathlib.Path(os.path.join(wroot, wdir)) for uu in ds_base.iterdir(): if uu.name.endswith('.xlsx'): meta_dic = chuli_meta('u' + sig[2:], uu) pp_data['title'] = meta_dic['title'] pp_data['cnt_md'] = meta_dic['anytext'] pp_data['user_name']
python
{ "resource": "" }
q5028
update_label
train
def update_label(signature, post_data): ''' Update the label when updating. ''' current_tag_infos = MPost2Label.get_by_uid(signature).objects() if 'tags' in post_data: pass else: return False tags_arr = [x.strip() for x in post_data['tags'].split(',')] for tag_name in tags_arr: if tag_name == '':
python
{ "resource": "" }
q5029
PostHandler.index
train
def index(self): ''' The default page of POST. ''' self.render('post_{0}/post_index.html'.format(self.kind),
python
{ "resource": "" }
q5030
PostHandler._view_or_add
train
def _view_or_add(self, uid): ''' Try to get the post. If not, to add the wiki. ''' postinfo = MPost.get_by_uid(uid)
python
{ "resource": "" }
q5031
PostHandler._to_add
train
def _to_add(self, **kwargs): ''' Used for info1. ''' if 'catid' in kwargs: catid = kwargs['catid'] return self._to_add_with_category(catid) else: if 'uid' in kwargs and MPost.get_by_uid(kwargs['uid']): # todo: # self.redirect('/{0}/edit/{1}'.format(self.app_url_name, uid)) uid = kwargs['uid'] else:
python
{ "resource": "" }
q5032
PostHandler._to_edit
train
def _to_edit(self, infoid): ''' render the HTML page for post editing. ''' postinfo = MPost.get_by_uid(infoid) if postinfo: pass else: return self.show404() if 'def_cat_uid' in postinfo.extinfo: catid = postinfo.extinfo['def_cat_uid'] elif 'gcat0' in postinfo.extinfo: catid = postinfo.extinfo['gcat0'] else: catid = '' if len(catid) == 4: pass else: catid = '' catinfo = None p_catinfo = None post2catinfo = MPost2Catalog.get_first_category(postinfo.uid) if post2catinfo: catid = post2catinfo.tag_id catinfo = MCategory.get_by_uid(catid) if catinfo: p_catinfo = MCategory.get_by_uid(catinfo.pid) kwd = { 'gcat0': catid, 'parentname': '', 'catname': '', 'parentlist': MCategory.get_parent_list(), 'userip': self.request.remote_ip, 'extinfo': json.dumps(postinfo.extinfo, indent=2, ensure_ascii=False), } if
python
{ "resource": "" }
q5033
PostHandler._gen_last_current_relation
train
def _gen_last_current_relation(self, post_id): ''' Generate the relation for the post and last post viewed. ''' last_post_id = self.get_secure_cookie('last_post_uid')
python
{ "resource": "" }
q5034
PostHandler.fetch_additional_posts
train
def fetch_additional_posts(self, uid): ''' fetch the rel_recs, and random recs when view the post. ''' cats = MPost2Catalog.query_by_entity_uid(uid, kind=self.kind) cat_uid_arr = [] for cat_rec in cats: cat_uid = cat_rec.tag_id cat_uid_arr.append(cat_uid) logger.info('info category: {0}'.format(cat_uid_arr)) rel_recs = MRelation.get_app_relations(uid, 8, kind=self.kind).objects() logger.info('rel_recs count: {0}'.format(rel_recs.count()))
python
{ "resource": "" }
q5035
PostHandler._delete
train
def _delete(self, *args, **kwargs): ''' delete the post. ''' _ = kwargs uid = args[0] current_infor = MPost.get_by_uid(uid) if MPost.delete(uid): tslug = MCategory.get_by_uid(current_infor.extinfo['def_cat_uid']) MCategory.update_count(current_infor.extinfo['def_cat_uid'])
python
{ "resource": "" }
q5036
PostHandler._chuli_cookie_relation
train
def _chuli_cookie_relation(self, app_id): ''' The current Info and the Info viewed last should have some relation. And the last viewed Info could be found from cookie. ''' last_app_uid = self.get_secure_cookie('use_app_uid') if last_app_uid: last_app_uid = last_app_uid.decode('utf-8')
python
{ "resource": "" }
q5037
PostHandler._to_edit_kind
train
def _to_edit_kind(self, post_uid): ''' Show the page for changing the category. ''' if self.userinfo and self.userinfo.role[1] >= '3': pass else: self.redirect('/') postinfo = MPost.get_by_uid(post_uid, ) json_cnt = json.dumps(postinfo.extinfo, indent=True) kwd = {} self.render('man_info/post_kind.html',
python
{ "resource": "" }
q5038
PostHandler._change_kind
train
def _change_kind(self, post_uid): ''' To modify the category of the post, and kind. ''' post_data = self.get_post_data() logger.info('admin post update: {0}'.format(post_data)) MPost.update_misc(post_uid, kind=post_data['kcat'])
python
{ "resource": "" }
q5039
EntityHandler.list
train
def list(self, cur_p=''): ''' Lists of the entities. ''' current_page_number = int(cur_p) if cur_p else 1 current_page_number = 1 if current_page_number < 1 else current_page_number kwd = { 'current_page': current_page_number }
python
{ "resource": "" }
q5040
EntityHandler.down
train
def down(self, down_uid): ''' Download the entity by UID. ''' down_url = MPost.get_by_uid(down_uid).extinfo.get('tag__file_download', '') print('=' * 40) print(down_url) str_down_url = str(down_url)[15:] if down_url: ment_id
python
{ "resource": "" }
q5041
EntityHandler.to_add
train
def to_add(self): ''' To add the entity. ''' kwd = { 'pager': '',
python
{ "resource": "" }
q5042
EntityHandler.add_entity
train
def add_entity(self): ''' Add the entity. All the information got from the post data. ''' post_data = self.get_post_data() if 'kind' in post_data: if post_data['kind'] == '1':
python
{ "resource": "" }
q5043
EntityHandler.add_pic
train
def add_pic(self, post_data): ''' Adding the picture. ''' img_entity = self.request.files['file'][0] filename = img_entity["filename"] if filename and allowed_file(filename): pass else: return False _, hou = os.path.splitext(filename) signature = str(uuid.uuid1()) outfilename = '{0}{1}'.format(signature, hou) outpath = 'static/upload/{0}'.format(signature[:2]) if os.path.exists(outpath): pass else: os.makedirs(outpath) with open(os.path.join(outpath, outfilename), "wb") as fileout: fileout.write(img_entity["body"]) path_save = os.path.join(signature[:2], outfilename) sig_save = os.path.join(signature[:2], signature) imgpath = os.path.join(outpath, signature + '_m.jpg') imgpath_sm = os.path.join(outpath, signature + '_sm.jpg') ptr_image = Image.open(os.path.join('static/upload', path_save)) tmpl_size = (768, 768) thub_size = (256, 256) (imgwidth, imgheight) = ptr_image.size if imgwidth < tmpl_size[0] and imgheight < tmpl_size[1]: tmpl_size = (imgwidth, imgheight) ptr_image.thumbnail(tmpl_size) im0 = ptr_image.convert('RGB') im0.save(imgpath, 'JPEG')
python
{ "resource": "" }
q5044
EntityHandler.add_pdf
train
def add_pdf(self, post_data): ''' Adding the pdf file. ''' img_entity = self.request.files['file'][0] img_desc = post_data['desc'] filename = img_entity["filename"] if filename and allowed_file_pdf(filename): pass else: return False _, hou = os.path.splitext(filename) signature = str(uuid.uuid1()) outfilename = '{0}{1}'.format(signature, hou) outpath = 'static/upload/{0}'.format(signature[:2]) if os.path.exists(outpath): pass else: os.makedirs(outpath) with open(os.path.join(outpath, outfilename), "wb") as fout: fout.write(img_entity["body"]) sig_save =
python
{ "resource": "" }
q5045
EntityHandler.add_url
train
def add_url(self, post_data): ''' Adding the URL as entity. ''' img_desc = post_data['desc'] img_path = post_data['file1'] cur_uid = tools.get_uudd(4) while MEntity.get_by_uid(cur_uid): cur_uid = tools.get_uudd(4) MEntity.create_entity(cur_uid, img_path, img_desc, kind=post_data['kind'] if 'kind' in post_data else '3') kwd = {
python
{ "resource": "" }
q5046
UserHandler.p_changepassword
train
def p_changepassword(self): ''' Changing password. ''' post_data = self.get_post_data() usercheck = MUser.check_user(self.userinfo.uid, post_data['rawpass']) if usercheck == 1: MUser.update_pass(self.userinfo.uid, post_data['user_pass'])
python
{ "resource": "" }
q5047
UserHandler.p_changeinfo
train
def p_changeinfo(self): ''' Change Infor via Ajax. ''' post_data, def_dic = self.fetch_post_data() usercheck = MUser.check_user(self.userinfo.uid, post_data['rawpass']) if usercheck == 1:
python
{ "resource": "" }
q5048
UserHandler.__check_valid
train
def __check_valid(self, post_data): ''' To check if the user is succesfully created. Return the status code dict. ''' user_create_status = {'success': False, 'code': '00'} if not tools.check_username_valid(post_data['user_name']): user_create_status['code'] = '11' return user_create_status
python
{ "resource": "" }
q5049
UserHandler.p_to_find
train
def p_to_find(self, ): ''' To find, pager. ''' kwd = { 'pager': '', } self.render('user/user_find_list.html', kwd=kwd,
python
{ "resource": "" }
q5050
SysHandler.set_language
train
def set_language(self, language): ''' Set the cookie for locale. ''' if language == 'ZH': self.set_cookie('ulocale', 'zh_CN') self.set_cookie('blocale',
python
{ "resource": "" }
q5051
gen_input_add
train
def gen_input_add(sig_dic): ''' Adding for HTML Input control. ''' if sig_dic['en'] == 'tag_file_download': html_str = HTML_TPL_DICT['input_add_download'].format( sig_en=sig_dic['en'], sig_zh=sig_dic['zh'], sig_dic=sig_dic['dic'][1], sig_type=sig_dic['type']
python
{ "resource": "" }
q5052
gen_input_edit
train
def gen_input_edit(sig_dic): ''' Editing for HTML input control. ''' if sig_dic['en'] == 'tag_file_download': html_str = HTML_TPL_DICT['input_edit_download'].format( sig_en=sig_dic['en'], sig_zh=sig_dic['zh'], sig_dic=sig_dic['dic'][1], sig_type=sig_dic['type']
python
{ "resource": "" }
q5053
gen_input_view
train
def gen_input_view(sig_dic): ''' Viewing the HTML text. ''' if sig_dic['en'] == 'tag_file_download': html_str = HTML_TPL_DICT['input_view_download'].format( sig_zh=sig_dic['zh'], sig_unit=sig_dic['dic'][1] ) elif sig_dic['en'] in ['tag_access_link', 'tag_dmoz_url', 'tag_online_link', 'tag_event_url', 'tag_expert_home', 'tag_pic_url']: html_str = HTML_TPL_DICT['input_view_link'].format(
python
{ "resource": "" }
q5054
MPost.__update_rating
train
def __update_rating(uid, rating): ''' Update the rating for post. ''' entry = TabPost.update(
python
{ "resource": "" }
q5055
MPost.__update_kind
train
def __update_kind(uid, kind): ''' update the kind of post. '''
python
{ "resource": "" }
q5056
MPost.update_cnt
train
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'],
python
{ "resource": "" }
q5057
MPost.update_order
train
def update_order(uid, order): ''' Update the order of the posts. ''' entry = TabPost.update(
python
{ "resource": "" }
q5058
MPost.update
train
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()),
python
{ "resource": "" }
q5059
MPost.add_or_update
train
def add_or_update(uid, post_data): ''' Add or update the post. ''' cur_rec = MPost.get_by_uid(uid) if cur_rec:
python
{ "resource": "" }
q5060
MPost.create_post
train
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.get('time_create', tools.timestamp()), time_update=post_data.get('time_update', tools.timestamp()), user_name=post_data['user_name'], view_count=post_data['view_count'] if 'view_count' in post_data else 1,
python
{ "resource": "" }
q5061
MPost.query_cat_random
train
def query_cat_random(catid, **kwargs): ''' Get random lists of certain category. ''' num = kwargs.get('limit', 8) if catid == '': rand_recs = TabPost.select().order_by(peewee.fn.Random()).limit(num)
python
{ "resource": "" }
q5062
MPost.query_random
train
def query_random(**kwargs): ''' Return the random records of centain kind. ''' if 'limit' in kwargs: limit = kwargs['limit'] elif 'num' in kwargs: limit = kwargs['num'] else: limit = 10 kind = kwargs.get('kind', None) if kind: rand_recs = TabPost.select().where( (TabPost.kind == kind) & (TabPost.valid == 1)
python
{ "resource": "" }
q5063
MPost.query_recent
train
def query_recent(num=8, **kwargs): ''' query recent posts. ''' order_by_create = kwargs.get('order_by_create', False) kind = kwargs.get('kind', None) if order_by_create: if kind: recent_recs = TabPost.select().where( (TabPost.kind == kind) & (TabPost.valid == 1) ).order_by( TabPost.time_create.desc() ).limit(num) else: recent_recs = TabPost.select().where( TabPost.valid == 1 ).order_by( TabPost.time_create.desc() ).limit(num) else: if kind: recent_recs = TabPost.select().where(
python
{ "resource": "" }
q5064
MPost.query_all
train
def query_all(**kwargs): ''' query all the posts. ''' kind = kwargs.get('kind', '1') limit = kwargs.get('limit', 10) return TabPost.select().where( (TabPost.kind == kind) &
python
{ "resource": "" }
q5065
MPost.query_keywords_empty
train
def query_keywords_empty(kind='1'): ''' Query keywords, empty. '''
python
{ "resource": "" }
q5066
MPost.query_recent_edited
train
def query_recent_edited(timstamp, kind='1'): ''' Query posts recently update. ''' return TabPost.select().where( (TabPost.kind == kind) &
python
{ "resource": "" }
q5067
MPost.query_dated
train
def query_dated(num=8, kind='1'): ''' Query posts, outdate. ''' return TabPost.select().where( TabPost.kind == kind
python
{ "resource": "" }
q5068
MPost.query_most_pic
train
def query_most_pic(num, kind='1'): ''' Query most pics. ''' return TabPost.select().where(
python
{ "resource": "" }
q5069
MPost.query_most
train
def query_most(num=8, kind='1'): ''' Query most viewed. ''' return TabPost.select().where( (TabPost.kind == kind) &
python
{ "resource": "" }
q5070
MPost.update_misc
train
def update_misc(uid, **kwargs): ''' update rating, kind, or count ''' if 'rating' in kwargs: MPost.__update_rating(uid, kwargs['rating']) elif 'kind' in kwargs: MPost.__update_kind(uid, kwargs['kind']) elif 'keywords'
python
{ "resource": "" }
q5071
MPost.__update_keywords
train
def __update_keywords(uid, inkeywords): ''' Update with keywords. ''' entry
python
{ "resource": "" }
q5072
MPost.get_next_record
train
def get_next_record(in_uid, kind='1'): ''' Get next record by time_create. ''' current_rec = MPost.get_by_uid(in_uid) recs = TabPost.select().where(
python
{ "resource": "" }
q5073
MPost.get_all
train
def get_all(kind='2'): ''' Get All the records. ''' return TabPost.select().where( (TabPost.kind == kind) &
python
{ "resource": "" }
q5074
MPost.update_jsonb
train
def update_jsonb(uid, extinfo): ''' Update the json. ''' cur_extinfo = MPost.get_by_uid(uid).extinfo for key in extinfo: cur_extinfo[key] = extinfo[key] entry = TabPost.update(
python
{ "resource": "" }
q5075
MPost.modify_meta
train
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'],
python
{ "resource": "" }
q5076
MPost.modify_init
train
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,
python
{ "resource": "" }
q5077
MPost.query_under_condition
train
def query_under_condition(condition, kind='2'): ''' Get All data of certain kind according to the condition ''' if DB_CFG['kind'] == 's': return TabPost.select().where(
python
{ "resource": "" }
q5078
MPost.query_list_pager
train
def query_list_pager(con, idx, kind='2'): ''' Get records of certain pager. ''' all_list = MPost.query_under_condition(con, kind=kind)
python
{ "resource": "" }
q5079
UserListHandler.list_app
train
def list_app(self): ''' List the apps. ''' kwd = { 'pager': '',
python
{ "resource": "" }
q5080
UserListHandler.user_most
train
def user_most(self): ''' User most used. ''' kwd = { 'pager': '', 'title': '', } self.render('user/info_list/user_most.html',
python
{ "resource": "" }
q5081
UserListHandler.user_recent
train
def user_recent(self): ''' User used recently. ''' kwd = { 'pager': '', 'title': '' } self.render('user/info_list/user_recent.html',
python
{ "resource": "" }
q5082
UserListHandler.list_recent
train
def list_recent(self): ''' List the recent. ''' recs = MPost.query_recent(20) kwd = { 'pager': '', 'title': '', } self.render('user/info_list/list.html',
python
{ "resource": "" }
q5083
UserListHandler.find
train
def find(self): ''' find the infors. ''' keyword = self.get_argument('keyword').strip() kwd = { 'pager': '', 'title': 'Searching Result', } self.render('user/info_list/find_list.html',
python
{ "resource": "" }
q5084
RelHandler.add_relation
train
def add_relation(self, url_arr): ''' Add relationship. ''' if MPost.get_by_uid(url_arr[1]): pass else: return False last_post_id = self.get_secure_cookie('last_post_uid') if last_post_id: last_post_id = last_post_id.decode('utf-8') last_app_id = self.get_secure_cookie('use_app_uid') if last_app_id: last_app_id = last_app_id.decode('utf-8') if url_arr[0] == 'info': if last_post_id: MRelation.add_relation(last_post_id, url_arr[1], 2)
python
{ "resource": "" }
q5085
ReplyHandler.get_by_id
train
def get_by_id(self, reply_id): ''' Get the reply by id. ''' reply = MReply.get_by_uid(reply_id) logger.info('get_reply: {0}'.format(reply_id)) self.render('misc/reply/show_reply.html', reply=reply,
python
{ "resource": "" }
q5086
ReplyHandler.add
train
def add(self, post_id): ''' Adding reply to a post. ''' post_data = self.get_post_data() post_data['user_name'] = self.userinfo.user_name post_data['user_id'] = self.userinfo.uid post_data['post_id'] = post_id replyid = MReply.create_reply(post_data) if replyid:
python
{ "resource": "" }
q5087
ReplyHandler.delete
train
def delete(self, del_id): ''' Delete the id ''' if MReply2User.delete(del_id): output = {'del_zan': 1}
python
{ "resource": "" }
q5088
WikiHistoryHandler.update
train
def update(self, uid): ''' Update the post via ID. ''' if self.userinfo.role[0] > '0': pass else: return False post_data = self.get_post_data() post_data['user_name'] = self.userinfo.user_name if self.userinfo else '' cur_info = MWiki.get_by_uid(uid) MWikiHist.create_wiki_history(cur_info) MWiki.update_cnt(uid, post_data)
python
{ "resource": "" }
q5089
WikiHistoryHandler.to_edit
train
def to_edit(self, postid): ''' Try to edit the Post. ''' if self.userinfo.role[0] > '0': pass else: return False kwd = {} self.render('man_info/wiki_man_edit.html',
python
{ "resource": "" }
q5090
WikiHistoryHandler.delete
train
def delete(self, uid): ''' Delete the history of certain ID. ''' if self.check_post_role()['DELETE']: pass else: return False
python
{ "resource": "" }
q5091
WikiHistoryHandler.restore
train
def restore(self, hist_uid): ''' Restore by ID ''' if self.check_post_role()['ADMIN']: pass else: return False histinfo = MWikiHist.get_by_uid(hist_uid) if histinfo: pass else: return False postinfo = MWiki.get_by_uid(histinfo.wiki_id) cur_cnt = tornado.escape.xhtml_unescape(postinfo.cnt_md) old_cnt = tornado.escape.xhtml_unescape(histinfo.cnt_md) MWiki.update_cnt( histinfo.wiki_id, {'cnt_md': old_cnt, 'user_name': self.userinfo.user_name} ) MWikiHist.update_cnt(
python
{ "resource": "" }
q5092
MLog.add
train
def add(data_dic): ''' Insert new record. ''' uid = data_dic['uid'] TabLog.create( uid=uid, current_url=data_dic['url'], refer_url=data_dic['refer'], user_id=data_dic['user_id'],
python
{ "resource": "" }
q5093
MCollect.get_by_signature
train
def get_by_signature(user_id, app_id): ''' Get the collection. ''' try: return TabCollect.get( (TabCollect.user_id == user_id) &
python
{ "resource": "" }
q5094
MCollect.count_of_user
train
def count_of_user(user_id): ''' Get the cound of views. ''' return TabCollect.select( TabCollect, TabPost.uid.alias('post_uid'), TabPost.title.alias('post_title'), TabPost.view_count.alias('post_view_count') ).where(
python
{ "resource": "" }
q5095
MCollect.add_or_update
train
def add_or_update(user_id, app_id): ''' Add the collection or update. ''' rec = MCollect.get_by_signature(user_id, app_id) if rec: entry = TabCollect.update(
python
{ "resource": "" }
q5096
deprecated
train
def deprecated(deprecated_in=None, removed_in=None, current_version=None, details=""): """Decorate a function to signify its deprecation This function wraps a method that will soon be removed and does two things: * The docstring of the method will be modified to include a notice about deprecation, e.g., "Deprecated since 0.9.11. Use foo instead." * Raises a :class:`~deprecation.DeprecatedWarning` via the :mod:`warnings` module, which is a subclass of the built-in :class:`DeprecationWarning`. Note that built-in :class:`DeprecationWarning`\\s are ignored by default, so for users to be informed of said warnings they will need to enable them--see the :mod:`warnings` module documentation for more details. :param deprecated_in: The version at which the decorated method is considered deprecated. This will usually be the next version to be released when the decorator is added. The default is **None**, which effectively means immediate deprecation. If this is not specified, then the `removed_in` and `current_version` arguments are ignored. :param removed_in: The version when the decorated method will be removed. The default is **None**, specifying that the function is not currently planned to be removed. Note: This cannot be set to a value if `deprecated_in=None`. :param current_version: The source of version information for the currently running code. This will usually be a `__version__` attribute on your library. The default is `None`. When `current_version=None` the automation to determine if the wrapped function is actually in a period of deprecation or time for removal does not work, causing a :class:`~deprecation.DeprecatedWarning` to be raised in all cases. :param details: Extra details to be added to the method docstring and warning. For example, the details may point users to a replacement method, such as "Use the foo_bar method instead". By default there are no details. """ # You can't just jump to removal. It's weird, unfair, and also makes # building up the docstring weird. if deprecated_in is None and removed_in is not None: raise TypeError("Cannot set removed_in to a value " "without also setting deprecated_in") # Only warn when it's appropriate. There may be cases when it makes sense # to add this decorator before a formal deprecation period begins. # In CPython, PendingDeprecatedWarning gets used in that period, # so perhaps mimick that at some point. is_deprecated = False is_unsupported = False # StrictVersion won't take a None or a "", so
python
{ "resource": "" }
q5097
fail_if_not_removed
train
def fail_if_not_removed(method): """Decorate a test method to track removal of deprecated code This decorator catches :class:`~deprecation.UnsupportedWarning` warnings that occur during testing and causes unittests to fail, making it easier to keep track of when code should be removed. :raises: :class:`AssertionError` if an :class:`~deprecation.UnsupportedWarning` is raised while running the test method. """ def _inner(*args, **kwargs): with warnings.catch_warnings(record=True) as caught_warnings: warnings.simplefilter("always") rval = method(*args,
python
{ "resource": "" }
q5098
BaseHandler.get_post_data
train
def get_post_data(self): ''' Get all the arguments from post request. Only get the first argument by default.
python
{ "resource": "" }
q5099
BaseHandler.check_post_role
train
def check_post_role(self): ''' check the user role for docs. ''' priv_dic = {'ADD': False, 'EDIT': False, 'DELETE': False, 'ADMIN': False} if self.userinfo: if self.userinfo.role[1] > '0':
python
{ "resource": "" }