id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
51
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
5,000
bukun/TorCMS
torcms/model/post_hist_model.py
MPostHist.create_post_history
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, user_name=raw_data.user_name, cnt_md=raw_data.cnt_md, time_update=tools.timestamp(), logo=raw_data.logo, ) return True
python
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, user_name=raw_data.user_name, cnt_md=raw_data.cnt_md, time_update=tools.timestamp(), logo=raw_data.logo, ) return True
[ "def", "create_post_history", "(", "raw_data", ")", ":", "uid", "=", "tools", ".", "get_uuid", "(", ")", "TabPostHist", ".", "create", "(", "uid", "=", "uid", ",", "title", "=", "raw_data", ".", "title", ",", "post_id", "=", "raw_data", ".", "uid", ","...
Create the history of certain post.
[ "Create", "the", "history", "of", "certain", "post", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_hist_model.py#L74-L88
5,001
bukun/TorCMS
torcms/handlers/list_handler.py
ListHandler.ajax_list_catalog
def ajax_list_catalog(self, catid): ''' Get posts of certain catid. In Json. 根据分类ID(catid)获取 该分类下 post 的相关信息,返回Json格式 ''' out_arr = {} for catinfo in MPost2Catalog.query_postinfo_by_cat(catid): out_arr[catinfo.uid] = catinfo.title json.dump(out_arr, self)
python
def ajax_list_catalog(self, catid): ''' Get posts of certain catid. In Json. 根据分类ID(catid)获取 该分类下 post 的相关信息,返回Json格式 ''' out_arr = {} for catinfo in MPost2Catalog.query_postinfo_by_cat(catid): out_arr[catinfo.uid] = catinfo.title json.dump(out_arr, self)
[ "def", "ajax_list_catalog", "(", "self", ",", "catid", ")", ":", "out_arr", "=", "{", "}", "for", "catinfo", "in", "MPost2Catalog", ".", "query_postinfo_by_cat", "(", "catid", ")", ":", "out_arr", "[", "catinfo", ".", "uid", "]", "=", "catinfo", ".", "ti...
Get posts of certain catid. In Json. 根据分类ID(catid)获取 该分类下 post 的相关信息,返回Json格式
[ "Get", "posts", "of", "certain", "catid", ".", "In", "Json", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/list_handler.py#L57-L67
5,002
bukun/TorCMS
torcms/handlers/list_handler.py
ListHandler.ajax_kindcat_arr
def ajax_kindcat_arr(self, kind_sig): ''' Get the sub category. 根据kind值(kind_sig)获取相应分类,返回Json格式 ''' out_arr = {} for catinfo in MCategory.query_kind_cat(kind_sig): out_arr[catinfo.uid] = catinfo.name json.dump(out_arr, self)
python
def ajax_kindcat_arr(self, kind_sig): ''' Get the sub category. 根据kind值(kind_sig)获取相应分类,返回Json格式 ''' out_arr = {} for catinfo in MCategory.query_kind_cat(kind_sig): out_arr[catinfo.uid] = catinfo.name json.dump(out_arr, self)
[ "def", "ajax_kindcat_arr", "(", "self", ",", "kind_sig", ")", ":", "out_arr", "=", "{", "}", "for", "catinfo", "in", "MCategory", ".", "query_kind_cat", "(", "kind_sig", ")", ":", "out_arr", "[", "catinfo", ".", "uid", "]", "=", "catinfo", ".", "name", ...
Get the sub category. 根据kind值(kind_sig)获取相应分类,返回Json格式
[ "Get", "the", "sub", "category", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/list_handler.py#L81-L90
5,003
bukun/TorCMS
torcms/handlers/list_handler.py
ListHandler.list_catalog
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: tmpl = 'list/catalog_list.html' else: tmpl = 'list/category_list.html' infos = MPost2Catalog.query_pager_by_slug( cat_slug, current_page_num, tag=tag, order=self.order ) # ToDo: `gen_pager_purecss` should not use any more. self.render(tmpl, catinfo=cat_rec, infos=infos, pager=tools.gen_pager_purecss( '/list/{0}'.format(cat_slug), page_num, current_page_num), userinfo=self.userinfo, html2text=html2text, cfg=CMS_CFG, kwd=kwd, router=router_post[cat_rec.kind])
python
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: tmpl = 'list/catalog_list.html' else: tmpl = 'list/category_list.html' infos = MPost2Catalog.query_pager_by_slug( cat_slug, current_page_num, tag=tag, order=self.order ) # ToDo: `gen_pager_purecss` should not use any more. self.render(tmpl, catinfo=cat_rec, infos=infos, pager=tools.gen_pager_purecss( '/list/{0}'.format(cat_slug), page_num, current_page_num), userinfo=self.userinfo, html2text=html2text, cfg=CMS_CFG, kwd=kwd, router=router_post[cat_rec.kind])
[ "def", "list_catalog", "(", "self", ",", "cat_slug", ",", "*", "*", "kwargs", ")", ":", "post_data", "=", "self", ".", "get_post_data", "(", ")", "tag", "=", "post_data", ".", "get", "(", "'tag'", ",", "''", ")", "def", "get_pager_idx", "(", ")", ":"...
listing the posts via category 根据分类(cat_slug)显示分类列表
[ "listing", "the", "posts", "via", "category" ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/list_handler.py#L92-L155
5,004
bukun/TorCMS
torcms/core/tool/send_email.py
send_mail
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 alinyun ECS has masked the 25 port since 9,2016. smtper = smtplib.SMTP_SSL(SMTP_CFG['host'], port=994) smtper.login(SMTP_CFG['user'], SMTP_CFG['pass']) smtper.sendmail(sender, to_list, msg.as_string()) smtper.close() return True except: return False
python
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 alinyun ECS has masked the 25 port since 9,2016. smtper = smtplib.SMTP_SSL(SMTP_CFG['host'], port=994) smtper.login(SMTP_CFG['user'], SMTP_CFG['pass']) smtper.sendmail(sender, to_list, msg.as_string()) smtper.close() return True except: return False
[ "def", "send_mail", "(", "to_list", ",", "sub", ",", "content", ",", "cc", "=", "None", ")", ":", "sender", "=", "SMTP_CFG", "[", "'name'", "]", "+", "\"<\"", "+", "SMTP_CFG", "[", "'user'", "]", "+", "\">\"", "msg", "=", "MIMEText", "(", "content", ...
Sending email via Python.
[ "Sending", "email", "via", "Python", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/core/tool/send_email.py#L12-L31
5,005
bukun/TorCMS
torcms/handlers/post_ajax_handler.py
PostAjaxHandler.viewinfo
def viewinfo(self, postinfo): ''' View the info ''' out_json = { 'uid': postinfo.uid, 'time_update': postinfo.time_update, 'title': postinfo.title, 'cnt_html': tornado.escape.xhtml_unescape(postinfo.cnt_html), } self.write(json.dumps(out_json))
python
def viewinfo(self, postinfo): ''' View the info ''' out_json = { 'uid': postinfo.uid, 'time_update': postinfo.time_update, 'title': postinfo.title, 'cnt_html': tornado.escape.xhtml_unescape(postinfo.cnt_html), } self.write(json.dumps(out_json))
[ "def", "viewinfo", "(", "self", ",", "postinfo", ")", ":", "out_json", "=", "{", "'uid'", ":", "postinfo", ".", "uid", ",", "'time_update'", ":", "postinfo", ".", "time_update", ",", "'title'", ":", "postinfo", ".", "title", ",", "'cnt_html'", ":", "torn...
View the info
[ "View", "the", "info" ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/post_ajax_handler.py#L42-L53
5,006
bukun/TorCMS
torcms/handlers/post_ajax_handler.py
PostAjaxHandler.count_plus
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, 'status': 1 if MPost.update_misc(uid, count=1) else 0 } # return json.dump(output, self) self.write(json.dumps(output))
python
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, 'status': 1 if MPost.update_misc(uid, count=1) else 0 } # return json.dump(output, self) self.write(json.dumps(output))
[ "def", "count_plus", "(", "self", ",", "uid", ")", ":", "self", ".", "set_header", "(", "\"Content-Type\"", ",", "\"application/json\"", ")", "output", "=", "{", "# ToDo: Test the following codes.", "# MPost.__update_view_count_by_uid(uid) else 0,", "'status'", ":", "1"...
Ajax request, that the view count will plus 1.
[ "Ajax", "request", "that", "the", "view", "count", "will", "plus", "1", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/post_ajax_handler.py#L55-L66
5,007
bukun/TorCMS
torcms/handlers/post_ajax_handler.py
PostAjaxHandler.p_recent
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.', 'with_catalog': with_catalog, 'with_date': with_date, 'kind': kind, 'current_page': current_page_number, 'post_count': MPost.get_counts(), 'router': config.router_post[kind], } self.render('admin/post_ajax/post_list.html', kwd=kwd, view=MPost.query_recent(num=20, kind=kind), infos=MPost.query_pager_by_slug( kind=kind, current_page_num=current_page_number ), format_date=tools.format_date, userinfo=self.userinfo, cfg=CMS_CFG, )
python
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.', 'with_catalog': with_catalog, 'with_date': with_date, 'kind': kind, 'current_page': current_page_number, 'post_count': MPost.get_counts(), 'router': config.router_post[kind], } self.render('admin/post_ajax/post_list.html', kwd=kwd, view=MPost.query_recent(num=20, kind=kind), infos=MPost.query_pager_by_slug( kind=kind, current_page_num=current_page_number ), format_date=tools.format_date, userinfo=self.userinfo, cfg=CMS_CFG, )
[ "def", "p_recent", "(", "self", ",", "kind", ",", "cur_p", "=", "''", ",", "with_catalog", "=", "True", ",", "with_date", "=", "True", ")", ":", "if", "cur_p", "==", "''", ":", "current_page_number", "=", "1", "else", ":", "current_page_number", "=", "...
List posts that recent edited, partially.
[ "List", "posts", "that", "recent", "edited", "partially", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/post_ajax_handler.py#L68-L99
5,008
bukun/TorCMS
torcms/handlers/post_ajax_handler.py
PostAjaxHandler.j_delete
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, 'cat_id': tslug.uid, 'kind': current_infor.kind } else: output = { 'del_info': 0, } return json.dump(output, self)
python
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, 'cat_id': tslug.uid, 'kind': current_infor.kind } else: output = { 'del_info': 0, } return json.dump(output, self)
[ "def", "j_delete", "(", "self", ",", "*", "args", ")", ":", "uid", "=", "args", "[", "0", "]", "current_infor", "=", "MPost", ".", "get_by_uid", "(", "uid", ")", "tslug", "=", "MCategory", ".", "get_by_uid", "(", "current_infor", ".", "extinfo", "[", ...
Delete the post, but return the JSON.
[ "Delete", "the", "post", "but", "return", "the", "JSON", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/post_ajax_handler.py#L103-L126
5,009
bukun/TorCMS
torcms/script/script_init_tabels.py
run_init_tables
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) create_table(TabPost2Tag) create_table(TabRel) create_table(TabEvaluation) create_table(TabUsage) create_table(TabReply) create_table(TabUser2Reply) create_table(TabRating) create_table(TabEntity2User) create_table(TabLog)
python
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) create_table(TabPost2Tag) create_table(TabRel) create_table(TabEvaluation) create_table(TabUsage) create_table(TabReply) create_table(TabUser2Reply) create_table(TabRating) create_table(TabEntity2User) create_table(TabLog)
[ "def", "run_init_tables", "(", "*", "args", ")", ":", "print", "(", "'--'", ")", "create_table", "(", "TabPost", ")", "create_table", "(", "TabTag", ")", "create_table", "(", "TabMember", ")", "create_table", "(", "TabWiki", ")", "create_table", "(", "TabLin...
Run to init tables.
[ "Run", "to", "init", "tables", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/script/script_init_tabels.py#L22-L45
5,010
bukun/TorCMS
torcms/core/tool/run_whoosh.py
gen_whoosh_database
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) else: os.makedirs(whoosh_db) create_idx = create_in(whoosh_db, schema) writer = create_idx.writer() for switch in [True, False]: do_for_post(writer, rand=switch, doc_type=post_type['1']) do_for_wiki(writer, rand=switch, doc_type=post_type['1']) do_for_page(writer, rand=switch, doc_type=post_type['1']) for kind in kind_arr: do_for_app(writer, rand=switch, kind=kind, doc_type=post_type) writer.commit()
python
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) else: os.makedirs(whoosh_db) create_idx = create_in(whoosh_db, schema) writer = create_idx.writer() for switch in [True, False]: do_for_post(writer, rand=switch, doc_type=post_type['1']) do_for_wiki(writer, rand=switch, doc_type=post_type['1']) do_for_page(writer, rand=switch, doc_type=post_type['1']) for kind in kind_arr: do_for_app(writer, rand=switch, kind=kind, doc_type=post_type) writer.commit()
[ "def", "gen_whoosh_database", "(", "kind_arr", ",", "post_type", ")", ":", "SITE_CFG", "[", "'LANG'", "]", "=", "SITE_CFG", ".", "get", "(", "'LANG'", ",", "'zh'", ")", "# Using jieba lib for Chinese.", "if", "SITE_CFG", "[", "'LANG'", "]", "==", "'zh'", "an...
kind_arr, define the `type` except Post, Page, Wiki post_type, define the templates for different kind.
[ "kind_arr", "define", "the", "type", "except", "Post", "Page", "Wiki", "post_type", "define", "the", "templates", "for", "different", "kind", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/core/tool/run_whoosh.py#L132-L167
5,011
bukun/TorCMS
torcms/handlers/publish_handler.py
PublishHandler.view_class2
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', 'parentlist': MCategory.get_parent_list()} if fatherid.endswith('00'): self.render('misc/publish/publish2.html', userinfo=self.userinfo, kwd=kwd) else: catinfo = MCategory.get_by_uid(fatherid) self.redirect('/{1}/_cat_add/{0}'.format(fatherid, router_post[catinfo.kind]))
python
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', 'parentlist': MCategory.get_parent_list()} if fatherid.endswith('00'): self.render('misc/publish/publish2.html', userinfo=self.userinfo, kwd=kwd) else: catinfo = MCategory.get_by_uid(fatherid) self.redirect('/{1}/_cat_add/{0}'.format(fatherid, router_post[catinfo.kind]))
[ "def", "view_class2", "(", "self", ",", "fatherid", "=", "''", ")", ":", "if", "self", ".", "is_admin", "(", ")", ":", "pass", "else", ":", "return", "False", "kwd", "=", "{", "'class1str'", ":", "self", ".", "format_class2", "(", "fatherid", ")", ",...
Publishing from 2ed range category.
[ "Publishing", "from", "2ed", "range", "category", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/publish_handler.py#L88-L108
5,012
bukun/TorCMS
torcms/model/evaluation_model.py
MEvaluation.app_evaluation_count
def app_evaluation_count(app_id, value=1): ''' Get the Evalution sum. ''' return TabEvaluation.select().where( (TabEvaluation.post_id == app_id) & (TabEvaluation.value == value) ).count()
python
def app_evaluation_count(app_id, value=1): ''' Get the Evalution sum. ''' return TabEvaluation.select().where( (TabEvaluation.post_id == app_id) & (TabEvaluation.value == value) ).count()
[ "def", "app_evaluation_count", "(", "app_id", ",", "value", "=", "1", ")", ":", "return", "TabEvaluation", ".", "select", "(", ")", ".", "where", "(", "(", "TabEvaluation", ".", "post_id", "==", "app_id", ")", "&", "(", "TabEvaluation", ".", "value", "==...
Get the Evalution sum.
[ "Get", "the", "Evalution", "sum", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/evaluation_model.py#L17-L23
5,013
bukun/TorCMS
torcms/model/evaluation_model.py
MEvaluation.get_by_signature
def get_by_signature(user_id, app_id): ''' get by user ID, and app ID. ''' try: return TabEvaluation.get( (TabEvaluation.user_id == user_id) & (TabEvaluation.post_id == app_id) ) except: return None
python
def get_by_signature(user_id, app_id): ''' get by user ID, and app ID. ''' try: return TabEvaluation.get( (TabEvaluation.user_id == user_id) & (TabEvaluation.post_id == app_id) ) except: return None
[ "def", "get_by_signature", "(", "user_id", ",", "app_id", ")", ":", "try", ":", "return", "TabEvaluation", ".", "get", "(", "(", "TabEvaluation", ".", "user_id", "==", "user_id", ")", "&", "(", "TabEvaluation", ".", "post_id", "==", "app_id", ")", ")", "...
get by user ID, and app ID.
[ "get", "by", "user", "ID", "and", "app", "ID", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/evaluation_model.py#L26-L35
5,014
bukun/TorCMS
torcms/model/evaluation_model.py
MEvaluation.add_or_update
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( value=value, ).where(TabEvaluation.uid == rec.uid) entry.execute() else: TabEvaluation.create( uid=tools.get_uuid(), user_id=user_id, post_id=app_id, value=value, )
python
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( value=value, ).where(TabEvaluation.uid == rec.uid) entry.execute() else: TabEvaluation.create( uid=tools.get_uuid(), user_id=user_id, post_id=app_id, value=value, )
[ "def", "add_or_update", "(", "user_id", ",", "app_id", ",", "value", ")", ":", "rec", "=", "MEvaluation", ".", "get_by_signature", "(", "user_id", ",", "app_id", ")", "if", "rec", ":", "entry", "=", "TabEvaluation", ".", "update", "(", "value", "=", "val...
Editing evaluation.
[ "Editing", "evaluation", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/evaluation_model.py#L38-L54
5,015
bukun/TorCMS
torcms/handlers/page_ajax_handler.py
PageAjaxHandler.view
def view(self, rec): ''' view the post. ''' out_json = { 'uid': rec.uid, 'time_update': rec.time_update, 'title': rec.title, 'cnt_html': tornado.escape.xhtml_unescape(rec.cnt_html), } self.write(json.dumps(out_json))
python
def view(self, rec): ''' view the post. ''' out_json = { 'uid': rec.uid, 'time_update': rec.time_update, 'title': rec.title, 'cnt_html': tornado.escape.xhtml_unescape(rec.cnt_html), } self.write(json.dumps(out_json))
[ "def", "view", "(", "self", ",", "rec", ")", ":", "out_json", "=", "{", "'uid'", ":", "rec", ".", "uid", ",", "'time_update'", ":", "rec", ".", "time_update", ",", "'title'", ":", "rec", ".", "title", ",", "'cnt_html'", ":", "tornado", ".", "escape",...
view the post.
[ "view", "the", "post", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/page_ajax_handler.py#L44-L55
5,016
bukun/TorCMS
torcms/handlers/page_ajax_handler.py
PageAjaxHandler.j_count_plus
def j_count_plus(self, slug): ''' plus count via ajax. ''' output = {'status': 1 if MWiki.view_count_plus(slug) else 0} return json.dump(output, self)
python
def j_count_plus(self, slug): ''' plus count via ajax. ''' output = {'status': 1 if MWiki.view_count_plus(slug) else 0} return json.dump(output, self)
[ "def", "j_count_plus", "(", "self", ",", "slug", ")", ":", "output", "=", "{", "'status'", ":", "1", "if", "MWiki", ".", "view_count_plus", "(", "slug", ")", "else", "0", "}", "return", "json", ".", "dump", "(", "output", ",", "self", ")" ]
plus count via ajax.
[ "plus", "count", "via", "ajax", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/page_ajax_handler.py#L61-L66
5,017
bukun/TorCMS
torcms/handlers/page_ajax_handler.py
PageAjaxHandler.p_list
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, 'page_count': MWiki.get_counts(), } self.render('admin/page_ajax/page_list.html', postrecs=MWiki.query_pager_by_kind(kind=kind, current_page_num=current_page_number), kwd=kwd)
python
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, 'page_count': MWiki.get_counts(), } self.render('admin/page_ajax/page_list.html', postrecs=MWiki.query_pager_by_kind(kind=kind, current_page_num=current_page_number), kwd=kwd)
[ "def", "p_list", "(", "self", ",", "kind", ",", "cur_p", "=", "''", ",", ")", ":", "if", "cur_p", "==", "''", ":", "current_page_number", "=", "1", "else", ":", "current_page_number", "=", "int", "(", "cur_p", ")", "current_page_number", "=", "1", "if"...
List the post .
[ "List", "the", "post", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/page_ajax_handler.py#L68-L92
5,018
bukun/TorCMS
torcms/model/user_model.py
MUser.set_sendemail_time
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()
python
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", "set_sendemail_time", "(", "uid", ")", ":", "entry", "=", "TabMember", ".", "update", "(", "time_email", "=", "tools", ".", "timestamp", "(", ")", ",", ")", ".", "where", "(", "TabMember", ".", "uid", "==", "uid", ")", "entry", ".", "execute", ...
Set the time that send E-mail to user.
[ "Set", "the", "time", "that", "send", "E", "-", "mail", "to", "user", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/user_model.py#L46-L53
5,019
bukun/TorCMS
torcms/model/user_model.py
MUser.check_user
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 the_user = TabMember.get(uid=user_id) if the_user.user_pass == tools.md5(u_pass): return 1 return 0
python
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 the_user = TabMember.get(uid=user_id) if the_user.user_pass == tools.md5(u_pass): return 1 return 0
[ "def", "check_user", "(", "user_id", ",", "u_pass", ")", ":", "user_count", "=", "TabMember", ".", "select", "(", ")", ".", "where", "(", "TabMember", ".", "uid", "==", "user_id", ")", ".", "count", "(", ")", "if", "user_count", "==", "0", ":", "retu...
Checking the password by user's ID.
[ "Checking", "the", "password", "by", "user", "s", "ID", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/user_model.py#L66-L76
5,020
bukun/TorCMS
torcms/model/user_model.py
MUser.check_user_by_name
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 the_user = the_query.get() if the_user.user_pass == tools.md5(u_pass): return 1 return 0
python
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 the_user = the_query.get() if the_user.user_pass == tools.md5(u_pass): return 1 return 0
[ "def", "check_user_by_name", "(", "user_name", ",", "u_pass", ")", ":", "the_query", "=", "TabMember", ".", "select", "(", ")", ".", "where", "(", "TabMember", ".", "user_name", "==", "user_name", ")", "if", "the_query", ".", "count", "(", ")", "==", "0"...
Checking the password by user's name.
[ "Checking", "the", "password", "by", "user", "s", "name", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/user_model.py#L79-L90
5,021
bukun/TorCMS
torcms/model/user_model.py
MUser.update_pass
def update_pass(user_id, newpass): ''' Update the password of a user. ''' out_dic = {'success': False, 'code': '00'} entry = TabMember.update(user_pass=tools.md5(newpass)).where(TabMember.uid == user_id) entry.execute() out_dic['success'] = True return out_dic
python
def update_pass(user_id, newpass): ''' Update the password of a user. ''' out_dic = {'success': False, 'code': '00'} entry = TabMember.update(user_pass=tools.md5(newpass)).where(TabMember.uid == user_id) entry.execute() out_dic['success'] = True return out_dic
[ "def", "update_pass", "(", "user_id", ",", "newpass", ")", ":", "out_dic", "=", "{", "'success'", ":", "False", ",", "'code'", ":", "'00'", "}", "entry", "=", "TabMember", ".", "update", "(", "user_pass", "=", "tools", ".", "md5", "(", "newpass", ")", ...
Update the password of a user.
[ "Update", "the", "password", "of", "a", "user", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/user_model.py#L93-L105
5,022
bukun/TorCMS
torcms/model/user_model.py
MUser.update_time_reset_passwd
def update_time_reset_passwd(user_name, the_time): ''' Update the time when user reset passwd. ''' entry = TabMember.update( time_reset_passwd=the_time, ).where(TabMember.user_name == user_name) try: entry.execute() return True except: return False
python
def update_time_reset_passwd(user_name, the_time): ''' Update the time when user reset passwd. ''' entry = TabMember.update( time_reset_passwd=the_time, ).where(TabMember.user_name == user_name) try: entry.execute() return True except: return False
[ "def", "update_time_reset_passwd", "(", "user_name", ",", "the_time", ")", ":", "entry", "=", "TabMember", ".", "update", "(", "time_reset_passwd", "=", "the_time", ",", ")", ".", "where", "(", "TabMember", ".", "user_name", "==", "user_name", ")", "try", ":...
Update the time when user reset passwd.
[ "Update", "the", "time", "when", "user", "reset", "passwd", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/user_model.py#L158-L169
5,023
bukun/TorCMS
torcms/model/user_model.py
MUser.update_role
def update_role(u_name, newprivilege): ''' Update the role of the usr. ''' entry = TabMember.update( role=newprivilege ).where(TabMember.user_name == u_name) try: entry.execute() return True except: return False
python
def update_role(u_name, newprivilege): ''' Update the role of the usr. ''' entry = TabMember.update( role=newprivilege ).where(TabMember.user_name == u_name) try: entry.execute() return True except: return False
[ "def", "update_role", "(", "u_name", ",", "newprivilege", ")", ":", "entry", "=", "TabMember", ".", "update", "(", "role", "=", "newprivilege", ")", ".", "where", "(", "TabMember", ".", "user_name", "==", "u_name", ")", "try", ":", "entry", ".", "execute...
Update the role of the usr.
[ "Update", "the", "role", "of", "the", "usr", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/user_model.py#L172-L183
5,024
bukun/TorCMS
torcms/model/user_model.py
MUser.update_time_login
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()
python
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", "update_time_login", "(", "u_name", ")", ":", "entry", "=", "TabMember", ".", "update", "(", "time_login", "=", "tools", ".", "timestamp", "(", ")", ")", ".", "where", "(", "TabMember", ".", "user_name", "==", "u_name", ")", "entry", ".", "execute...
Update the login time for user.
[ "Update", "the", "login", "time", "for", "user", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/user_model.py#L186-L195
5,025
bukun/TorCMS
torcms/model/user_model.py
MUser.delete_by_user_name
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) del_count.execute() return True except: return False
python
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) del_count.execute() return True except: return False
[ "def", "delete_by_user_name", "(", "user_name", ")", ":", "try", ":", "del_count", "=", "TabMember", ".", "delete", "(", ")", ".", "where", "(", "TabMember", ".", "user_name", "==", "user_name", ")", "del_count", ".", "execute", "(", ")", "return", "True",...
Delete user in the database by `user_name`.
[ "Delete", "user", "in", "the", "database", "by", "user_name", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/user_model.py#L241-L250
5,026
bukun/TorCMS
torcms/model/user_model.py
MUser.delete
def delete(user_id): ''' Delele the user in the database by `user_id`. ''' try: del_count = TabMember.delete().where(TabMember.uid == user_id) del_count.execute() return True except: return False
python
def delete(user_id): ''' Delele the user in the database by `user_id`. ''' try: del_count = TabMember.delete().where(TabMember.uid == user_id) del_count.execute() return True except: return False
[ "def", "delete", "(", "user_id", ")", ":", "try", ":", "del_count", "=", "TabMember", ".", "delete", "(", ")", ".", "where", "(", "TabMember", ".", "uid", "==", "user_id", ")", "del_count", ".", "execute", "(", ")", "return", "True", "except", ":", "...
Delele the user in the database by `user_id`.
[ "Delele", "the", "user", "in", "the", "database", "by", "user_id", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/user_model.py#L253-L262
5,027
bukun/TorCMS
helper_scripts/script_meta_xlsx_import_v2.py
get_meta
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'] = 'admin' pp_data['def_cat_uid'] = catid pp_data['gcat0'] = catid pp_data['def_cat_pid'] = catid[:2] + '00' pp_data['extinfo'] = {} elif uu.name.startswith('thumbnail_'): pp_data['logo'] = os.path.join(wroot, wdir, uu.name).strip('.') return pp_data
python
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'] = 'admin' pp_data['def_cat_uid'] = catid pp_data['gcat0'] = catid pp_data['def_cat_pid'] = catid[:2] + '00' pp_data['extinfo'] = {} elif uu.name.startswith('thumbnail_'): pp_data['logo'] = os.path.join(wroot, wdir, uu.name).strip('.') return pp_data
[ "def", "get_meta", "(", "catid", ",", "sig", ")", ":", "meta_base", "=", "'./static/dataset_list'", "if", "os", ".", "path", ".", "exists", "(", "meta_base", ")", ":", "pass", "else", ":", "return", "False", "pp_data", "=", "{", "'logo'", ":", "''", ",...
Get metadata of dataset via ID.
[ "Get", "metadata", "of", "dataset", "via", "ID", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/helper_scripts/script_meta_xlsx_import_v2.py#L29-L59
5,028
bukun/TorCMS
torcms/handlers/post_handler.py
update_label
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 == '': pass else: MPost2Label.add_record(signature, tag_name, 1) for cur_info in current_tag_infos: if cur_info.tag_name in tags_arr: pass else: MPost2Label.remove_relation(signature, cur_info.tag_id)
python
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 == '': pass else: MPost2Label.add_record(signature, tag_name, 1) for cur_info in current_tag_infos: if cur_info.tag_name in tags_arr: pass else: MPost2Label.remove_relation(signature, cur_info.tag_id)
[ "def", "update_label", "(", "signature", ",", "post_data", ")", ":", "current_tag_infos", "=", "MPost2Label", ".", "get_by_uid", "(", "signature", ")", ".", "objects", "(", ")", "if", "'tags'", "in", "post_data", ":", "pass", "else", ":", "return", "False", ...
Update the label when updating.
[ "Update", "the", "label", "when", "updating", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/post_handler.py#L93-L114
5,029
bukun/TorCMS
torcms/handlers/post_handler.py
PostHandler.index
def index(self): ''' The default page of POST. ''' self.render('post_{0}/post_index.html'.format(self.kind), userinfo=self.userinfo, kwd={'uid': '', })
python
def index(self): ''' The default page of POST. ''' self.render('post_{0}/post_index.html'.format(self.kind), userinfo=self.userinfo, kwd={'uid': '', })
[ "def", "index", "(", "self", ")", ":", "self", ".", "render", "(", "'post_{0}/post_index.html'", ".", "format", "(", "self", ".", "kind", ")", ",", "userinfo", "=", "self", ".", "userinfo", ",", "kwd", "=", "{", "'uid'", ":", "''", ",", "}", ")" ]
The default page of POST.
[ "The", "default", "page", "of", "POST", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/post_handler.py#L182-L188
5,030
bukun/TorCMS
torcms/handlers/post_handler.py
PostHandler._view_or_add
def _view_or_add(self, uid): ''' Try to get the post. If not, to add the wiki. ''' postinfo = MPost.get_by_uid(uid) if postinfo: self.viewinfo(postinfo) elif self.userinfo: self._to_add(uid=uid) else: self.show404()
python
def _view_or_add(self, uid): ''' Try to get the post. If not, to add the wiki. ''' postinfo = MPost.get_by_uid(uid) if postinfo: self.viewinfo(postinfo) elif self.userinfo: self._to_add(uid=uid) else: self.show404()
[ "def", "_view_or_add", "(", "self", ",", "uid", ")", ":", "postinfo", "=", "MPost", ".", "get_by_uid", "(", "uid", ")", "if", "postinfo", ":", "self", ".", "viewinfo", "(", "postinfo", ")", "elif", "self", ".", "userinfo", ":", "self", ".", "_to_add", ...
Try to get the post. If not, to add the wiki.
[ "Try", "to", "get", "the", "post", ".", "If", "not", "to", "add", "the", "wiki", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/post_handler.py#L244-L254
5,031
bukun/TorCMS
torcms/handlers/post_handler.py
PostHandler._to_add
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: uid = '' self.render('post_{0}/post_add.html'.format(self.kind), tag_infos=MCategory.query_all(by_order=True, kind=self.kind), userinfo=self.userinfo, kwd={'uid': uid, })
python
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: uid = '' self.render('post_{0}/post_add.html'.format(self.kind), tag_infos=MCategory.query_all(by_order=True, kind=self.kind), userinfo=self.userinfo, kwd={'uid': uid, })
[ "def", "_to_add", "(", "self", ",", "*", "*", "kwargs", ")", ":", "if", "'catid'", "in", "kwargs", ":", "catid", "=", "kwargs", "[", "'catid'", "]", "return", "self", ".", "_to_add_with_category", "(", "catid", ")", "else", ":", "if", "'uid'", "in", ...
Used for info1.
[ "Used", "for", "info1", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/post_handler.py#L258-L277
5,032
bukun/TorCMS
torcms/handlers/post_handler.py
PostHandler._to_edit
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 self.filter_view: tmpl = 'autogen/edit/edit_{0}.html'.format(catid) else: tmpl = 'post_{0}/post_edit.html'.format(self.kind) logger.info('Meta template: {0}'.format(tmpl)) self.render( tmpl, kwd=kwd, postinfo=postinfo, catinfo=catinfo, pcatinfo=p_catinfo, userinfo=self.userinfo, cat_enum=MCategory.get_qian2(catid[:2]), tag_infos=MCategory.query_all(by_order=True, kind=self.kind), tag_infos2=MCategory.query_all(by_order=True, kind=self.kind), app2tag_info=MPost2Catalog.query_by_entity_uid(infoid, kind=self.kind).objects(), app2label_info=MPost2Label.get_by_uid(infoid).objects() )
python
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 self.filter_view: tmpl = 'autogen/edit/edit_{0}.html'.format(catid) else: tmpl = 'post_{0}/post_edit.html'.format(self.kind) logger.info('Meta template: {0}'.format(tmpl)) self.render( tmpl, kwd=kwd, postinfo=postinfo, catinfo=catinfo, pcatinfo=p_catinfo, userinfo=self.userinfo, cat_enum=MCategory.get_qian2(catid[:2]), tag_infos=MCategory.query_all(by_order=True, kind=self.kind), tag_infos2=MCategory.query_all(by_order=True, kind=self.kind), app2tag_info=MPost2Catalog.query_by_entity_uid(infoid, kind=self.kind).objects(), app2label_info=MPost2Label.get_by_uid(infoid).objects() )
[ "def", "_to_edit", "(", "self", ",", "infoid", ")", ":", "postinfo", "=", "MPost", ".", "get_by_uid", "(", "infoid", ")", "if", "postinfo", ":", "pass", "else", ":", "return", "self", ".", "show404", "(", ")", "if", "'def_cat_uid'", "in", "postinfo", "...
render the HTML page for post editing.
[ "render", "the", "HTML", "page", "for", "post", "editing", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/post_handler.py#L281-L343
5,033
bukun/TorCMS
torcms/handlers/post_handler.py
PostHandler._gen_last_current_relation
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') if last_post_id: last_post_id = last_post_id.decode('utf-8') self.set_secure_cookie('last_post_uid', post_id) if last_post_id and MPost.get_by_uid(last_post_id): self._add_relation(last_post_id, post_id)
python
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') if last_post_id: last_post_id = last_post_id.decode('utf-8') self.set_secure_cookie('last_post_uid', post_id) if last_post_id and MPost.get_by_uid(last_post_id): self._add_relation(last_post_id, post_id)
[ "def", "_gen_last_current_relation", "(", "self", ",", "post_id", ")", ":", "last_post_id", "=", "self", ".", "get_secure_cookie", "(", "'last_post_uid'", ")", "if", "last_post_id", ":", "last_post_id", "=", "last_post_id", ".", "decode", "(", "'utf-8'", ")", "s...
Generate the relation for the post and last post viewed.
[ "Generate", "the", "relation", "for", "the", "post", "and", "last", "post", "viewed", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/post_handler.py#L345-L355
5,034
bukun/TorCMS
torcms/handlers/post_handler.py
PostHandler.fetch_additional_posts
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())) if cat_uid_arr: rand_recs = MPost.query_cat_random(cat_uid_arr[0], limit=4 - rel_recs.count() + 4) else: rand_recs = MPost.query_random(num=4 - rel_recs.count() + 4, kind=self.kind) return rand_recs, rel_recs
python
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())) if cat_uid_arr: rand_recs = MPost.query_cat_random(cat_uid_arr[0], limit=4 - rel_recs.count() + 4) else: rand_recs = MPost.query_random(num=4 - rel_recs.count() + 4, kind=self.kind) return rand_recs, rel_recs
[ "def", "fetch_additional_posts", "(", "self", ",", "uid", ")", ":", "cats", "=", "MPost2Catalog", ".", "query_by_entity_uid", "(", "uid", ",", "kind", "=", "self", ".", "kind", ")", "cat_uid_arr", "=", "[", "]", "for", "cat_rec", "in", "cats", ":", "cat_...
fetch the rel_recs, and random recs when view the post.
[ "fetch", "the", "rel_recs", "and", "random", "recs", "when", "view", "the", "post", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/post_handler.py#L455-L472
5,035
bukun/TorCMS
torcms/handlers/post_handler.py
PostHandler._delete
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']) if router_post[self.kind] == 'info': url = "filter" id_dk8 = current_infor.extinfo['def_cat_uid'] else: url = "list" id_dk8 = tslug.slug self.redirect('/{0}/{1}'.format(url, id_dk8)) else: self.redirect('/{0}/{1}'.format(router_post[self.kind], uid))
python
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']) if router_post[self.kind] == 'info': url = "filter" id_dk8 = current_infor.extinfo['def_cat_uid'] else: url = "list" id_dk8 = tslug.slug self.redirect('/{0}/{1}'.format(url, id_dk8)) else: self.redirect('/{0}/{1}'.format(router_post[self.kind], uid))
[ "def", "_delete", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "_", "=", "kwargs", "uid", "=", "args", "[", "0", "]", "current_infor", "=", "MPost", ".", "get_by_uid", "(", "uid", ")", "if", "MPost", ".", "delete", "(", "uid"...
delete the post.
[ "delete", "the", "post", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/post_handler.py#L622-L647
5,036
bukun/TorCMS
torcms/handlers/post_handler.py
PostHandler._chuli_cookie_relation
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') self.set_secure_cookie('use_app_uid', app_id) if last_app_uid and MPost.get_by_uid(last_app_uid): self._add_relation(last_app_uid, app_id)
python
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') self.set_secure_cookie('use_app_uid', app_id) if last_app_uid and MPost.get_by_uid(last_app_uid): self._add_relation(last_app_uid, app_id)
[ "def", "_chuli_cookie_relation", "(", "self", ",", "app_id", ")", ":", "last_app_uid", "=", "self", ".", "get_secure_cookie", "(", "'use_app_uid'", ")", "if", "last_app_uid", ":", "last_app_uid", "=", "last_app_uid", ".", "decode", "(", "'utf-8'", ")", "self", ...
The current Info and the Info viewed last should have some relation. And the last viewed Info could be found from cookie.
[ "The", "current", "Info", "and", "the", "Info", "viewed", "last", "should", "have", "some", "relation", ".", "And", "the", "last", "viewed", "Info", "could", "be", "found", "from", "cookie", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/post_handler.py#L649-L659
5,037
bukun/TorCMS
torcms/handlers/post_handler.py
PostHandler._to_edit_kind
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', postinfo=postinfo, sig_dic=router_post, userinfo=self.userinfo, json_cnt=json_cnt, kwd=kwd)
python
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', postinfo=postinfo, sig_dic=router_post, userinfo=self.userinfo, json_cnt=json_cnt, kwd=kwd)
[ "def", "_to_edit_kind", "(", "self", ",", "post_uid", ")", ":", "if", "self", ".", "userinfo", "and", "self", ".", "userinfo", ".", "role", "[", "1", "]", ">=", "'3'", ":", "pass", "else", ":", "self", ".", "redirect", "(", "'/'", ")", "postinfo", ...
Show the page for changing the category.
[ "Show", "the", "page", "for", "changing", "the", "category", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/post_handler.py#L691-L707
5,038
bukun/TorCMS
torcms/handlers/post_handler.py
PostHandler._change_kind
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']) # self.update_category(post_uid) update_category(post_uid, post_data) self.redirect('/{0}/{1}'.format(router_post[post_data['kcat']], post_uid))
python
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']) # self.update_category(post_uid) update_category(post_uid, post_data) self.redirect('/{0}/{1}'.format(router_post[post_data['kcat']], post_uid))
[ "def", "_change_kind", "(", "self", ",", "post_uid", ")", ":", "post_data", "=", "self", ".", "get_post_data", "(", ")", "logger", ".", "info", "(", "'admin post update: {0}'", ".", "format", "(", "post_data", ")", ")", "MPost", ".", "update_misc", "(", "p...
To modify the category of the post, and kind.
[ "To", "modify", "the", "category", "of", "the", "post", "and", "kind", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/post_handler.py#L711-L724
5,039
bukun/TorCMS
torcms/handlers/entity_handler.py
EntityHandler.list
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 } recs = MEntity.get_all_pager(current_page_num=current_page_number) self.render('misc/entity/entity_list.html', imgs=recs, cfg=config.CMS_CFG, kwd=kwd, userinfo=self.userinfo)
python
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 } recs = MEntity.get_all_pager(current_page_num=current_page_number) self.render('misc/entity/entity_list.html', imgs=recs, cfg=config.CMS_CFG, kwd=kwd, userinfo=self.userinfo)
[ "def", "list", "(", "self", ",", "cur_p", "=", "''", ")", ":", "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", "...
Lists of the entities.
[ "Lists", "of", "the", "entities", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/entity_handler.py#L71-L86
5,040
bukun/TorCMS
torcms/handlers/entity_handler.py
EntityHandler.down
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 = MEntity.get_id_by_impath(str_down_url) if ment_id: MEntity2User.create_entity2user(ment_id, self.userinfo.uid) return True else: return False
python
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 = MEntity.get_id_by_impath(str_down_url) if ment_id: MEntity2User.create_entity2user(ment_id, self.userinfo.uid) return True else: return False
[ "def", "down", "(", "self", ",", "down_uid", ")", ":", "down_url", "=", "MPost", ".", "get_by_uid", "(", "down_uid", ")", ".", "extinfo", ".", "get", "(", "'tag__file_download'", ",", "''", ")", "print", "(", "'='", "*", "40", ")", "print", "(", "dow...
Download the entity by UID.
[ "Download", "the", "entity", "by", "UID", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/entity_handler.py#L89-L105
5,041
bukun/TorCMS
torcms/handlers/entity_handler.py
EntityHandler.to_add
def to_add(self): ''' To add the entity. ''' kwd = { 'pager': '', } self.render('misc/entity/entity_add.html', cfg=config.CMS_CFG, kwd=kwd, userinfo=self.userinfo)
python
def to_add(self): ''' To add the entity. ''' kwd = { 'pager': '', } self.render('misc/entity/entity_add.html', cfg=config.CMS_CFG, kwd=kwd, userinfo=self.userinfo)
[ "def", "to_add", "(", "self", ")", ":", "kwd", "=", "{", "'pager'", ":", "''", ",", "}", "self", ".", "render", "(", "'misc/entity/entity_add.html'", ",", "cfg", "=", "config", ".", "CMS_CFG", ",", "kwd", "=", "kwd", ",", "userinfo", "=", "self", "."...
To add the entity.
[ "To", "add", "the", "entity", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/entity_handler.py#L108-L118
5,042
bukun/TorCMS
torcms/handlers/entity_handler.py
EntityHandler.add_entity
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': self.add_pic(post_data) elif post_data['kind'] == '2': self.add_pdf(post_data) elif post_data['kind'] == '3': self.add_url(post_data) else: pass else: self.add_pic(post_data)
python
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': self.add_pic(post_data) elif post_data['kind'] == '2': self.add_pdf(post_data) elif post_data['kind'] == '3': self.add_url(post_data) else: pass else: self.add_pic(post_data)
[ "def", "add_entity", "(", "self", ")", ":", "post_data", "=", "self", ".", "get_post_data", "(", ")", "if", "'kind'", "in", "post_data", ":", "if", "post_data", "[", "'kind'", "]", "==", "'1'", ":", "self", ".", "add_pic", "(", "post_data", ")", "elif"...
Add the entity. All the information got from the post data.
[ "Add", "the", "entity", ".", "All", "the", "information", "got", "from", "the", "post", "data", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/entity_handler.py#L121-L137
5,043
bukun/TorCMS
torcms/handlers/entity_handler.py
EntityHandler.add_pic
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') im0.thumbnail(thub_size) im0.save(imgpath_sm, 'JPEG') create_pic = MEntity.create_entity(signature, path_save, post_data['desc'] if 'desc' in post_data else '', kind=post_data['kind'] if 'kind' in post_data else '1') if self.entity_ajax == False: self.redirect('/entity/{0}_m.jpg'.format(sig_save)) else: if create_pic: output = {'path_save': imgpath} else: output = {'path_save': ''} return json.dump(output, self)
python
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') im0.thumbnail(thub_size) im0.save(imgpath_sm, 'JPEG') create_pic = MEntity.create_entity(signature, path_save, post_data['desc'] if 'desc' in post_data else '', kind=post_data['kind'] if 'kind' in post_data else '1') if self.entity_ajax == False: self.redirect('/entity/{0}_m.jpg'.format(sig_save)) else: if create_pic: output = {'path_save': imgpath} else: output = {'path_save': ''} return json.dump(output, self)
[ "def", "add_pic", "(", "self", ",", "post_data", ")", ":", "img_entity", "=", "self", ".", "request", ".", "files", "[", "'file'", "]", "[", "0", "]", "filename", "=", "img_entity", "[", "\"filename\"", "]", "if", "filename", "and", "allowed_file", "(", ...
Adding the picture.
[ "Adding", "the", "picture", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/entity_handler.py#L140-L193
5,044
bukun/TorCMS
torcms/handlers/entity_handler.py
EntityHandler.add_pdf
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 = os.path.join(signature[:2], signature) path_save = os.path.join(signature[:2], outfilename) create_pdf = MEntity.create_entity(signature, path_save, img_desc, kind=post_data['kind'] if 'kind' in post_data else '2') if self.entity_ajax == False: self.redirect('/entity/{0}{1}'.format(sig_save, hou.lower())) else: if create_pdf: output = {'path_save': path_save} else: output = {'path_save': ''} return json.dump(output, self)
python
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 = os.path.join(signature[:2], signature) path_save = os.path.join(signature[:2], outfilename) create_pdf = MEntity.create_entity(signature, path_save, img_desc, kind=post_data['kind'] if 'kind' in post_data else '2') if self.entity_ajax == False: self.redirect('/entity/{0}{1}'.format(sig_save, hou.lower())) else: if create_pdf: output = {'path_save': path_save} else: output = {'path_save': ''} return json.dump(output, self)
[ "def", "add_pdf", "(", "self", ",", "post_data", ")", ":", "img_entity", "=", "self", ".", "request", ".", "files", "[", "'file'", "]", "[", "0", "]", "img_desc", "=", "post_data", "[", "'desc'", "]", "filename", "=", "img_entity", "[", "\"filename\"", ...
Adding the pdf file.
[ "Adding", "the", "pdf", "file", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/entity_handler.py#L196-L232
5,045
bukun/TorCMS
torcms/handlers/entity_handler.py
EntityHandler.add_url
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 = { 'kind': post_data['kind'] if 'kind' in post_data else '3', } self.render('misc/entity/entity_view.html', filename=img_path, cfg=config.CMS_CFG, kwd=kwd, userinfo=self.userinfo)
python
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 = { 'kind': post_data['kind'] if 'kind' in post_data else '3', } self.render('misc/entity/entity_view.html', filename=img_path, cfg=config.CMS_CFG, kwd=kwd, userinfo=self.userinfo)
[ "def", "add_url", "(", "self", ",", "post_data", ")", ":", "img_desc", "=", "post_data", "[", "'desc'", "]", "img_path", "=", "post_data", "[", "'file1'", "]", "cur_uid", "=", "tools", ".", "get_uudd", "(", "4", ")", "while", "MEntity", ".", "get_by_uid"...
Adding the URL as entity.
[ "Adding", "the", "URL", "as", "entity", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/entity_handler.py#L235-L253
5,046
bukun/TorCMS
torcms/handlers/user_handler.py
UserHandler.p_changepassword
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']) output = {'changepass ': usercheck} else: output = {'changepass ': 0} return json.dump(output, self)
python
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']) output = {'changepass ': usercheck} else: output = {'changepass ': 0} return json.dump(output, self)
[ "def", "p_changepassword", "(", "self", ")", ":", "post_data", "=", "self", ".", "get_post_data", "(", ")", "usercheck", "=", "MUser", ".", "check_user", "(", "self", ".", "userinfo", ".", "uid", ",", "post_data", "[", "'rawpass'", "]", ")", "if", "userc...
Changing password.
[ "Changing", "password", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/user_handler.py#L120-L133
5,047
bukun/TorCMS
torcms/handlers/user_handler.py
UserHandler.p_changeinfo
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: MUser.update_info(self.userinfo.uid, post_data['user_email'], extinfo=def_dic) output = {'changeinfo ': usercheck} else: output = {'changeinfo ': 0} return json.dump(output, self)
python
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: MUser.update_info(self.userinfo.uid, post_data['user_email'], extinfo=def_dic) output = {'changeinfo ': usercheck} else: output = {'changeinfo ': 0} return json.dump(output, self)
[ "def", "p_changeinfo", "(", "self", ")", ":", "post_data", ",", "def_dic", "=", "self", ".", "fetch_post_data", "(", ")", "usercheck", "=", "MUser", ".", "check_user", "(", "self", ".", "userinfo", ".", "uid", ",", "post_data", "[", "'rawpass'", "]", ")"...
Change Infor via Ajax.
[ "Change", "Infor", "via", "Ajax", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/user_handler.py#L136-L149
5,048
bukun/TorCMS
torcms/handlers/user_handler.py
UserHandler.__check_valid
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 elif not tools.check_email_valid(post_data['user_email']): user_create_status['code'] = '21' return user_create_status elif MUser.get_by_name(post_data['user_name']): user_create_status['code'] = '12' return user_create_status elif MUser.get_by_email(post_data['user_email']): user_create_status['code'] = '22' return user_create_status user_create_status['success'] = True return user_create_status
python
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 elif not tools.check_email_valid(post_data['user_email']): user_create_status['code'] = '21' return user_create_status elif MUser.get_by_name(post_data['user_name']): user_create_status['code'] = '12' return user_create_status elif MUser.get_by_email(post_data['user_email']): user_create_status['code'] = '22' return user_create_status user_create_status['success'] = True return user_create_status
[ "def", "__check_valid", "(", "self", ",", "post_data", ")", ":", "user_create_status", "=", "{", "'success'", ":", "False", ",", "'code'", ":", "'00'", "}", "if", "not", "tools", ".", "check_username_valid", "(", "post_data", "[", "'user_name'", "]", ")", ...
To check if the user is succesfully created. Return the status code dict.
[ "To", "check", "if", "the", "user", "is", "succesfully", "created", ".", "Return", "the", "status", "code", "dict", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/user_handler.py#L333-L354
5,049
bukun/TorCMS
torcms/handlers/user_handler.py
UserHandler.p_to_find
def p_to_find(self, ): ''' To find, pager. ''' kwd = { 'pager': '', } self.render('user/user_find_list.html', kwd=kwd, view=MUser.get_by_keyword(""), cfg=config.CMS_CFG, userinfo=self.userinfo)
python
def p_to_find(self, ): ''' To find, pager. ''' kwd = { 'pager': '', } self.render('user/user_find_list.html', kwd=kwd, view=MUser.get_by_keyword(""), cfg=config.CMS_CFG, userinfo=self.userinfo)
[ "def", "p_to_find", "(", "self", ",", ")", ":", "kwd", "=", "{", "'pager'", ":", "''", ",", "}", "self", ".", "render", "(", "'user/user_find_list.html'", ",", "kwd", "=", "kwd", ",", "view", "=", "MUser", ".", "get_by_keyword", "(", "\"\"", ")", ","...
To find, pager.
[ "To", "find", "pager", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/user_handler.py#L584-L596
5,050
bukun/TorCMS
torcms/handlers/sys_handler.py
SysHandler.set_language
def set_language(self, language): ''' Set the cookie for locale. ''' if language == 'ZH': self.set_cookie('ulocale', 'zh_CN') self.set_cookie('blocale', 'zh_CN') else: self.set_cookie('ulocale', 'en_US') self.set_cookie('blocale', 'en_US')
python
def set_language(self, language): ''' Set the cookie for locale. ''' if language == 'ZH': self.set_cookie('ulocale', 'zh_CN') self.set_cookie('blocale', 'zh_CN') else: self.set_cookie('ulocale', 'en_US') self.set_cookie('blocale', 'en_US')
[ "def", "set_language", "(", "self", ",", "language", ")", ":", "if", "language", "==", "'ZH'", ":", "self", ".", "set_cookie", "(", "'ulocale'", ",", "'zh_CN'", ")", "self", ".", "set_cookie", "(", "'blocale'", ",", "'zh_CN'", ")", "else", ":", "self", ...
Set the cookie for locale.
[ "Set", "the", "cookie", "for", "locale", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/sys_handler.py#L54-L63
5,051
bukun/TorCMS
torcms/script/autocrud/func_gen_html.py
gen_input_add
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'] ) else: html_str = HTML_TPL_DICT['input_add'].format( sig_en=sig_dic['en'], sig_zh=sig_dic['zh'], sig_dic=sig_dic['dic'][1], sig_type=sig_dic['type'] ) return html_str
python
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'] ) else: html_str = HTML_TPL_DICT['input_add'].format( sig_en=sig_dic['en'], sig_zh=sig_dic['zh'], sig_dic=sig_dic['dic'][1], sig_type=sig_dic['type'] ) return html_str
[ "def", "gen_input_add", "(", "sig_dic", ")", ":", "if", "sig_dic", "[", "'en'", "]", "==", "'tag_file_download'", ":", "html_str", "=", "HTML_TPL_DICT", "[", "'input_add_download'", "]", ".", "format", "(", "sig_en", "=", "sig_dic", "[", "'en'", "]", ",", ...
Adding for HTML Input control.
[ "Adding", "for", "HTML", "Input", "control", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/script/autocrud/func_gen_html.py#L10-L28
5,052
bukun/TorCMS
torcms/script/autocrud/func_gen_html.py
gen_input_edit
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'] ) else: html_str = HTML_TPL_DICT['input_edit'].format( sig_en=sig_dic['en'], sig_zh=sig_dic['zh'], sig_dic=sig_dic['dic'][1], sig_type=sig_dic['type'] ) return html_str
python
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'] ) else: html_str = HTML_TPL_DICT['input_edit'].format( sig_en=sig_dic['en'], sig_zh=sig_dic['zh'], sig_dic=sig_dic['dic'][1], sig_type=sig_dic['type'] ) return html_str
[ "def", "gen_input_edit", "(", "sig_dic", ")", ":", "if", "sig_dic", "[", "'en'", "]", "==", "'tag_file_download'", ":", "html_str", "=", "HTML_TPL_DICT", "[", "'input_edit_download'", "]", ".", "format", "(", "sig_en", "=", "sig_dic", "[", "'en'", "]", ",", ...
Editing for HTML input control.
[ "Editing", "for", "HTML", "input", "control", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/script/autocrud/func_gen_html.py#L31-L49
5,053
bukun/TorCMS
torcms/script/autocrud/func_gen_html.py
gen_input_view
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( sig_dic['en'], sig_dic['zh'], sig_dic['dic'][1] ) else: html_str = HTML_TPL_DICT['input_view'].format( sig_dic['en'], sig_dic['zh'], sig_dic['dic'][1] ) return html_str
python
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( sig_dic['en'], sig_dic['zh'], sig_dic['dic'][1] ) else: html_str = HTML_TPL_DICT['input_view'].format( sig_dic['en'], sig_dic['zh'], sig_dic['dic'][1] ) return html_str
[ "def", "gen_input_view", "(", "sig_dic", ")", ":", "if", "sig_dic", "[", "'en'", "]", "==", "'tag_file_download'", ":", "html_str", "=", "HTML_TPL_DICT", "[", "'input_view_download'", "]", ".", "format", "(", "sig_zh", "=", "sig_dic", "[", "'zh'", "]", ",", ...
Viewing the HTML text.
[ "Viewing", "the", "HTML", "text", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/script/autocrud/func_gen_html.py#L52-L76
5,054
bukun/TorCMS
torcms/model/post_model.py
MPost.__update_rating
def __update_rating(uid, rating): ''' Update the rating for post. ''' entry = TabPost.update( rating=rating ).where(TabPost.uid == uid) entry.execute()
python
def __update_rating(uid, rating): ''' Update the rating for post. ''' entry = TabPost.update( rating=rating ).where(TabPost.uid == uid) entry.execute()
[ "def", "__update_rating", "(", "uid", ",", "rating", ")", ":", "entry", "=", "TabPost", ".", "update", "(", "rating", "=", "rating", ")", ".", "where", "(", "TabPost", ".", "uid", "==", "uid", ")", "entry", ".", "execute", "(", ")" ]
Update the rating for post.
[ "Update", "the", "rating", "for", "post", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L87-L94
5,055
bukun/TorCMS
torcms/model/post_model.py
MPost.__update_kind
def __update_kind(uid, kind): ''' update the kind of post. ''' entry = TabPost.update( kind=kind, ).where(TabPost.uid == uid) entry.execute() return True
python
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_kind", "(", "uid", ",", "kind", ")", ":", "entry", "=", "TabPost", ".", "update", "(", "kind", "=", "kind", ",", ")", ".", "where", "(", "TabPost", ".", "uid", "==", "uid", ")", "entry", ".", "execute", "(", ")", "return", "True" ]
update the kind of post.
[ "update", "the", "kind", "of", "post", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L97-L106
5,056
bukun/TorCMS
torcms/model/post_model.py
MPost.update_cnt
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()
python
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_cnt", "(", "uid", ",", "post_data", ")", ":", "entry", "=", "TabPost", ".", "update", "(", "cnt_html", "=", "tools", ".", "markdown2html", "(", "post_data", "[", "'cnt_md'", "]", ")", ",", "user_name", "=", "post_data", "[", "'user_name'", ...
update content.
[ "update", "content", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L117-L128
5,057
bukun/TorCMS
torcms/model/post_model.py
MPost.update_order
def update_order(uid, order): ''' Update the order of the posts. ''' entry = TabPost.update( order=order ).where(TabPost.uid == uid) entry.execute()
python
def update_order(uid, order): ''' Update the order of the posts. ''' entry = TabPost.update( order=order ).where(TabPost.uid == uid) entry.execute()
[ "def", "update_order", "(", "uid", ",", "order", ")", ":", "entry", "=", "TabPost", ".", "update", "(", "order", "=", "order", ")", ".", "where", "(", "TabPost", ".", "uid", "==", "uid", ")", "entry", ".", "execute", "(", ")" ]
Update the order of the posts.
[ "Update", "the", "order", "of", "the", "posts", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L131-L138
5,058
bukun/TorCMS
torcms/model/post_model.py
MPost.update
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=post_data.get('valid', 1) ).where(TabPost.uid == uid) entry.execute()
python
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=post_data.get('valid', 1) ).where(TabPost.uid == uid) entry.execute()
[ "def", "update", "(", "uid", ",", "post_data", ",", "update_time", "=", "False", ")", ":", "title", "=", "post_data", "[", "'title'", "]", ".", "strip", "(", ")", "if", "len", "(", "title", ")", "<", "2", ":", "return", "False", "cnt_html", "=", "t...
update the infor.
[ "update", "the", "infor", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L141-L175
5,059
bukun/TorCMS
torcms/model/post_model.py
MPost.add_or_update
def add_or_update(uid, post_data): ''' Add or update the post. ''' cur_rec = MPost.get_by_uid(uid) if cur_rec: MPost.update(uid, post_data) else: MPost.create_post(uid, post_data)
python
def add_or_update(uid, post_data): ''' Add or update the post. ''' cur_rec = MPost.get_by_uid(uid) if cur_rec: MPost.update(uid, post_data) else: MPost.create_post(uid, post_data)
[ "def", "add_or_update", "(", "uid", ",", "post_data", ")", ":", "cur_rec", "=", "MPost", ".", "get_by_uid", "(", "uid", ")", "if", "cur_rec", ":", "MPost", ".", "update", "(", "uid", ",", "post_data", ")", "else", ":", "MPost", ".", "create_post", "(",...
Add or update the post.
[ "Add", "or", "update", "the", "post", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L178-L186
5,060
bukun/TorCMS
torcms/model/post_model.py
MPost.create_post
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, 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=post_data.get('valid', 1) ) return entry.uid
python
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, 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=post_data.get('valid', 1) ) return entry.uid
[ "def", "create_post", "(", "post_uid", ",", "post_data", ")", ":", "title", "=", "post_data", "[", "'title'", "]", ".", "strip", "(", ")", "if", "len", "(", "title", ")", "<", "2", ":", "return", "False", "cur_rec", "=", "MPost", ".", "get_by_uid", "...
create the post.
[ "create", "the", "post", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L189-L220
5,061
bukun/TorCMS
torcms/model/post_model.py
MPost.query_cat_random
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) else: rand_recs = TabPost.select().join( TabPost2Tag, on=(TabPost.uid == TabPost2Tag.post_id) ).where( (TabPost.valid == 1) & (TabPost2Tag.tag_id == catid) ).order_by( peewee.fn.Random() ).limit(num) return rand_recs
python
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) else: rand_recs = TabPost.select().join( TabPost2Tag, on=(TabPost.uid == TabPost2Tag.post_id) ).where( (TabPost.valid == 1) & (TabPost2Tag.tag_id == catid) ).order_by( peewee.fn.Random() ).limit(num) return rand_recs
[ "def", "query_cat_random", "(", "catid", ",", "*", "*", "kwargs", ")", ":", "num", "=", "kwargs", ".", "get", "(", "'limit'", ",", "8", ")", "if", "catid", "==", "''", ":", "rand_recs", "=", "TabPost", ".", "select", "(", ")", ".", "order_by", "(",...
Get random lists of certain category.
[ "Get", "random", "lists", "of", "certain", "category", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L223-L239
5,062
bukun/TorCMS
torcms/model/post_model.py
MPost.query_random
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) ).order_by( peewee.fn.Random() ).limit(limit) else: rand_recs = TabPost.select().where( TabPost.valid == 1 ).order_by( peewee.fn.Random() ).limit(limit) return rand_recs
python
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) ).order_by( peewee.fn.Random() ).limit(limit) else: rand_recs = TabPost.select().where( TabPost.valid == 1 ).order_by( peewee.fn.Random() ).limit(limit) return rand_recs
[ "def", "query_random", "(", "*", "*", "kwargs", ")", ":", "if", "'limit'", "in", "kwargs", ":", "limit", "=", "kwargs", "[", "'limit'", "]", "elif", "'num'", "in", "kwargs", ":", "limit", "=", "kwargs", "[", "'num'", "]", "else", ":", "limit", "=", ...
Return the random records of centain kind.
[ "Return", "the", "random", "records", "of", "centain", "kind", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L242-L269
5,063
bukun/TorCMS
torcms/model/post_model.py
MPost.query_recent
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( (TabPost.kind == kind) & (TabPost.valid == 1) ).order_by( TabPost.time_update.desc() ).limit(num) else: recent_recs = TabPost.select().where( TabPost.valid == 1 ).order_by( TabPost.time_update.desc() ).limit(num) return recent_recs
python
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( (TabPost.kind == kind) & (TabPost.valid == 1) ).order_by( TabPost.time_update.desc() ).limit(num) else: recent_recs = TabPost.select().where( TabPost.valid == 1 ).order_by( TabPost.time_update.desc() ).limit(num) return recent_recs
[ "def", "query_recent", "(", "num", "=", "8", ",", "*", "*", "kwargs", ")", ":", "order_by_create", "=", "kwargs", ".", "get", "(", "'order_by_create'", ",", "False", ")", "kind", "=", "kwargs", ".", "get", "(", "'kind'", ",", "None", ")", "if", "orde...
query recent posts.
[ "query", "recent", "posts", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L272-L304
5,064
bukun/TorCMS
torcms/model/post_model.py
MPost.query_all
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) & (TabPost.valid == 1) ).order_by( TabPost.time_update.desc() ).limit(limit)
python
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) & (TabPost.valid == 1) ).order_by( TabPost.time_update.desc() ).limit(limit)
[ "def", "query_all", "(", "*", "*", "kwargs", ")", ":", "kind", "=", "kwargs", ".", "get", "(", "'kind'", ",", "'1'", ")", "limit", "=", "kwargs", ".", "get", "(", "'limit'", ",", "10", ")", "return", "TabPost", ".", "select", "(", ")", ".", "wher...
query all the posts.
[ "query", "all", "the", "posts", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L307-L319
5,065
bukun/TorCMS
torcms/model/post_model.py
MPost.query_keywords_empty
def query_keywords_empty(kind='1'): ''' Query keywords, empty. ''' return TabPost.select().where((TabPost.kind == kind) & (TabPost.keywords == ''))
python
def query_keywords_empty(kind='1'): ''' Query keywords, empty. ''' return TabPost.select().where((TabPost.kind == kind) & (TabPost.keywords == ''))
[ "def", "query_keywords_empty", "(", "kind", "=", "'1'", ")", ":", "return", "TabPost", ".", "select", "(", ")", ".", "where", "(", "(", "TabPost", ".", "kind", "==", "kind", ")", "&", "(", "TabPost", ".", "keywords", "==", "''", ")", ")" ]
Query keywords, empty.
[ "Query", "keywords", "empty", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L322-L326
5,066
bukun/TorCMS
torcms/model/post_model.py
MPost.query_recent_edited
def query_recent_edited(timstamp, kind='1'): ''' Query posts recently update. ''' return TabPost.select().where( (TabPost.kind == kind) & (TabPost.time_update > timstamp) ).order_by( TabPost.time_update.desc() )
python
def query_recent_edited(timstamp, kind='1'): ''' Query posts recently update. ''' return TabPost.select().where( (TabPost.kind == kind) & (TabPost.time_update > timstamp) ).order_by( TabPost.time_update.desc() )
[ "def", "query_recent_edited", "(", "timstamp", ",", "kind", "=", "'1'", ")", ":", "return", "TabPost", ".", "select", "(", ")", ".", "where", "(", "(", "TabPost", ".", "kind", "==", "kind", ")", "&", "(", "TabPost", ".", "time_update", ">", "timstamp",...
Query posts recently update.
[ "Query", "posts", "recently", "update", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L329-L338
5,067
bukun/TorCMS
torcms/model/post_model.py
MPost.query_dated
def query_dated(num=8, kind='1'): ''' Query posts, outdate. ''' return TabPost.select().where( TabPost.kind == kind ).order_by( TabPost.time_update.asc() ).limit(num)
python
def query_dated(num=8, kind='1'): ''' Query posts, outdate. ''' return TabPost.select().where( TabPost.kind == kind ).order_by( TabPost.time_update.asc() ).limit(num)
[ "def", "query_dated", "(", "num", "=", "8", ",", "kind", "=", "'1'", ")", ":", "return", "TabPost", ".", "select", "(", ")", ".", "where", "(", "TabPost", ".", "kind", "==", "kind", ")", ".", "order_by", "(", "TabPost", ".", "time_update", ".", "as...
Query posts, outdate.
[ "Query", "posts", "outdate", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L341-L349
5,068
bukun/TorCMS
torcms/model/post_model.py
MPost.query_most_pic
def query_most_pic(num, kind='1'): ''' Query most pics. ''' return TabPost.select().where( (TabPost.kind == kind) & (TabPost.logo != "") ).order_by(TabPost.view_count.desc()).limit(num)
python
def query_most_pic(num, kind='1'): ''' Query most pics. ''' return TabPost.select().where( (TabPost.kind == kind) & (TabPost.logo != "") ).order_by(TabPost.view_count.desc()).limit(num)
[ "def", "query_most_pic", "(", "num", ",", "kind", "=", "'1'", ")", ":", "return", "TabPost", ".", "select", "(", ")", ".", "where", "(", "(", "TabPost", ".", "kind", "==", "kind", ")", "&", "(", "TabPost", ".", "logo", "!=", "\"\"", ")", ")", "."...
Query most pics.
[ "Query", "most", "pics", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L352-L358
5,069
bukun/TorCMS
torcms/model/post_model.py
MPost.query_most
def query_most(num=8, kind='1'): ''' Query most viewed. ''' return TabPost.select().where( (TabPost.kind == kind) & (TabPost.valid == 1) ).order_by( TabPost.view_count.desc() ).limit(num)
python
def query_most(num=8, kind='1'): ''' Query most viewed. ''' return TabPost.select().where( (TabPost.kind == kind) & (TabPost.valid == 1) ).order_by( TabPost.view_count.desc() ).limit(num)
[ "def", "query_most", "(", "num", "=", "8", ",", "kind", "=", "'1'", ")", ":", "return", "TabPost", ".", "select", "(", ")", ".", "where", "(", "(", "TabPost", ".", "kind", "==", "kind", ")", "&", "(", "TabPost", ".", "valid", "==", "1", ")", ")...
Query most viewed.
[ "Query", "most", "viewed", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L487-L496
5,070
bukun/TorCMS
torcms/model/post_model.py
MPost.update_misc
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' in kwargs: MPost.__update_keywords(uid, kwargs['keywords']) elif 'count' in kwargs: MPost.__update_view_count(uid)
python
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' in kwargs: MPost.__update_keywords(uid, kwargs['keywords']) elif 'count' in kwargs: MPost.__update_view_count(uid)
[ "def", "update_misc", "(", "uid", ",", "*", "*", "kwargs", ")", ":", "if", "'rating'", "in", "kwargs", ":", "MPost", ".", "__update_rating", "(", "uid", ",", "kwargs", "[", "'rating'", "]", ")", "elif", "'kind'", "in", "kwargs", ":", "MPost", ".", "_...
update rating, kind, or count
[ "update", "rating", "kind", "or", "count" ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L499-L510
5,071
bukun/TorCMS
torcms/model/post_model.py
MPost.__update_keywords
def __update_keywords(uid, inkeywords): ''' Update with keywords. ''' entry = TabPost.update(keywords=inkeywords).where(TabPost.uid == uid) entry.execute()
python
def __update_keywords(uid, inkeywords): ''' Update with keywords. ''' entry = TabPost.update(keywords=inkeywords).where(TabPost.uid == uid) entry.execute()
[ "def", "__update_keywords", "(", "uid", ",", "inkeywords", ")", ":", "entry", "=", "TabPost", ".", "update", "(", "keywords", "=", "inkeywords", ")", ".", "where", "(", "TabPost", ".", "uid", "==", "uid", ")", "entry", ".", "execute", "(", ")" ]
Update with keywords.
[ "Update", "with", "keywords", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L524-L529
5,072
bukun/TorCMS
torcms/model/post_model.py
MPost.get_next_record
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( (TabPost.kind == kind) & (TabPost.time_create < current_rec.time_create) ).order_by(TabPost.time_create.desc()) if recs.count(): return recs.get() return None
python
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( (TabPost.kind == kind) & (TabPost.time_create < current_rec.time_create) ).order_by(TabPost.time_create.desc()) if recs.count(): return recs.get() return None
[ "def", "get_next_record", "(", "in_uid", ",", "kind", "=", "'1'", ")", ":", "current_rec", "=", "MPost", ".", "get_by_uid", "(", "in_uid", ")", "recs", "=", "TabPost", ".", "select", "(", ")", ".", "where", "(", "(", "TabPost", ".", "kind", "==", "ki...
Get next record by time_create.
[ "Get", "next", "record", "by", "time_create", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L532-L543
5,073
bukun/TorCMS
torcms/model/post_model.py
MPost.get_all
def get_all(kind='2'): ''' Get All the records. ''' return TabPost.select().where( (TabPost.kind == kind) & (TabPost.valid == 1) ).order_by( TabPost.time_update.desc() )
python
def get_all(kind='2'): ''' Get All the records. ''' return TabPost.select().where( (TabPost.kind == kind) & (TabPost.valid == 1) ).order_by( TabPost.time_update.desc() )
[ "def", "get_all", "(", "kind", "=", "'2'", ")", ":", "return", "TabPost", ".", "select", "(", ")", ".", "where", "(", "(", "TabPost", ".", "kind", "==", "kind", ")", "&", "(", "TabPost", ".", "valid", "==", "1", ")", ")", ".", "order_by", "(", ...
Get All the records.
[ "Get", "All", "the", "records", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L560-L569
5,074
bukun/TorCMS
torcms/model/post_model.py
MPost.update_jsonb
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( extinfo=cur_extinfo, ).where(TabPost.uid == uid) entry.execute() return uid
python
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( extinfo=cur_extinfo, ).where(TabPost.uid == uid) entry.execute() return uid
[ "def", "update_jsonb", "(", "uid", ",", "extinfo", ")", ":", "cur_extinfo", "=", "MPost", ".", "get_by_uid", "(", "uid", ")", ".", "extinfo", "for", "key", "in", "extinfo", ":", "cur_extinfo", "[", "key", "]", "=", "extinfo", "[", "key", "]", "entry", ...
Update the json.
[ "Update", "the", "json", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L572-L583
5,075
bukun/TorCMS
torcms/model/post_model.py
MPost.modify_meta
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
python
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", "modify_meta", "(", "uid", ",", "data_dic", ",", "extinfo", "=", "None", ")", ":", "if", "extinfo", "is", "None", ":", "extinfo", "=", "{", "}", "title", "=", "data_dic", "[", "'title'", "]", ".", "strip", "(", ")", "if", "len", "(", "title"...
update meta of the rec.
[ "update", "meta", "of", "the", "rec", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L586-L637
5,076
bukun/TorCMS
torcms/model/post_model.py
MPost.modify_init
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
python
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", "modify_init", "(", "uid", ",", "data_dic", ")", ":", "postinfo", "=", "MPost", ".", "get_by_uid", "(", "uid", ")", "entry", "=", "TabPost", ".", "update", "(", "time_update", "=", "tools", ".", "timestamp", "(", ")", ",", "date", "=", "datetime...
update when init.
[ "update", "when", "init", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L640-L652
5,077
bukun/TorCMS
torcms/model/post_model.py
MPost.query_under_condition
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( (TabPost.kind == kind) & (TabPost.valid == 1) ).order_by( TabPost.time_update.desc() ) return TabPost.select().where( (TabPost.kind == kind) & (TabPost.valid == 1) & TabPost.extinfo.contains(condition) ).order_by(TabPost.time_update.desc())
python
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( (TabPost.kind == kind) & (TabPost.valid == 1) ).order_by( TabPost.time_update.desc() ) return TabPost.select().where( (TabPost.kind == kind) & (TabPost.valid == 1) & TabPost.extinfo.contains(condition) ).order_by(TabPost.time_update.desc())
[ "def", "query_under_condition", "(", "condition", ",", "kind", "=", "'2'", ")", ":", "if", "DB_CFG", "[", "'kind'", "]", "==", "'s'", ":", "return", "TabPost", ".", "select", "(", ")", ".", "where", "(", "(", "TabPost", ".", "kind", "==", "kind", ")"...
Get All data of certain kind according to the condition
[ "Get", "All", "data", "of", "certain", "kind", "according", "to", "the", "condition" ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L771-L786
5,078
bukun/TorCMS
torcms/model/post_model.py
MPost.query_list_pager
def query_list_pager(con, idx, kind='2'): ''' Get records of certain pager. ''' all_list = MPost.query_under_condition(con, kind=kind) return all_list[(idx - 1) * CMS_CFG['list_num']: idx * CMS_CFG['list_num']]
python
def query_list_pager(con, idx, kind='2'): ''' Get records of certain pager. ''' all_list = MPost.query_under_condition(con, kind=kind) return all_list[(idx - 1) * CMS_CFG['list_num']: idx * CMS_CFG['list_num']]
[ "def", "query_list_pager", "(", "con", ",", "idx", ",", "kind", "=", "'2'", ")", ":", "all_list", "=", "MPost", ".", "query_under_condition", "(", "con", ",", "kind", "=", "kind", ")", "return", "all_list", "[", "(", "idx", "-", "1", ")", "*", "CMS_C...
Get records of certain pager.
[ "Get", "records", "of", "certain", "pager", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L830-L835
5,079
bukun/TorCMS
torcms/handlers/user_info_list_handler.py
UserListHandler.list_app
def list_app(self): ''' List the apps. ''' kwd = { 'pager': '', 'title': '' } self.render('user/info_list/list_app.html', kwd=kwd, userinfo=self.userinfo)
python
def list_app(self): ''' List the apps. ''' kwd = { 'pager': '', 'title': '' } self.render('user/info_list/list_app.html', kwd=kwd, userinfo=self.userinfo)
[ "def", "list_app", "(", "self", ")", ":", "kwd", "=", "{", "'pager'", ":", "''", ",", "'title'", ":", "''", "}", "self", ".", "render", "(", "'user/info_list/list_app.html'", ",", "kwd", "=", "kwd", ",", "userinfo", "=", "self", ".", "userinfo", ")" ]
List the apps.
[ "List", "the", "apps", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/user_info_list_handler.py#L36-L45
5,080
bukun/TorCMS
torcms/handlers/user_info_list_handler.py
UserListHandler.user_most
def user_most(self): ''' User most used. ''' kwd = { 'pager': '', 'title': '', } self.render('user/info_list/user_most.html', kwd=kwd, user_name=self.get_current_user(), userinfo=self.userinfo)
python
def user_most(self): ''' User most used. ''' kwd = { 'pager': '', 'title': '', } self.render('user/info_list/user_most.html', kwd=kwd, user_name=self.get_current_user(), userinfo=self.userinfo)
[ "def", "user_most", "(", "self", ")", ":", "kwd", "=", "{", "'pager'", ":", "''", ",", "'title'", ":", "''", ",", "}", "self", ".", "render", "(", "'user/info_list/user_most.html'", ",", "kwd", "=", "kwd", ",", "user_name", "=", "self", ".", "get_curre...
User most used.
[ "User", "most", "used", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/user_info_list_handler.py#L48-L59
5,081
bukun/TorCMS
torcms/handlers/user_info_list_handler.py
UserListHandler.user_recent
def user_recent(self): ''' User used recently. ''' kwd = { 'pager': '', 'title': '' } self.render('user/info_list/user_recent.html', kwd=kwd, user_name=self.get_current_user(), userinfo=self.userinfo)
python
def user_recent(self): ''' User used recently. ''' kwd = { 'pager': '', 'title': '' } self.render('user/info_list/user_recent.html', kwd=kwd, user_name=self.get_current_user(), userinfo=self.userinfo)
[ "def", "user_recent", "(", "self", ")", ":", "kwd", "=", "{", "'pager'", ":", "''", ",", "'title'", ":", "''", "}", "self", ".", "render", "(", "'user/info_list/user_recent.html'", ",", "kwd", "=", "kwd", ",", "user_name", "=", "self", ".", "get_current_...
User used recently.
[ "User", "used", "recently", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/user_info_list_handler.py#L62-L73
5,082
bukun/TorCMS
torcms/handlers/user_info_list_handler.py
UserListHandler.list_recent
def list_recent(self): ''' List the recent. ''' recs = MPost.query_recent(20) kwd = { 'pager': '', 'title': '', } self.render('user/info_list/list.html', kwd=kwd, rand_eqs=MPost.query_random(), recs=recs, userinfo=self.userinfo)
python
def list_recent(self): ''' List the recent. ''' recs = MPost.query_recent(20) kwd = { 'pager': '', 'title': '', } self.render('user/info_list/list.html', kwd=kwd, rand_eqs=MPost.query_random(), recs=recs, userinfo=self.userinfo)
[ "def", "list_recent", "(", "self", ")", ":", "recs", "=", "MPost", ".", "query_recent", "(", "20", ")", "kwd", "=", "{", "'pager'", ":", "''", ",", "'title'", ":", "''", ",", "}", "self", ".", "render", "(", "'user/info_list/list.html'", ",", "kwd", ...
List the recent.
[ "List", "the", "recent", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/user_info_list_handler.py#L86-L99
5,083
bukun/TorCMS
torcms/handlers/user_info_list_handler.py
UserListHandler.find
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', userinfo=self.userinfo, kwd=kwd, recs=MPost.get_by_keyword(keyword))
python
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', userinfo=self.userinfo, kwd=kwd, recs=MPost.get_by_keyword(keyword))
[ "def", "find", "(", "self", ")", ":", "keyword", "=", "self", ".", "get_argument", "(", "'keyword'", ")", ".", "strip", "(", ")", "kwd", "=", "{", "'pager'", ":", "''", ",", "'title'", ":", "'Searching Result'", ",", "}", "self", ".", "render", "(", ...
find the infors.
[ "find", "the", "infors", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/user_info_list_handler.py#L101-L114
5,084
bukun/TorCMS
torcms/handlers/relation_handler.py
RelHandler.add_relation
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) MRelation.add_relation(url_arr[1], last_post_id, 1) if url_arr[0] == 'post': if last_app_id: MRelation.add_relation(last_app_id, url_arr[1], 2) MRelation.add_relation(url_arr[1], last_app_id, 1)
python
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) MRelation.add_relation(url_arr[1], last_post_id, 1) if url_arr[0] == 'post': if last_app_id: MRelation.add_relation(last_app_id, url_arr[1], 2) MRelation.add_relation(url_arr[1], last_app_id, 1)
[ "def", "add_relation", "(", "self", ",", "url_arr", ")", ":", "if", "MPost", ".", "get_by_uid", "(", "url_arr", "[", "1", "]", ")", ":", "pass", "else", ":", "return", "False", "last_post_id", "=", "self", ".", "get_secure_cookie", "(", "'last_post_uid'", ...
Add relationship.
[ "Add", "relationship", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/relation_handler.py#L25-L50
5,085
bukun/TorCMS
torcms/handlers/reply_handler.py
ReplyHandler.get_by_id
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, username=reply.user_name, date=reply.date, vote=reply.vote, uid=reply.uid, userinfo=self.userinfo, kwd={})
python
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, username=reply.user_name, date=reply.date, vote=reply.vote, uid=reply.uid, userinfo=self.userinfo, kwd={})
[ "def", "get_by_id", "(", "self", ",", "reply_id", ")", ":", "reply", "=", "MReply", ".", "get_by_uid", "(", "reply_id", ")", "logger", ".", "info", "(", "'get_reply: {0}'", ".", "format", "(", "reply_id", ")", ")", "self", ".", "render", "(", "'misc/repl...
Get the reply by id.
[ "Get", "the", "reply", "by", "id", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/reply_handler.py#L66-L80
5,086
bukun/TorCMS
torcms/handlers/reply_handler.py
ReplyHandler.add
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: out_dic = {'pinglun': post_data['cnt_reply'], 'uid': replyid} logger.info('add reply result dic: {0}'.format(out_dic)) return json.dump(out_dic, self)
python
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: out_dic = {'pinglun': post_data['cnt_reply'], 'uid': replyid} logger.info('add reply result dic: {0}'.format(out_dic)) return json.dump(out_dic, self)
[ "def", "add", "(", "self", ",", "post_id", ")", ":", "post_data", "=", "self", ".", "get_post_data", "(", ")", "post_data", "[", "'user_name'", "]", "=", "self", ".", "userinfo", ".", "user_name", "post_data", "[", "'user_id'", "]", "=", "self", ".", "...
Adding reply to a post.
[ "Adding", "reply", "to", "a", "post", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/reply_handler.py#L82-L96
5,087
bukun/TorCMS
torcms/handlers/reply_handler.py
ReplyHandler.delete
def delete(self, del_id): ''' Delete the id ''' if MReply2User.delete(del_id): output = {'del_zan': 1} else: output = {'del_zan': 0} return json.dump(output, self)
python
def delete(self, del_id): ''' Delete the id ''' if MReply2User.delete(del_id): output = {'del_zan': 1} else: output = {'del_zan': 0} return json.dump(output, self)
[ "def", "delete", "(", "self", ",", "del_id", ")", ":", "if", "MReply2User", ".", "delete", "(", "del_id", ")", ":", "output", "=", "{", "'del_zan'", ":", "1", "}", "else", ":", "output", "=", "{", "'del_zan'", ":", "0", "}", "return", "json", ".", ...
Delete the id
[ "Delete", "the", "id" ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/reply_handler.py#L118-L126
5,088
bukun/TorCMS
torcms/handlers/wiki_history_manager.py
WikiHistoryHandler.update
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) if cur_info.kind == '1': self.redirect('/wiki/{0}'.format(cur_info.title)) elif cur_info.kind == '2': self.redirect('/page/{0}.html'.format(cur_info.uid))
python
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) if cur_info.kind == '1': self.redirect('/wiki/{0}'.format(cur_info.title)) elif cur_info.kind == '2': self.redirect('/page/{0}.html'.format(cur_info.uid))
[ "def", "update", "(", "self", ",", "uid", ")", ":", "if", "self", ".", "userinfo", ".", "role", "[", "0", "]", ">", "'0'", ":", "pass", "else", ":", "return", "False", "post_data", "=", "self", ".", "get_post_data", "(", ")", "post_data", "[", "'us...
Update the post via ID.
[ "Update", "the", "post", "via", "ID", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/wiki_history_manager.py#L26-L43
5,089
bukun/TorCMS
torcms/handlers/wiki_history_manager.py
WikiHistoryHandler.to_edit
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', userinfo=self.userinfo, postinfo=MWiki.get_by_uid(postid), kwd=kwd)
python
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', userinfo=self.userinfo, postinfo=MWiki.get_by_uid(postid), kwd=kwd)
[ "def", "to_edit", "(", "self", ",", "postid", ")", ":", "if", "self", ".", "userinfo", ".", "role", "[", "0", "]", ">", "'0'", ":", "pass", "else", ":", "return", "False", "kwd", "=", "{", "}", "self", ".", "render", "(", "'man_info/wiki_man_edit.htm...
Try to edit the Post.
[ "Try", "to", "edit", "the", "Post", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/wiki_history_manager.py#L46-L58
5,090
bukun/TorCMS
torcms/handlers/wiki_history_manager.py
WikiHistoryHandler.delete
def delete(self, uid): ''' Delete the history of certain ID. ''' if self.check_post_role()['DELETE']: pass else: return False histinfo = MWikiHist.get_by_uid(uid) if histinfo: pass else: return False postinfo = MWiki.get_by_uid(histinfo.wiki_id) MWikiHist.delete(uid) self.redirect('/wiki_man/view/{0}'.format(postinfo.uid))
python
def delete(self, uid): ''' Delete the history of certain ID. ''' if self.check_post_role()['DELETE']: pass else: return False histinfo = MWikiHist.get_by_uid(uid) if histinfo: pass else: return False postinfo = MWiki.get_by_uid(histinfo.wiki_id) MWikiHist.delete(uid) self.redirect('/wiki_man/view/{0}'.format(postinfo.uid))
[ "def", "delete", "(", "self", ",", "uid", ")", ":", "if", "self", ".", "check_post_role", "(", ")", "[", "'DELETE'", "]", ":", "pass", "else", ":", "return", "False", "histinfo", "=", "MWikiHist", ".", "get_by_uid", "(", "uid", ")", "if", "histinfo", ...
Delete the history of certain ID.
[ "Delete", "the", "history", "of", "certain", "ID", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/wiki_history_manager.py#L61-L78
5,091
bukun/TorCMS
torcms/handlers/wiki_history_manager.py
WikiHistoryHandler.restore
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( histinfo.uid, {'cnt_md': cur_cnt, 'user_name': postinfo.user_name} ) if postinfo.kind == '1': self.redirect('/wiki/{0}'.format(postinfo.title)) elif postinfo.kind == '2': self.redirect('/page/{0}.html'.format(postinfo.uid))
python
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( histinfo.uid, {'cnt_md': cur_cnt, 'user_name': postinfo.user_name} ) if postinfo.kind == '1': self.redirect('/wiki/{0}'.format(postinfo.title)) elif postinfo.kind == '2': self.redirect('/page/{0}.html'.format(postinfo.uid))
[ "def", "restore", "(", "self", ",", "hist_uid", ")", ":", "if", "self", ".", "check_post_role", "(", ")", "[", "'ADMIN'", "]", ":", "pass", "else", ":", "return", "False", "histinfo", "=", "MWikiHist", ".", "get_by_uid", "(", "hist_uid", ")", "if", "hi...
Restore by ID
[ "Restore", "by", "ID" ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/wiki_history_manager.py#L124-L155
5,092
bukun/TorCMS
torcms/model/log_model.py
MLog.add
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'], time_create=data_dic['timein'], time_out=data_dic['timeOut'], time=data_dic['timeon'] ) return uid
python
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'], time_create=data_dic['timein'], time_out=data_dic['timeOut'], time=data_dic['timeon'] ) return uid
[ "def", "add", "(", "data_dic", ")", ":", "uid", "=", "data_dic", "[", "'uid'", "]", "TabLog", ".", "create", "(", "uid", "=", "uid", ",", "current_url", "=", "data_dic", "[", "'url'", "]", ",", "refer_url", "=", "data_dic", "[", "'refer'", "]", ",", ...
Insert new record.
[ "Insert", "new", "record", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/log_model.py#L20-L35
5,093
bukun/TorCMS
torcms/model/collect_model.py
MCollect.get_by_signature
def get_by_signature(user_id, app_id): ''' Get the collection. ''' try: return TabCollect.get( (TabCollect.user_id == user_id) & (TabCollect.post_id == app_id) ) except: return None
python
def get_by_signature(user_id, app_id): ''' Get the collection. ''' try: return TabCollect.get( (TabCollect.user_id == user_id) & (TabCollect.post_id == app_id) ) except: return None
[ "def", "get_by_signature", "(", "user_id", ",", "app_id", ")", ":", "try", ":", "return", "TabCollect", ".", "get", "(", "(", "TabCollect", ".", "user_id", "==", "user_id", ")", "&", "(", "TabCollect", ".", "post_id", "==", "app_id", ")", ")", "except", ...
Get the collection.
[ "Get", "the", "collection", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/collect_model.py#L42-L52
5,094
bukun/TorCMS
torcms/model/collect_model.py
MCollect.count_of_user
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( TabCollect.user_id == user_id ).join( TabPost, on=(TabCollect.post_id == TabPost.uid) ).count()
python
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( TabCollect.user_id == user_id ).join( TabPost, on=(TabCollect.post_id == TabPost.uid) ).count()
[ "def", "count_of_user", "(", "user_id", ")", ":", "return", "TabCollect", ".", "select", "(", "TabCollect", ",", "TabPost", ".", "uid", ".", "alias", "(", "'post_uid'", ")", ",", "TabPost", ".", "title", ".", "alias", "(", "'post_title'", ")", ",", "TabP...
Get the cound of views.
[ "Get", "the", "cound", "of", "views", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/collect_model.py#L55-L67
5,095
bukun/TorCMS
torcms/model/collect_model.py
MCollect.add_or_update
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( timestamp=int(time.time()) ).where(TabCollect.uid == rec.uid) entry.execute() else: TabCollect.create( uid=tools.get_uuid(), user_id=user_id, post_id=app_id, timestamp=int(time.time()), )
python
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( timestamp=int(time.time()) ).where(TabCollect.uid == rec.uid) entry.execute() else: TabCollect.create( uid=tools.get_uuid(), user_id=user_id, post_id=app_id, timestamp=int(time.time()), )
[ "def", "add_or_update", "(", "user_id", ",", "app_id", ")", ":", "rec", "=", "MCollect", ".", "get_by_signature", "(", "user_id", ",", "app_id", ")", "if", "rec", ":", "entry", "=", "TabCollect", ".", "update", "(", "timestamp", "=", "int", "(", "time", ...
Add the collection or update.
[ "Add", "the", "collection", "or", "update", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/collect_model.py#L87-L105
5,096
bukun/TorCMS
torcms/core/libs/deprecation.py
deprecated
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 make whatever goes to it # is at least *something*. if current_version: current_version = version.StrictVersion(current_version) if removed_in and current_version >= version.StrictVersion(removed_in): is_unsupported = True elif deprecated_in and current_version >= version.StrictVersion(deprecated_in): is_deprecated = True else: # If we can't actually calculate that we're in a period of # deprecation...well, they used the decorator, so it's deprecated. # This will cover the case of someone just using # @deprecated("1.0") without the other advantages. is_deprecated = True should_warn = any([is_deprecated, is_unsupported]) def _function_wrapper(function): if should_warn: # Everything *should* have a docstring, but just in case... existing_docstring = function.__doc__ or "" # The various parts of this decorator being optional makes for # a number of ways the deprecation notice could go. The following # makes for a nicely constructed sentence with or without any # of the parts. parts = { "deprecated_in": " in %s" % deprecated_in if deprecated_in else "", "removed_in": ", to be removed in %s" % removed_in if removed_in else "", "period": "." if deprecated_in or removed_in or details else "", "details": " %s" % details if details else ""} deprecation_note = ("*Deprecated{deprecated_in}{removed_in}" "{period}{details}*".format(**parts)) function.__doc__ = "\n\n".join([existing_docstring, deprecation_note]) @functools.wraps(function) def _inner(*args, **kwargs): if should_warn: if is_unsupported: cls = UnsupportedWarning else: cls = DeprecatedWarning the_warning = cls(function.__name__, deprecated_in, removed_in, details) warnings.warn(the_warning) return function(*args, **kwargs) return _inner return _function_wrapper
python
def deprecated(deprecated_in=None, removed_in=None, current_version=None, 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 make whatever goes to it # is at least *something*. if current_version: current_version = version.StrictVersion(current_version) if removed_in and current_version >= version.StrictVersion(removed_in): is_unsupported = True elif deprecated_in and current_version >= version.StrictVersion(deprecated_in): is_deprecated = True else: # If we can't actually calculate that we're in a period of # deprecation...well, they used the decorator, so it's deprecated. # This will cover the case of someone just using # @deprecated("1.0") without the other advantages. is_deprecated = True should_warn = any([is_deprecated, is_unsupported]) def _function_wrapper(function): if should_warn: # Everything *should* have a docstring, but just in case... existing_docstring = function.__doc__ or "" # The various parts of this decorator being optional makes for # a number of ways the deprecation notice could go. The following # makes for a nicely constructed sentence with or without any # of the parts. parts = { "deprecated_in": " in %s" % deprecated_in if deprecated_in else "", "removed_in": ", to be removed in %s" % removed_in if removed_in else "", "period": "." if deprecated_in or removed_in or details else "", "details": " %s" % details if details else ""} deprecation_note = ("*Deprecated{deprecated_in}{removed_in}" "{period}{details}*".format(**parts)) function.__doc__ = "\n\n".join([existing_docstring, deprecation_note]) @functools.wraps(function) def _inner(*args, **kwargs): if should_warn: if is_unsupported: cls = UnsupportedWarning else: cls = DeprecatedWarning the_warning = cls(function.__name__, deprecated_in, removed_in, details) warnings.warn(the_warning) return function(*args, **kwargs) return _inner return _function_wrapper
[ "def", "deprecated", "(", "deprecated_in", "=", "None", ",", "removed_in", "=", "None", ",", "current_version", "=", "None", ",", "details", "=", "\"\"", ")", ":", "# You can't just jump to removal. It's weird, unfair, and also makes", "# building up the docstring weird.", ...
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.
[ "Decorate", "a", "function", "to", "signify", "its", "deprecation" ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/core/libs/deprecation.py#L78-L190
5,097
bukun/TorCMS
torcms/core/libs/deprecation.py
fail_if_not_removed
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, **kwargs) for warning in caught_warnings: if warning.category == UnsupportedWarning: raise AssertionError( ("%s uses a function that should be removed: %s" % (method, str(warning.message)))) return rval return _inner
python
def fail_if_not_removed(method): def _inner(*args, **kwargs): with warnings.catch_warnings(record=True) as caught_warnings: warnings.simplefilter("always") rval = method(*args, **kwargs) for warning in caught_warnings: if warning.category == UnsupportedWarning: raise AssertionError( ("%s uses a function that should be removed: %s" % (method, str(warning.message)))) return rval return _inner
[ "def", "fail_if_not_removed", "(", "method", ")", ":", "def", "_inner", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "with", "warnings", ".", "catch_warnings", "(", "record", "=", "True", ")", "as", "caught_warnings", ":", "warnings", ".", "simpl...
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.
[ "Decorate", "a", "test", "method", "to", "track", "removal", "of", "deprecated", "code" ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/core/libs/deprecation.py#L193-L217
5,098
bukun/TorCMS
torcms/core/base_handler.py
BaseHandler.get_post_data
def get_post_data(self): ''' Get all the arguments from post request. Only get the first argument by default. ''' post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key)[0] return post_data
python
def get_post_data(self): ''' Get all the arguments from post request. Only get the first argument by default. ''' post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key)[0] return post_data
[ "def", "get_post_data", "(", "self", ")", ":", "post_data", "=", "{", "}", "for", "key", "in", "self", ".", "request", ".", "arguments", ":", "post_data", "[", "key", "]", "=", "self", ".", "get_arguments", "(", "key", ")", "[", "0", "]", "return", ...
Get all the arguments from post request. Only get the first argument by default.
[ "Get", "all", "the", "arguments", "from", "post", "request", ".", "Only", "get", "the", "first", "argument", "by", "default", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/core/base_handler.py#L36-L43
5,099
bukun/TorCMS
torcms/core/base_handler.py
BaseHandler.check_post_role
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': priv_dic['ADD'] = True if self.userinfo.role[1] >= '1': priv_dic['EDIT'] = True if self.userinfo.role[1] >= '3': priv_dic['DELETE'] = True if self.userinfo.role[1] >= '2': priv_dic['ADMIN'] = True return priv_dic
python
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': priv_dic['ADD'] = True if self.userinfo.role[1] >= '1': priv_dic['EDIT'] = True if self.userinfo.role[1] >= '3': priv_dic['DELETE'] = True if self.userinfo.role[1] >= '2': priv_dic['ADMIN'] = True return priv_dic
[ "def", "check_post_role", "(", "self", ")", ":", "priv_dic", "=", "{", "'ADD'", ":", "False", ",", "'EDIT'", ":", "False", ",", "'DELETE'", ":", "False", ",", "'ADMIN'", ":", "False", "}", "if", "self", ".", "userinfo", ":", "if", "self", ".", "useri...
check the user role for docs.
[ "check", "the", "user", "role", "for", "docs", "." ]
6567c7fe2604a1d646d4570c017840958630ed2b
https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/core/base_handler.py#L55-L69