code
string | signature
string | docstring
string | loss_without_docstring
float64 | loss_with_docstring
float64 | factor
float64 |
---|---|---|---|---|---|
'''
根据分类uid的4位编码来找模板。如果4位的存在,则使用4位的;不然找其父类;再不然则使用通用模板
只有View需要,edit, list使用通用模板
:return String.
'''
the_view_file_4 = './templates/tmpl_{0}/tpl_view_{1}.html'.format(
KIND_DICS['kind_' + tag_key.split('_')[-1]],
tag_key.split('_')[1]
)
the_view_file_2 = './templates/tmpl_{0}/tpl_view_{1}.html'.format(
KIND_DICS['kind_' + tag_key.split('_')[-1]],
tag_key.split('_')[1][:2]
)
if os.path.exists(the_view_file_4):
the_view_sig_str = '_{0}'.format(tag_key.split('_')[1])
elif os.path.exists(the_view_file_2):
the_view_sig_str = '_{0}'.format(tag_key.split('_')[1][:2])
else:
the_view_sig_str = ''
return the_view_sig_str
|
def __get_view_tmpl(tag_key)
|
根据分类uid的4位编码来找模板。如果4位的存在,则使用4位的;不然找其父类;再不然则使用通用模板
只有View需要,edit, list使用通用模板
:return String.
| 4.462737 | 2.111248 | 2.113791 |
'''
Convert to html.
:return String.
'''
bianliang = HTML_DICS[bl_str]
# bianliang = eval('html_vars.' + bl_str)
html_out = '''<li class="list-group-item">
<div class="row"><div class="col-sm-3">{0}</div><div class="col-sm-9">
<span class="label label-default" name='{1}' onclick='change(this);' value=''>{{{{_('All')}}}}</span>
'''.format(bianliang['zh'], '_'.join(bl_str.split('_')[1:]))
tmp_dic = bianliang['dic']
for key in tmp_dic.keys():
tmp_str = '''
<span class="label label-default" name='{0}' onclick='change(this);' value='{1}'>
{2}</span>'''.format('_'.join(bl_str.split('_')[1:]), key, tmp_dic[key])
html_out += tmp_str
html_out += '''</div></div></li>'''
return html_out
|
def __gen_select_filter(bl_str)
|
Convert to html.
:return String.
| 3.662241 | 3.255359 | 1.124989 |
'''
Generate the templates for adding, editing, viewing.
:return: None
'''
_ = args
for tag_key, tag_list in SWITCH_DICS.items():
if tag_key.startswith('dic_') and (not tag_key.endswith('00')):
__write_add_tmpl(tag_key, tag_list)
__write_edit_tmpl(tag_key, tag_list)
__write_view_tmpl(tag_key, tag_list)
__write_filter_tmpl(TPL_LIST)
__write_list_tmpl(TPL_LISTINFO)
|
def generate_html_files(*args)
|
Generate the templates for adding, editing, viewing.
:return: None
| 5.411883 | 4.224391 | 1.281104 |
'''
Generate the HTML file for editing.
:param tag_key: key of the tags.
:param tag_list: list of the tags.
:return: None
'''
edit_file = os.path.join(OUT_DIR, 'edit', 'edit_' + tag_key.split('_')[1] + '.html')
edit_widget_arr = []
for sig in tag_list:
html_sig = '_'.join(['html', sig])
# var_html = eval('html_vars.' + html_sig)
var_html = HTML_DICS[html_sig]
if var_html['type'] in INPUT_ARR:
tmpl = func_gen_html.gen_input_edit(var_html)
elif var_html['type'] == 'select':
tmpl = func_gen_html.gen_select_edit(var_html)
elif var_html['type'] == 'radio':
tmpl = func_gen_html.gen_radio_edit(var_html)
elif var_html['type'] == 'checkbox':
tmpl = func_gen_html.gen_checkbox_edit(var_html)
elif var_html['type'] == 'file':
tmpl = func_gen_html.gen_file_edit(var_html)
else:
tmpl = ''
edit_widget_arr.append(tmpl)
with open(edit_file, 'w') as fileout2:
outstr = minify(
TPL_EDIT.replace(
'xxxxxx',
''.join(edit_widget_arr)
).replace(
'yyyyyy',
tag_key.split('_')[1][:2]
).replace(
'kkkk',
KIND_DICS['kind_' + tag_key.split('_')[-1]]
)
)
fileout2.write(outstr)
|
def __write_edit_tmpl(tag_key, tag_list)
|
Generate the HTML file for editing.
:param tag_key: key of the tags.
:param tag_list: list of the tags.
:return: None
| 2.786204 | 2.624584 | 1.061579 |
'''
Generate the HTML file for viewing.
:param tag_key: key of the tags.
:param tag_list: list of the tags.
:return: None
'''
view_file = os.path.join(OUT_DIR, 'view', 'view_' + tag_key.split('_')[1] + '.html')
view_widget_arr = []
for sig in tag_list:
html_sig = '_'.join(['html', sig])
# var_html = eval('html_vars.' + html_sig)
var_html = HTML_DICS[html_sig]
if var_html['type'] in INPUT_ARR:
tmpl = func_gen_html.gen_input_view(var_html)
elif var_html['type'] == 'select':
tmpl = func_gen_html.gen_select_view(var_html)
elif var_html['type'] == 'radio':
tmpl = func_gen_html.gen_radio_view(var_html)
elif var_html['type'] == 'checkbox':
tmpl = func_gen_html.gen_checkbox_view(var_html)
elif var_html['type'] == 'file':
tmpl = func_gen_html.gen_file_view(var_html)
else:
tmpl = ''
# The admin information should be hidden for user.
if sig.startswith('_'):
tmpl = '''{% if userinfo and userinfo.role[1] > '0' %}''' + tmpl + '''{% end %}'''
view_widget_arr.append(tmpl)
the_view_sig_str = __get_view_tmpl(tag_key)
with open(view_file, 'w') as fileout:
outstr = minify(
TPL_VIEW.replace(
'xxxxxx', ''.join(view_widget_arr)
).replace(
'yyyyyy',
tag_key.split('_')[1][:2]
).replace(
'ssss',
the_view_sig_str
).replace(
'kkkk',
KIND_DICS['kind_' + tag_key.split('_')[-1]]
)
)
fileout.write(outstr)
|
def __write_view_tmpl(tag_key, tag_list)
|
Generate the HTML file for viewing.
:param tag_key: key of the tags.
:param tag_list: list of the tags.
:return: None
| 3.274936 | 3.092342 | 1.059047 |
'''
Generate the HTML file for adding.
:param tag_key: key of the tags.
:param tag_list: list of the tags.
:return: None
'''
add_file = os.path.join(OUT_DIR, 'add', 'add_' + tag_key.split('_')[1] + '.html')
add_widget_arr = []
# var_dic = eval('dic_vars.' + bianliang)
for sig in tag_list:
html_sig = '_'.join(['html', sig])
# var_html = eval('html_vars.' + html_sig)
var_html = HTML_DICS[html_sig]
if var_html['type'] in INPUT_ARR:
tmpl = func_gen_html.gen_input_add(var_html)
elif var_html['type'] == 'select':
tmpl = func_gen_html.gen_select_add(var_html)
elif var_html['type'] == 'radio':
tmpl = func_gen_html.gen_radio_add(var_html)
elif var_html['type'] == 'checkbox':
tmpl = func_gen_html.gen_checkbox_add(var_html)
elif var_html['type'] == 'file':
tmpl = func_gen_html.gen_file_add(var_html)
else:
tmpl = ''
add_widget_arr.append(tmpl)
with open(add_file, 'w') as fileout:
outstr = minify(
TPL_ADD.replace(
'xxxxxx',
''.join(add_widget_arr)
).replace(
'yyyyyy',
tag_key.split('_')[1][:2]
).replace(
'kkkk',
KIND_DICS['kind_' + tag_key.split('_')[-1]]
)
)
fileout.write(outstr)
|
def __write_add_tmpl(tag_key, tag_list)
|
Generate the HTML file for adding.
:param tag_key: key of the tags.
:param tag_list: list of the tags.
:return: None
| 2.966784 | 2.771597 | 1.070424 |
'''
doing for directory.
'''
out_dir = os.path.join(os.getcwd(), CRUD_PATH, 'list')
if os.path.exists(out_dir):
pass
else:
os.mkdir(out_dir)
# for var_name in VAR_NAMES:
for var_name, bl_val in SWITCH_DICS.items():
if var_name.startswith('dic_'):
# 此处简化一下,不考虑子类的问题。
subdir = ''
outfile = os.path.join(out_dir, 'list' + '_' + var_name.split('_')[1] + '.html')
html_view_str_arr = []
# tview_var = eval('dic_vars.' + var_name)
for the_val in bl_val:
# sig = eval('html_vars.html_' + x)
sig = HTML_DICS['html_' + the_val]
if sig['type'] == 'select':
html_view_str_arr.append(__gen_select_filter('html_' + the_val))
with open(outfile, 'w') as outfileo:
outstr = minify(
html_tpl.replace(
'xxxxxx',
''.join(html_view_str_arr)
).replace(
'yyyyyy',
var_name.split('_')[1][:2]
).replace(
'ssssss',
subdir
).replace(
'kkkk',
KIND_DICS['kind_' + var_name.split('_')[-1]]
)
)
outfileo.write(outstr)
|
def __write_filter_tmpl(html_tpl)
|
doing for directory.
| 4.946254 | 4.788157 | 1.033018 |
'''
doing for directory.
'''
out_dir = os.path.join(os.getcwd(), CRUD_PATH, 'infolist')
if os.path.exists(out_dir):
pass
else:
os.mkdir(out_dir)
# for var_name in VAR_NAMES:
for var_name, bl_val in SWITCH_DICS.items():
if var_name.startswith('dic_'):
outfile = os.path.join(out_dir, 'infolist' + '_' + var_name.split('_')[1] + '.html')
html_view_str_arr = []
# tview_var = eval('dic_vars.' + var_name)
subdir = ''
for the_val2 in bl_val:
# sig = eval('html_vars.html_' + x)
sig = HTML_DICS['html_' + the_val2]
if sig['type'] == 'select':
html_view_str_arr.append(func_gen_html.gen_select_list(sig))
elif sig['type'] == 'radio':
html_view_str_arr.append(func_gen_html.gen_radio_list(sig))
elif sig['type'] == 'checkbox':
html_view_str_arr.append(func_gen_html.gen_checkbox_list(sig))
with open(outfile, 'w') as outfileo:
outstr = minify(
html_tpl.replace(
'xxxxxx',
''.join(html_view_str_arr)
).replace(
'yyyyyy',
var_name.split('_')[1][:2]
).replace(
'ssssss',
subdir
).replace(
'kkkk',
KIND_DICS['kind_' + var_name.split('_')[-1]]
)
)
outfileo.write(outstr)
|
def __write_list_tmpl(html_tpl)
|
doing for directory.
| 3.84023 | 3.73271 | 1.028805 |
'''
List the apps.
'''
kwd = {
'pager': '',
'title': ''
}
self.render('user/info_list/list_app.html', kwd=kwd,
userinfo=self.userinfo)
|
def list_app(self)
|
List the apps.
| 8.223685 | 6.504652 | 1.264278 |
'''
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)
|
User most used.
| 6.986139 | 5.498481 | 1.270558 |
'''
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)
|
User used recently.
| 7.136607 | 5.371838 | 1.328522 |
'''
Todo: the name should be changed.
list the infors.
'''
kwd = {'pager': ''}
self.render('user/info_list/most.html',
topmenu='',
userinfo=self.userinfo,
kwd=kwd)
|
def to_find(self)
|
Todo: the name should be changed.
list the infors.
| 18.882904 | 7.137505 | 2.645589 |
'''
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)
|
List the recent.
| 9.368556 | 7.889782 | 1.187429 |
'''
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)
|
find the infors.
| 10.688527 | 7.883751 | 1.355767 |
'''
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)
|
Add relationship.
| 2.166435 | 2.098462 | 1.032392 |
'''
List the replies.
'''
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(MReply.total_number() / CMS_CFG['list_num'])
kwd = {'pager': '',
'current_page': current_page_number,
'title': '单页列表'}
self.render('admin/reply_ajax/reply_list.html',
kwd=kwd,
view_all=MReply.query_all(),
infos=MReply.query_pager(current_page_num=current_page_number),
userinfo=self.userinfo
)
|
def list(self, cur_p='')
|
List the replies.
| 4.527987 | 4.120471 | 1.0989 |
'''
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)
|
Get the reply by id.
| 5.050769 | 4.820794 | 1.047705 |
'''
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)
|
Adding reply to a post.
| 4.796384 | 4.308817 | 1.113156 |
'''
先在外部表中更新,然后更新内部表字段的值。
有冗余,但是查看的时候避免了联合查询
'''
logger.info('zan: {0}'.format(id_reply))
MReply2User.create_reply(self.userinfo.uid, id_reply)
cur_count = MReply2User.get_voter_count(id_reply)
if cur_count:
MReply.update_vote(id_reply, cur_count)
output = {'text_zan': cur_count}
else:
output = {'text_zan': 0}
logger.info('zan dic: {0}'.format(cur_count))
return json.dump(output, self)
|
def zan(self, id_reply)
|
先在外部表中更新,然后更新内部表字段的值。
有冗余,但是查看的时候避免了联合查询
| 6.761945 | 3.661409 | 1.846815 |
'''
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)
|
Delete the id
| 8.421901 | 7.034496 | 1.197229 |
'''
查询全部章节
'''
cat_rec = MCategory.get_by_slug(slug)
if cat_rec:
cat_id = cat_rec.uid
else:
return None
if cat_id.endswith('00'):
cat_con = TabPost2Tag.par_id == cat_id
else:
cat_con = TabPost2Tag.tag_id == cat_id
recs = TabPost.select().join(
TabPost2Tag,
on=(TabPost.uid == TabPost2Tag.post_id)
).where(
cat_con
).order_by(
TabPost.time_update.desc()
)
return recs
|
def query_by_slug(slug)
|
查询全部章节
| 3.85035 | 3.51145 | 1.096513 |
'''
查询大类记录
'''
recs = TabTag.select().where(TabTag.uid.endswith('00')).order_by(TabTag.uid)
return recs
|
def query_all()
|
查询大类记录
| 14.870895 | 9.575694 | 1.552984 |
'''
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)
|
Update the post via ID.
| 4.745617 | 4.192429 | 1.131949 |
'''
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)
|
Try to edit the Post.
| 7.876711 | 6.858578 | 1.148447 |
'''
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)
|
Delete the history of certain ID.
| 6.597376 | 5.273113 | 1.251135 |
'''
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)
|
Restore by ID
| 3.279448 | 3.13629 | 1.045645 |
'''
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)
|
Insert new record.
| 5.468651 | 5.058524 | 1.081076 |
'''
Query pager
'''
return TabLog.select().where(TabLog.user_id == userid).order_by(
TabLog.time_create.desc()
).paginate(
current_page_num, CMS_CFG['list_num']
)
|
def query_pager_by_user(userid, current_page_num=1)
|
Query pager
| 5.876599 | 5.579946 | 1.053164 |
'''
查询所有登录用户的访问记录
ToDo: ``None`` ?
'''
return TabLog.select().where(TabLog.user_id != 'None').distinct(TabLog.user_id).order_by(
TabLog.user_id
)
|
def query_all_user()
|
查询所有登录用户的访问记录
ToDo: ``None`` ?
| 10.522189 | 4.297269 | 2.448576 |
'''
查询所有未登录用户的访问记录
ToDo: ``None`` ?
'''
return TabLog.select().where(TabLog.user_id == 'None').order_by(TabLog.time_out.desc()).paginate(
current_page_num, CMS_CFG['list_num']
)
|
def query_all(current_page_num=1)
|
查询所有未登录用户的访问记录
ToDo: ``None`` ?
| 10.442671 | 4.663833 | 2.239075 |
'''
查询所有页面(current_url),分页
'''
return TabLog.select().distinct(TabLog.current_url).order_by(TabLog.current_url).paginate(
current_page_num, CMS_CFG['list_num']
)
|
def query_all_pageview(current_page_num=1)
|
查询所有页面(current_url),分页
| 9.395206 | 5.571497 | 1.686298 |
'''
长询制订页面(current_url)的访问量
'''
res = TabLog.select().where(TabLog.current_url == current_url)
return res.count()
|
def count_of_current_url(current_url)
|
长询制订页面(current_url)的访问量
| 16.819098 | 4.164063 | 4.039107 |
'''
Running the script.
'''
tstr = ''
idx = 1
for kind in config.router_post.keys():
posts = MPost.query_all(kind=kind, limit=20000)
for post in posts:
the_url0 = '{site_url}/{kind_url}/{uid}'.format(
site_url=config.SITE_CFG['site_url'],
kind_url=config.router_post[post.kind],
uid=post.uid)
the_url = '{site_url}/{kind_url}/_edit/{uid}'.format(
site_url=config.SITE_CFG['site_url'],
kind_url=config.router_post[post.kind],
uid=post.uid)
req = requests.get(the_url0)
if req.status_code == 200:
pass
else:
print(the_url0)
tstr = tstr + DT_STR.format(idx=str(idx).zfill(2), url0=the_url0, code=req.status_code, edit_link=the_url)
idx = idx + 1
time_local = time.localtime(timestamp())
with open('xx200_{d}.html'.format(d=str(time.strftime("%Y_%m_%d", time_local))), 'w') as fileo:
fileo.write(HTML_TMPL.format(cnt=tstr))
print('Checking 200 finished.')
|
def run_check200(_)
|
Running the script.
| 3.681335 | 3.623546 | 1.015948 |
'''
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)
|
Get the collection.
| 5.442373 | 4.582892 | 1.187541 |
'''
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)
|
Get the cound of views.
| 3.832597 | 3.047417 | 1.257654 |
'''
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)
|
Add the collection or update.
| 4.871375 | 4.30645 | 1.131181 |
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)
|
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.
| 3.677447 | 2.903582 | 1.266521 |
'''
向表中插入数据
'''
XLSX_FILE = './database/esheet/20180811.xlsx'
if os.path.exists(XLSX_FILE):
pass
else:
return
RAW_LIST = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
FILTER_COLUMNS = RAW_LIST + ["A" + x for x in RAW_LIST] + \
["B" + x for x in RAW_LIST] + \
["C" + x for x in RAW_LIST] + \
["D" + x for x in RAW_LIST]
tvalue = []
file_d = open_workbook(XLSX_FILE)
# 获得第一个页签对象
x = 0
for sheet_ranges in load_workbook(filename=XLSX_FILE):
select_sheet = file_d.sheets()[x]
# 获取总共的行数
rows_num = select_sheet.nrows + 1
for row_num in range(6, rows_num):
tvalue = []
for xr in FILTER_COLUMNS:
row1_val = sheet_ranges[xr + '1'].value
row4_val = sheet_ranges[xr + '{0}'.format(row_num)].value
if row1_val:
if row4_val == None:
row4_val = ''
tvalue.append(row4_val)
insert_tab(tvalue)
x = x + 1
print("成功插入 " + str(rows_num - 6) + " 行数据")
|
def gen_xlsx_table_info()
|
向表中插入数据
| 3.254602 | 3.135541 | 1.037971 |
'''
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)
|
Get all the arguments from post request. Only get the first argument by default.
| 4.778401 | 2.16785 | 2.204213 |
'''
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)
|
check the user role for docs.
| 2.903961 | 2.418428 | 1.200764 |
'''
Override the function, to control the UI language.
'''
locale_id = self.get_cookie('ulocale')
if locale_id:
return tornado.locale.get(locale_id)
else:
return tornado.locale.get('en_US')
|
def get_user_locale(self)
|
Override the function, to control the UI language.
| 5.548738 | 3.049746 | 1.81941 |
'''
Override the function, to control the UI language.
'''
locale_id = self.get_cookie('blocale')
if locale_id:
return tornado.locale.get(locale_id)
else:
return tornado.locale.get('en_US')
|
def get_browser_locale(self)
|
Override the function, to control the UI language.
| 5.993813 | 3.17033 | 1.890596 |
'''
return the warpped template path.
:param tmpl:
'''
return 'admin/' + tmpl.format(sig='p') if self.is_p else tmpl.format(sig='')
|
def wrap_tmpl(self, tmpl)
|
return the warpped template path.
:param tmpl:
| 19.092985 | 10.167338 | 1.877874 |
'''
The the entity id by the path.
'''
logger.info('Get Entiry, Path: {0}'.format(path))
entity_list = TabEntity.select().where(TabEntity.path == path)
out_val = None
if entity_list.count() == 1:
out_val = entity_list.get()
elif entity_list.count() > 1:
for rec in entity_list:
MEntity.delete(rec.uid)
out_val = None
else:
pass
return out_val
|
def get_id_by_impath(path)
|
The the entity id by the path.
| 5.110607 | 4.246724 | 1.203423 |
'''
create entity record in the database.
'''
if path:
pass
else:
return False
if uid:
pass
else:
uid = get_uuid()
try:
TabEntity.create(
uid=uid,
path=path,
desc=desc,
time_create=time.time(),
kind=kind
)
return True
except:
return False
|
def create_entity(uid='', path='', desc='', kind='1')
|
create entity record in the database.
| 3.928514 | 3.417983 | 1.149366 |
'''
Generate the templates for adding, editing, viewing.
:return: None
'''
_ = args
for tag_key, tag_list in SWITCH_DICS.items():
if tag_key.startswith('dic_'):
__write_view_tmpl(tag_list)
__write_filter_tmpl(TPL_LIST)
__write_list_tmpl(TPL_LISTINFO)
|
def generate_html_files(*args)
|
Generate the templates for adding, editing, viewing.
:return: None
| 10.488691 | 7.1757 | 1.461696 |
'''
Index funtion.
'''
self.render('index/index.html',
userinfo=self.userinfo,
catalog_info=MCategory.query_all(by_order=True),
link=MLink.query_all(),
cfg=CMS_CFG,
view=MPost.query_most_pic(20),
kwd={}, )
|
def index(self)
|
Index funtion.
| 14.095179 | 11.56004 | 1.219302 |
'''
Add or update the category.
'''
logger.info('Collect info: user-{0}, uid-{1}'.format(self.userinfo.uid, app_id))
MCollect.add_or_update(self.userinfo.uid, app_id)
out_dic = {'success': True}
return json.dump(out_dic, self)
|
def add_or_update(self, app_id)
|
Add or update the category.
| 7.360161 | 6.105737 | 1.20545 |
'''
List of the user collections.
'''
current_page_num = int(cur_p) if cur_p else 1
current_page_num = 1 if current_page_num < 1 else current_page_num
num_of_cat = MCollect.count_of_user(self.userinfo.uid)
page_num = int(num_of_cat / CMS_CFG['list_num']) + 1
kwd = {'current_page': current_page_num}
self.render('misc/collect/list.html',
recs_collect=MCollect.query_pager_by_all(self.userinfo.uid,
current_page_num).objects(),
pager=tools.gen_pager_purecss('/collect/{0}'.format(the_list),
page_num,
current_page_num),
userinfo=self.userinfo,
cfg=CMS_CFG,
kwd=kwd)
|
def show_list(self, the_list, cur_p='')
|
List of the user collections.
| 5.031262 | 4.521214 | 1.112812 |
'''
Create the wiki.
'''
logger.info('Call create wiki')
title = post_data['title'].strip()
if len(title) < 2:
logger.info(' ' * 4 + 'The title is too short.')
return False
the_wiki = MWiki.get_by_wiki(title)
if the_wiki:
logger.info(' ' * 4 + 'The title already exists.')
MWiki.update(the_wiki.uid, post_data)
return
uid = '_' + tools.get_uu8d()
return MWiki.__create_rec(uid, '1', post_data=post_data)
|
def create_wiki(post_data)
|
Create the wiki.
| 5.380683 | 5.069155 | 1.061456 |
'''
The page would be created with slug.
'''
logger.info('Call create Page')
if MWiki.get_by_uid(slug):
return False
title = post_data['title'].strip()
if len(title) < 2:
return False
return MWiki.__create_rec(slug, '2', post_data=post_data)
|
def create_page(slug, post_data)
|
The page would be created with slug.
| 8.39388 | 6.573013 | 1.277022 |
'''
Create the record.
'''
uid = args[0]
kind = args[1]
post_data = kwargs['post_data']
try:
TabWiki.create(
uid=uid,
title=post_data['title'].strip(),
date=datetime.datetime.now(),
cnt_html=tools.markdown2html(post_data['cnt_md']),
time_create=tools.timestamp(),
user_name=post_data['user_name'],
cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md']),
time_update=tools.timestamp(),
view_count=1,
kind=kind, # 1 for wiki, 2 for page
)
return True
except:
return False
|
def __create_rec(*args, **kwargs)
|
Create the record.
| 4.365027 | 4.102376 | 1.064024 |
'''
List the wiki of dated.
'''
return TabWiki.select().where(
TabWiki.kind == kind
).order_by(
TabWiki.time_update.desc()
).limit(num)
|
def query_dated(num=10, kind='1')
|
List the wiki of dated.
| 7.197969 | 4.05042 | 1.777092 |
'''
List the most viewed wiki.
'''
return TabWiki.select().where(
TabWiki.kind == kind
).order_by(
TabWiki.view_count.desc()
).limit(num)
|
def query_most(num=8, kind='1')
|
List the most viewed wiki.
| 5.530084 | 3.646554 | 1.516524 |
'''
view count of the wiki, plus 1. By wiki
'''
entry = TabWiki.update(
view_count=TabWiki.view_count + 1
).where(
TabWiki.title == citiao
)
entry.execute()
|
def update_view_count(citiao)
|
view count of the wiki, plus 1. By wiki
| 8.889573 | 4.481564 | 1.983587 |
'''
update the count of wiki, by uid.
'''
entry = TabWiki.update(
view_count=TabWiki.view_count + 1
).where(
TabWiki.uid == uid
)
entry.execute()
|
def update_view_count_by_uid(uid)
|
update the count of wiki, by uid.
| 6.717699 | 4.251811 | 1.579962 |
'''
Get the wiki record by title.
'''
q_res = TabWiki.select().where(TabWiki.title == citiao)
the_count = q_res.count()
if the_count == 0 or the_count > 1:
return None
else:
MWiki.update_view_count(citiao)
return q_res.get()
|
def get_by_wiki(citiao)
|
Get the wiki record by title.
| 5.070554 | 4.138269 | 1.225284 |
'''
View count plus one.
'''
entry = TabWiki.update(
view_count=TabWiki.view_count + 1,
).where(TabWiki.uid == slug)
entry.execute()
|
def view_count_plus(slug)
|
View count plus one.
| 7.23843 | 6.408081 | 1.129578 |
'''
Qeury recent wiki.
'''
kind = kwargs.get('kind', '1')
limit = kwargs.get('limit', 50)
return TabWiki.select().where(TabWiki.kind == kind).limit(limit)
|
def query_all(**kwargs)
|
Qeury recent wiki.
| 8.394508 | 4.430963 | 1.894511 |
'''
Query wikis randomly.
'''
return TabWiki.select().where(
TabWiki.kind == kind
).order_by(
peewee.fn.Random()
).limit(num)
|
def query_random(num=6, kind='1')
|
Query wikis randomly.
| 6.444372 | 3.924259 | 1.642188 |
'''
Query pager
'''
return TabWiki.select().where(TabWiki.kind == kind).order_by(TabWiki.time_create.desc()).paginate(current_page_num, CMS_CFG['list_num'])
|
def query_pager_by_kind(kind, current_page_num=1)
|
Query pager
| 6.700467 | 6.279472 | 1.067043 |
'''
Get the count of certain kind.
'''
recs = TabWiki.select().where(TabWiki.kind == kind)
return recs.count()
|
def count_of_certain_kind(kind)
|
Get the count of certain kind.
| 10.901447 | 7.276956 | 1.498078 |
'''
Get ID by tag_name of the label.
'''
recs = TabTag.select().where(
(TabTag.name == tag_name) & (TabTag.kind == kind)
)
logger.info('tag count of {0}: {1} '.format(tag_name, recs.count()))
# the_id = ''
if recs.count() == 1:
the_id = recs.get().uid
elif recs.count() > 1:
rec0 = None
for rec in recs:
# Only keep one.
if rec0:
TabPost2Tag.delete().where(TabPost2Tag.tag_id == rec.uid).execute()
TabTag.delete().where(TabTag.uid == rec.uid).execute()
else:
rec0 = rec
the_id = rec0.uid
else:
the_id = MLabel.create_tag(tag_name)
return the_id
|
def get_id_by_name(tag_name, kind='z')
|
Get ID by tag_name of the label.
| 3.606329 | 3.252801 | 1.108684 |
'''
Get label by slug.
'''
label_recs = TabTag.select().where(TabTag.slug == tag_slug)
return label_recs.get() if label_recs else False
|
def get_by_slug(tag_slug)
|
Get label by slug.
| 6.013731 | 4.711514 | 1.27639 |
'''
Create tag record by tag_name
'''
cur_recs = TabTag.select().where(
(TabTag.name == tag_name) &
(TabTag.kind == kind)
)
if cur_recs.count():
uid = cur_recs.get().uid
# TabTag.delete().where(
# (TabTag.name == tag_name) &
# (TabTag.kind == kind)
# ).execute()
else:
uid = tools.get_uu4d_v2() # Label with the ID of v2.
while TabTag.select().where(TabTag.uid == uid).count() > 0:
uid = tools.get_uu4d_v2()
TabTag.create(
uid=uid,
slug=uid,
name=tag_name,
order=1,
count=0,
kind='z',
tmpl=9,
pid='zzzz',
)
return uid
|
def create_tag(tag_name, kind='z')
|
Create tag record by tag_name
| 4.038052 | 3.745062 | 1.078234 |
'''
Get records by post id.
'''
return TabPost2Tag.select(
TabPost2Tag,
TabTag.name.alias('tag_name'),
TabTag.uid.alias('tag_uid')
).join(
TabTag, on=(TabPost2Tag.tag_id == TabTag.uid)
).where(
(TabPost2Tag.post_id == post_id) & (TabTag.kind == 'z')
)
|
def get_by_uid(post_id)
|
Get records by post id.
| 3.480899 | 3.062206 | 1.136729 |
'''
Add the record.
'''
logger.info('Add label kind: {0}'.format(kind))
tag_id = MLabel.get_id_by_name(tag_name, 'z')
labelinfo = MPost2Label.get_by_info(post_id, tag_id)
if labelinfo:
entry = TabPost2Tag.update(
order=order,
).where(TabPost2Tag.uid == labelinfo.uid)
entry.execute()
else:
entry = TabPost2Tag.create(
uid=tools.get_uuid(),
post_id=post_id,
tag_id=tag_id,
order=order,
kind='z')
return entry.uid
|
def add_record(post_id, tag_name, order=1, kind='z')
|
Add the record.
| 4.10187 | 3.813781 | 1.075539 |
'''
Return the number of certian slug.
'''
return TabPost.select().join(
TabPost2Tag,
on=(TabPost.uid == TabPost2Tag.post_id)
).where(
(TabPost2Tag.tag_id == slug) & (TabPost.kind == kind)
).count()
|
def total_number(slug, kind='1')
|
Return the number of certian slug.
| 4.678604 | 3.093634 | 1.512333 |
'''
Query pager
'''
return TabPost.select().join(
TabPost2Tag, on=(TabPost.uid == TabPost2Tag.post_id)
).where(
(TabPost2Tag.tag_id == slug) &
(TabPost.kind == kind)
).paginate(current_page_num, CMS_CFG['list_num'])
|
def query_pager_by_slug(slug, kind='1', current_page_num=1)
|
Query pager
| 4.094581 | 3.883295 | 1.054409 |
'''
Adding or updating the evalution.
:param app_id: the ID of the post.
:param value: the evaluation
:return: in JSON format.
'''
MEvaluation.add_or_update(self.userinfo.uid, app_id, value)
out_dic = {
'eval0': MEvaluation.app_evaluation_count(app_id, 0),
'eval1': MEvaluation.app_evaluation_count(app_id, 1)
}
return json.dump(out_dic, self)
|
def add_or_update(self, app_id, value)
|
Adding or updating the evalution.
:param app_id: the ID of the post.
:param value: the evaluation
:return: in JSON format.
| 5.362446 | 3.008696 | 1.782316 |
'''
Command entry
'''
command_dic = {
'migrate': run_migrate,
'init': run_init,
'send_nologin': run_send_nologin,
'send_all': run_send_all,
'review': run_review,
'sitemap': run_sitemap,
'editmap': run_editmap,
'check_kind': run_check_kind,
'init_tables': run_init_tables,
'drop_tables': run_drop_tables,
'gen_category': run_gen_category,
'auto': run_auto,
'whoosh': run_whoosh,
'html': run_checkit,
'update_cat': run_update_cat,
'check200': run_check200,
}
try:
# 这里的 h 就表示该选项无参数,i:表示 i 选项后需要有参数
opts, args = getopt.getopt(argv, "hi:")
except getopt.GetoptError:
print('Error: helper.py -i cmd')
sys.exit(2)
for opt, arg in opts:
if opt == "-h":
print('helper.py -i cmd')
print('cmd list ----------------------')
print(' init: ')
print(' migrate: ')
print(' review: ')
print(' -------------')
print(' send_all: ')
print(' send_nologin: ')
print(' sitemap: ')
print(' editmap: ')
print(' check_kind: ')
print(' check200: ')
sys.exit()
elif opt == "-i":
if arg in command_dic:
command_dic[arg](args)
print('QED!')
else:
print('Wrong Command.')
|
def entry(argv)
|
Command entry
| 3.93647 | 3.899795 | 1.009404 |
'''
create entity2user record in the database.
'''
record = TabEntity2User.select().where(
(TabEntity2User.entity_id == enti_uid) & (TabEntity2User.user_id == user_id)
)
if record.count() > 0:
record = record.get()
MEntity2User.count_increate(record.uid, record.count)
else:
TabEntity2User.create(
uid=tools.get_uuid(),
entity_id=enti_uid,
user_id=user_id,
count=1,
timestamp=time.time()
)
|
def create_entity2user(enti_uid, user_id)
|
create entity2user record in the database.
| 3.302086 | 3.032425 | 1.088926 |
'''
Checking the HTML
'''
sig = False
for html_line in open(html_file).readlines():
# uu = x.find('{% extends')
uuu = pack_str(html_line).find('%extends')
# print(pack_str(x))
if uuu > 0:
f_tmpl = html_line.strip().split()[-2].strip('"')
curpath, curfile = os.path.split(html_file)
ff_tmpl = os.path.abspath(os.path.join(curpath, f_tmpl))
if os.path.isfile(ff_tmpl):
# print(os.path.abspath(ff_tmpl))
pass
else:
print('=' *10 + 'ERROR' + '=' *10)
print('The file:')
print(' ' * 4 + html_file)
print('needs:')
print(' ' * 4 +ff_tmpl)
print('Error, tmpl not find.')
# continue
sys.exit(1)
sig = True
if sig:
pass
else:
continue
vvv = pack_str(html_line).find('%block')
if vvv > 0:
test_fig = False
for the_line in open(ff_tmpl).readlines():
if the_line.find(pack_str(html_line)) > 0:
test_fig = True
# fff = sim_filename(ff_tmpl)
# sss = sim_filename(html_file)
fff = ff_tmpl[begin:]
sss = html_file[begin:]
tmplsig = [fff, sss]
if tmplsig in RELS_UNIQ_ARR:
pass
else:
RELS_UNIQ_ARR.append(tmplsig)
DOT_OBJ.edge(fff, sss)
if test_fig:
# G.add_edge(ff_tmpl[begin], html_file[begin])
pass
else:
pass
|
def check_html(html_file, begin)
|
Checking the HTML
| 4.368942 | 4.287201 | 1.019066 |
'''
do something in the directory.
'''
inws = os.path.abspath(inws)
for wroot, wdirs, wfiles in os.walk(inws):
for wfile in wfiles:
if wfile.endswith('.html'):
if 'autogen' in wroot:
continue
check_html(os.path.abspath(os.path.join(wroot, wfile)), begin)
|
def do_for_dir(inws, begin)
|
do something in the directory.
| 3.449185 | 3.126226 | 1.103306 |
'''
do check it.
'''
begin = len(os.path.abspath('templates')) + 1
inws = os.path.abspath(os.getcwd())
if srws:
do_for_dir(srws[0], begin)
else:
do_for_dir(os.path.join(inws, 'templates'), begin)
DOT_OBJ.render('xxtmpl', view=True)
|
def run_checkit(srws=None)
|
do check it.
| 8.120201 | 7.321507 | 1.109089 |
'''
Query all the records from TabPost2Tag.
'''
recs = TabPost2Tag.select(
TabPost2Tag,
TabTag.kind.alias('tag_kind'),
).join(
TabTag,
on=(TabPost2Tag.tag_id == TabTag.uid)
)
return recs
|
def query_all()
|
Query all the records from TabPost2Tag.
| 5.668561 | 3.078705 | 1.841216 |
'''
Delete the record of post 2 tag.
'''
entry = TabPost2Tag.delete().where(
(TabPost2Tag.post_id == post_id) &
(TabPost2Tag.tag_id == tag_id)
)
entry.execute()
MCategory.update_count(tag_id)
|
def remove_relation(post_id, tag_id)
|
Delete the record of post 2 tag.
| 5.177446 | 3.64135 | 1.421848 |
'''
Delete the records of certain tag.
'''
entry = TabPost2Tag.delete().where(
TabPost2Tag.tag_id == tag_id
)
entry.execute()
|
def remove_tag(tag_id)
|
Delete the records of certain tag.
| 8.962017 | 6.066004 | 1.477417 |
'''
Query records by post.
'''
return TabPost2Tag.select().where(
TabPost2Tag.post_id == postid
).order_by(TabPost2Tag.order)
|
def query_by_post(postid)
|
Query records by post.
| 5.901196 | 5.020892 | 1.175328 |
'''
Geo the record by post and catalog.
'''
recs = TabPost2Tag.select().where(
(TabPost2Tag.post_id == post_id) &
(TabPost2Tag.tag_id == catalog_id)
)
if recs.count() == 1:
return recs.get()
elif recs.count() > 1:
# return the first one, and delete others.
out_rec = None
for rec in recs:
if out_rec:
entry = TabPost2Tag.delete().where(
TabPost2Tag.uid == rec.uid
)
entry.execute()
else:
out_rec = rec
return out_rec
return None
|
def __get_by_info(post_id, catalog_id)
|
Geo the record by post and catalog.
| 3.308052 | 2.682365 | 1.23326 |
'''
The count of post2tag.
'''
recs = TabPost2Tag.select(
TabPost2Tag.tag_id,
peewee.fn.COUNT(TabPost2Tag.tag_id).alias('num')
).group_by(
TabPost2Tag.tag_id
)
return recs
|
def query_count()
|
The count of post2tag.
| 4.748882 | 3.198071 | 1.484921 |
'''
Update the field of post2tag.
'''
if post_id:
entry = TabPost2Tag.update(
post_id=post_id
).where(TabPost2Tag.uid == uid)
entry.execute()
if tag_id:
entry2 = TabPost2Tag.update(
par_id=tag_id[:2] + '00',
tag_id=tag_id,
).where(TabPost2Tag.uid == uid)
entry2.execute()
if par_id:
entry2 = TabPost2Tag.update(
par_id=par_id
).where(TabPost2Tag.uid == uid)
entry2.execute()
|
def update_field(uid, post_id=None, tag_id=None, par_id=None)
|
Update the field of post2tag.
| 2.645675 | 2.327021 | 1.136936 |
'''
Create the record of post 2 tag, and update the count in g_tag.
'''
rec = MPost2Catalog.__get_by_info(post_id, catalog_id)
if rec:
entry = TabPost2Tag.update(
order=order,
# For migration. the value should be added when created.
par_id=rec.tag_id[:2] + '00',
).where(TabPost2Tag.uid == rec.uid)
entry.execute()
else:
TabPost2Tag.create(
uid=tools.get_uuid(),
par_id=catalog_id[:2] + '00',
post_id=post_id,
tag_id=catalog_id,
order=order,
)
MCategory.update_count(catalog_id)
|
def add_record(post_id, catalog_id, order=0)
|
Create the record of post 2 tag, and update the count in g_tag.
| 5.851505 | 4.116545 | 1.42146 |
'''
Get the count of certain category.
'''
if cat_id.endswith('00'):
# The first level category, using the code bellow.
cat_con = TabPost2Tag.par_id == cat_id
else:
cat_con = TabPost2Tag.tag_id == cat_id
if tag:
condition = {
'def_tag_arr': [tag]
}
recs = TabPost2Tag.select().join(
TabPost,
on=((TabPost2Tag.post_id == TabPost.uid) & (TabPost.valid == 1))
).where(
cat_con & TabPost.extinfo.contains(condition)
)
else:
recs = TabPost2Tag.select().where(
cat_con
)
return recs.count()
|
def count_of_certain_category(cat_id, tag='')
|
Get the count of certain category.
| 4.645392 | 4.424167 | 1.050004 |
'''
Query pager via category slug.
'''
cat_rec = MCategory.get_by_slug(slug)
if cat_rec:
cat_id = cat_rec.uid
else:
return None
# The flowing code is valid.
if cat_id.endswith('00'):
# The first level category, using the code bellow.
cat_con = TabPost2Tag.par_id == cat_id
else:
cat_con = TabPost2Tag.tag_id == cat_id
if tag:
condition = {
'def_tag_arr': [tag]
}
recs = TabPost.select().join(
TabPost2Tag,
on=((TabPost.uid == TabPost2Tag.post_id) & (TabPost.valid == 1))
).where(
cat_con & TabPost.extinfo.contains(condition)
).order_by(
TabPost.time_update.desc()
).paginate(current_page_num, CMS_CFG['list_num'])
elif order:
recs = TabPost.select().join(
TabPost2Tag,
on=((TabPost.uid == TabPost2Tag.post_id) & (TabPost.valid == 1))
).where(
cat_con
).order_by(
TabPost.order.asc()
)
else:
recs = TabPost.select().join(
TabPost2Tag,
on=((TabPost.uid == TabPost2Tag.post_id) & (TabPost.valid == 1))
).where(
cat_con
).order_by(
TabPost.time_update.desc()
).paginate(current_page_num, CMS_CFG['list_num'])
return recs
|
def query_pager_by_slug(slug, current_page_num=1, tag='', order=False)
|
Query pager via category slug.
| 2.766517 | 2.644929 | 1.04597 |
'''
Query post2tag by certain post.
'''
if kind == '':
return TabPost2Tag.select(
TabPost2Tag,
TabTag.slug.alias('tag_slug'),
TabTag.name.alias('tag_name')
).join(
TabTag, on=(TabPost2Tag.tag_id == TabTag.uid)
).where(
(TabPost2Tag.post_id == idd) &
(TabTag.kind != 'z')
).order_by(
TabPost2Tag.order
)
return TabPost2Tag.select(
TabPost2Tag,
TabTag.slug.alias('tag_slug'),
TabTag.name.alias('tag_name')
).join(TabTag, on=(TabPost2Tag.tag_id == TabTag.uid)).where(
(TabTag.kind == kind) &
(TabPost2Tag.post_id == idd)
).order_by(
TabPost2Tag.order
)
|
def query_by_entity_uid(idd, kind='')
|
Query post2tag by certain post.
| 2.244129 | 1.871016 | 1.199417 |
'''
Get the first, as the uniqe category of post.
'''
recs = MPost2Catalog.query_by_entity_uid(app_uid).objects()
if recs.count() > 0:
return recs.get()
return None
|
def get_first_category(app_uid)
|
Get the first, as the uniqe category of post.
| 12.528551 | 6.07507 | 2.062289 |
'''
fun(uid_with_str)
fun(uid_with_str, slug = val1, glyph = val2)
'''
uid_with_str = args[0]
slug = kwargs.get('slug', False)
with_title = kwargs.get('with_title', False)
glyph = kwargs.get('glyph', '')
kwd = {
'glyph': glyph
}
curinfo = MCategory.get_by_uid(uid_with_str)
sub_cats = MCategory.query_sub_cat(uid_with_str)
if slug:
tmpl = 'modules/info/catalog_slug.html'
else:
tmpl = 'modules/info/catalog_of.html'
return self.render_string(tmpl,
pcatinfo=curinfo,
sub_cats=sub_cats,
recs=sub_cats,
with_title=with_title,
kwd=kwd)
|
def render(self, *args, **kwargs)
|
fun(uid_with_str)
fun(uid_with_str, slug = val1, glyph = val2)
| 4.798561 | 3.369214 | 1.424237 |
'''
fun(user_name, kind)
fun(user_name, kind, num)
fun(user_name, kind, num, with_tag = val1, glyph = val2)
fun(user_name = vala, kind = valb, num = valc, with_tag = val1, glyph = val2)
'''
user_name = kwargs.get('user_name', args[0])
kind = kwargs.get('kind', args[1])
num = kwargs.get('num', args[2] if len(args) > 2 else 6)
with_tag = kwargs.get('with_tag', False)
glyph = kwargs.get('glyph', '')
all_cats = MUsage.query_most(user_name, kind, num).objects()
kwd = {
'with_tag': with_tag,
'router': router_post[kind],
'glyph': glyph
}
return self.render_string('modules/info/list_user_equation.html',
recs=all_cats,
kwd=kwd)
|
def render(self, *args, **kwargs)
|
fun(user_name, kind)
fun(user_name, kind, num)
fun(user_name, kind, num, with_tag = val1, glyph = val2)
fun(user_name = vala, kind = valb, num = valc, with_tag = val1, glyph = val2)
| 4.113837 | 2.691802 | 1.528284 |
'''
Render without userinfo.
fun(kind, num)
fun(kind, num, with_tag = val1)
fun(kind, num, with_tag = val1, glyph = val2)
'''
kind = kwargs.get('kind', args[0])
num = kwargs.get('num', args[1] if len(args) > 1 else 6)
with_tag = kwargs.get('with_tag', False)
glyph = kwargs.get('glyph', '')
all_cats = MPost.query_most(kind=kind, num=num).objects()
kwd = {
'with_tag': with_tag,
'router': router_post[kind],
'glyph': glyph
}
return self.render_string('modules/info/list_equation.html',
recs=all_cats,
kwd=kwd)
|
def render_it(self, *args, **kwargs)
|
Render without userinfo.
fun(kind, num)
fun(kind, num, with_tag = val1)
fun(kind, num, with_tag = val1, glyph = val2)
| 5.693475 | 3.354977 | 1.697023 |
'''
render, no user logged in
'''
all_cats = MPost.query_recent(num, kind=kind)
kwd = {
'with_tag': with_tag,
'router': router_post[kind],
'glyph': glyph
}
return self.render_string('modules/info/list_equation.html',
recs=all_cats,
kwd=kwd)
|
def render_it(self, kind, num, with_tag=False, glyph='')
|
render, no user logged in
| 10.568489 | 8.486609 | 1.245313 |
'''
render, with userinfo
fun(kind, num)
fun(kind, num, with_tag = val1)
fun(kind, num, with_tag = val1, user_id = val2)
fun(kind, num, with_tag = val1, user_id = val2, glyph = val3)
'''
kind = kwargs.get('kind', args[0])
num = kwargs.get('num', args[1] if len(args) > 1 else 6)
with_tag = kwargs.get('with_tag', False)
user_id = kwargs.get('user_id', '')
glyph = kwargs.get('glyph', '')
logger.info(
'Infor user recent, username: {user_name}, kind: {kind}, num: {num}'.format(
user_name=user_id, kind=kind, num=num
)
)
all_cats = MUsage.query_recent(user_id, kind, num).objects()
kwd = {
'with_tag': with_tag,
'router': router_post[kind],
'glyph': glyph
}
return self.render_string('modules/info/list_user_equation.html',
recs=all_cats,
kwd=kwd)
|
def render_user(self, *args, **kwargs)
|
render, with userinfo
fun(kind, num)
fun(kind, num, with_tag = val1)
fun(kind, num, with_tag = val1, user_id = val2)
fun(kind, num, with_tag = val1, user_id = val2, glyph = val3)
| 4.318888 | 3.060878 | 1.410996 |
'''
Recent links.
'''
kwd = {
'pager': '',
'title': '最近文档',
}
if self.is_p:
self.render('admin/link_ajax/link_list.html',
kwd=kwd,
view=MLink.query_link(20),
format_date=tools.format_date,
userinfo=self.userinfo)
else:
self.render('misc/link/link_list.html',
kwd=kwd,
view=MLink.query_link(20),
format_date=tools.format_date,
userinfo=self.userinfo)
|
def recent(self)
|
Recent links.
| 5.076901 | 4.438243 | 1.143899 |
'''
To add link
'''
if self.check_post_role()['ADD']:
pass
else:
return False
kwd = {
'pager': '',
'uid': '',
}
self.render('misc/link/link_add.html',
topmenu='',
kwd=kwd,
userinfo=self.userinfo, )
|
def to_add_link(self, )
|
To add link
| 9.414504 | 8.470048 | 1.111505 |
'''
Update the link.
'''
if self.userinfo.role[1] >= '3':
pass
else:
return False
post_data = self.get_post_data()
post_data['user_name'] = self.get_current_user()
if self.is_p:
if MLink.update(uid, post_data):
output = {
'addinfo ': 1,
}
else:
output = {
'addinfo ': 0,
}
return json.dump(output, self)
else:
if MLink.update(uid, post_data):
self.redirect('/link/list')
|
def update(self, uid)
|
Update the link.
| 5.363812 | 4.919048 | 1.090417 |
'''
Try to edit the link.
'''
if self.userinfo.role[1] >= '3':
pass
else:
return False
self.render('misc/link/link_edit.html',
kwd={},
postinfo=MLink.get_by_uid(uid),
userinfo=self.userinfo)
|
def to_modify(self, uid)
|
Try to edit the link.
| 10.027939 | 7.970329 | 1.258159 |
'''
View the link.
'''
rec = MLink.get_by_uid(post_id)
if not rec:
kwd = {'info': '您要找的分类不存在。'}
self.render('misc/html/404.html', kwd=kwd)
return False
kwd = {
'pager': '',
'editable': self.editable(),
}
self.render('misc/link/link_view.html',
view=rec,
kwd=kwd,
userinfo=self.userinfo,
cfg=CMS_CFG, )
|
def viewit(self, post_id)
|
View the link.
| 6.466049 | 5.932338 | 1.089966 |
'''
user add link.
'''
if self.check_post_role()['ADD']:
pass
else:
return False
post_data = self.get_post_data()
post_data['user_name'] = self.get_current_user()
cur_uid = tools.get_uudd(2)
while MLink.get_by_uid(cur_uid):
cur_uid = tools.get_uudd(2)
if MLink.create_link(cur_uid, post_data):
output = {
'addinfo ': 1,
}
else:
output = {
'addinfo ': 0,
}
return json.dump(output, self)
|
def p_user_add_link(self)
|
user add link.
| 5.06057 | 4.763991 | 1.062254 |
'''
Create link by user.
'''
if self.check_post_role()['ADD']:
pass
else:
return False
post_data = self.get_post_data()
post_data['user_name'] = self.get_current_user()
cur_uid = tools.get_uudd(2)
while MLink.get_by_uid(cur_uid):
cur_uid = tools.get_uudd(2)
MLink.create_link(cur_uid, post_data)
self.redirect('/link/list')
|
def user_add_link(self)
|
Create link by user.
| 5.313831 | 4.514837 | 1.176971 |
'''
Delete a link by id.
'''
if self.check_post_role()['DELETE']:
pass
else:
return False
if self.is_p:
if MLink.delete(del_id):
output = {'del_link': 1}
else:
output = {'del_link': 0}
return json.dump(output, self)
else:
is_deleted = MLink.delete(del_id)
if is_deleted:
self.redirect('/link/list')
|
def delete_by_id(self, del_id)
|
Delete a link by id.
| 5.653185 | 5.086596 | 1.111389 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.