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_... | 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='c... | 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_lis... | 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(['h... | 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(['h... | 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 ... | 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_'):
# 此处简... | 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_'):
o... | 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... | 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=kw... | 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.... | 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... | 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,
... | 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:
... | 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_c... | 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 == ... | 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)
... | 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),
... | 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_... | 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.w... | 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_di... | 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'],
... | 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
).joi... | 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:
... | 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 Assert... | 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
... | 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']
F... | 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_d... | 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.co... | 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,
... | 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_p... | 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
... | 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:
... | 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=... | 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_h... | 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_... | 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.na... | 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_... | 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,
... | 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_co... | 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,
... | 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_i... | 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('"')
curpa... | 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.j... | 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:
#... | 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]... | 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.
... | 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 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 th... | 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 == T... | 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
... | 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('ki... | 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_ta... | 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',
... | 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', a... | 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),
forma... | 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=k... | 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):
... | 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.userin... | 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(),
... | 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)... | 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(cu... | 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}
... | 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.