code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
'''
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) | Delete user in the database by `user_name`. | 4.231161 | 3.4666 | 1.220551 |
'''
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) | Delele the user in the database by `user_id`. | 5.901251 | 3.502033 | 1.685093 |
'''
Generate the urls for posts.
:return: None
'''
with open(file_name, 'a') as fout:
for kind_key in router_post:
recent_posts = MPost.query_all(kind=kind_key, limit=1000000)
for recent_post in recent_posts:
url = os.path.join(SITE_CFG['site_url'],
... | def gen_post_map(file_name, ext_url='') | Generate the urls for posts.
:return: None | 4.659058 | 3.961854 | 1.175979 |
'''
Generate the urls for wiki.
:return: None
'''
# wiki
wiki_recs = MWiki.query_all(limit=10000, kind='1')
with open(file_name, 'a') as fileout:
for rec in wiki_recs:
url = os.path.join(SITE_CFG['site_url'],
'wiki' + '/_edit' if ext_url e... | def gen_wiki_map(file_name, ext_url='') | Generate the urls for wiki.
:return: None | 3.042925 | 2.734894 | 1.11263 |
'''
Generate the sitemap file.
:param args: args
:return: None
'''
site_map_file = 'xx_sitemap.txt'
if os.path.exists(site_map_file):
os.remove(site_map_file)
gen_wiki_map(site_map_file)
gen_post_map(site_map_file) | def run_sitemap(_) | Generate the sitemap file.
:param args: args
:return: None | 3.897916 | 3.41174 | 1.142501 |
'''
Generate the urls file for editing.
:param args: args
:return: None
'''
edit_map_file = 'xx_editmap.txt'
if os.path.exists(edit_map_file):
os.remove(edit_map_file)
gen_wiki_map(edit_map_file, ext_url='_edit')
gen_post_map(edit_map_file, ext_url='_edit') | def run_editmap(_) | Generate the urls file for editing.
:param args: args
:return: None | 4.76021 | 3.750182 | 1.269328 |
'''
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().en... | def get_meta(catid, sig) | Get metadata of dataset via ID. | 5.580027 | 5.279693 | 1.056885 |
'''
Update the category of the post.
:param uid: The ID of the post. Extra info would get by requests.
'''
# deprecated
# catid = kwargs['catid'] if MCategory.get_by_uid(kwargs.get('catid')) else None
# post_data = self.get_post_data()
if 'gcat0' in post_data:
pass
else:
... | def update_category(uid, post_data) | Update the category of the post.
:param uid: The ID of the post. Extra info would get by requests. | 3.761338 | 3.395042 | 1.107891 |
'''
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 == '':
... | def update_label(signature, post_data) | Update the label when updating. | 3.832212 | 3.506691 | 1.092828 |
'''
The default page of POST.
'''
self.render('post_{0}/post_index.html'.format(self.kind),
userinfo=self.userinfo,
kwd={'uid': '', }) | def index(self) | The default page of POST. | 17.432436 | 9.323946 | 1.869641 |
'''
Generate the ID for post.
:return: the new ID.
'''
cur_uid = self.kind + tools.get_uu4d()
while MPost.get_by_uid(cur_uid):
cur_uid = self.kind + tools.get_uu4d()
return cur_uid | def _gen_uid(self) | Generate the ID for post.
:return: the new ID. | 7.662562 | 4.486291 | 1.707995 |
'''
According to the application, each info of it's classification could
has different temaplate.
:param rec: the App record.
:return: the temaplte path.
'''
if 'def_cat_uid' in rec.extinfo and rec.extinfo['def_cat_uid'] != '':
cat_id = rec.extinfo['d... | def _get_tmpl_view(self, rec) | According to the application, each info of it's classification could
has different temaplate.
:param rec: the App record.
:return: the temaplte path. | 4.853715 | 3.061646 | 1.585329 |
'''
Used for info2.
:param catid: the uid of category
'''
catinfo = MCategory.get_by_uid(catid)
kwd = {
'uid': self._gen_uid(),
'userid': self.userinfo.user_name if self.userinfo else '',
'gcat0': catid,
'parentname': MCate... | def _to_add_with_category(self, catid) | Used for info2.
:param catid: the uid of category | 5.354309 | 4.118379 | 1.300101 |
'''
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) | Try to get the post. If not, to add the wiki. | 7.932034 | 4.343462 | 1.826201 |
'''
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... | def _to_add(self, **kwargs) | Used for info1. | 5.778893 | 4.89182 | 1.181338 |
'''
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 'gcat... | def _to_edit(self, infoid) | render the HTML page for post editing. | 3.73189 | 3.579218 | 1.042655 |
'''
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 M... | def _gen_last_current_relation(self, post_id) | Generate the relation for the post and last post viewed. | 3.231098 | 2.549365 | 1.267413 |
'''
Redirect according the kind of the post.
:param postinfo: the postinfo
:return: None
'''
logger.warning('info kind:{0} '.format(postinfo.kind))
# If not, there must be something wrong.
if postinfo.kind == self.kind:
pass
else:
... | def redirect_kind(self, postinfo) | Redirect according the kind of the post.
:param postinfo: the postinfo
:return: None | 6.174779 | 4.667446 | 1.322946 |
'''
In infor.
'''
self.redirect_kind(postinfo)
# ToDo: 原为下面代码。
# ext_catid = postinfo.extinfo['def_cat_uid'] if 'def_cat_uid' in postinfo.extinfo else ''
# ext_catid2 = postinfo.extinfo['def_cat_uid'] if 'def_cat_uid' in postinfo.extinfo else None
ext_ca... | def viewinfo(self, postinfo) | In infor. | 4.692673 | 4.564913 | 1.027987 |
'''
Generate the kwd dict for view.
:param postinfo: the postinfo
:return: dict
'''
kwd = {
'pager': '',
'url': self.request.uri,
'cookie_str': tools.get_uuid(),
'daohangstr': '',
'signature': postinfo.uid,
... | def _the_view_kwd(self, postinfo) | Generate the kwd dict for view.
:param postinfo: the postinfo
:return: dict | 6.31526 | 5.354963 | 1.179328 |
'''
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 categ... | def fetch_additional_posts(self, uid) | fetch the rel_recs, and random recs when view the post. | 4.213413 | 3.186529 | 1.322258 |
'''
Add the relation. And the from and to, should have different weight.
:param f_uid: the uid of `from` post.
:param t_uid: the uid of `to` post.
:return: return True if the relation has been succesfully added.
'''
if not MPost.get_by_uid(t_uid):
retu... | def _add_relation(self, f_uid, t_uid) | Add the relation. And the from and to, should have different weight.
:param f_uid: the uid of `from` post.
:param t_uid: the uid of `to` post.
:return: return True if the relation has been succesfully added. | 3.736472 | 2.651968 | 1.408943 |
'''
fetch post accessed data. post_data, and ext_dic.
'''
post_data = {}
ext_dic = {}
for key in self.request.arguments:
if key.startswith('ext_') or key.startswith('tag_'):
ext_dic[key] = self.get_argument(key)
else:
... | def fetch_post_data(self) | fetch post accessed data. post_data, and ext_dic. | 4.177336 | 3.09427 | 1.350023 |
'''
in infor.
'''
if 'uid' in kwargs:
uid = kwargs['uid']
else:
uid = self._gen_uid()
post_data, ext_dic = self.fetch_post_data()
if 'gcat0' in post_data:
pass
else:
return False
if 'valid' in post_... | def add(self, **kwargs) | in infor. | 4.57488 | 4.443582 | 1.029548 |
'''
in infor.
'''
postinfo = MPost.get_by_uid(uid)
if postinfo.kind == self.kind:
pass
else:
return False
post_data, ext_dic = self.fetch_post_data()
if 'gcat0' in post_data:
pass
else:
return False... | def update(self, uid) | in infor. | 4.768541 | 4.668727 | 1.021379 |
'''
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'])... | def _delete(self, *args, **kwargs) | delete the post. | 5.015236 | 4.739066 | 1.058275 |
'''
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... | 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. | 5.243207 | 2.590023 | 2.024387 |
'''
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 = {}
... | def _to_edit_kind(self, post_uid) | Show the page for changing the category. | 7.208519 | 5.933138 | 1.214959 |
'''
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... | def _change_kind(self, post_uid) | To modify the category of the post, and kind. | 6.809023 | 5.141751 | 1.324262 |
'''
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... | def list(self, cur_p='') | Lists of the entities. | 4.768538 | 4.147997 | 1.1496 |
'''
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)
... | def down(self, down_uid) | Download the entity by UID. | 7.131328 | 6.382057 | 1.117403 |
'''
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) | To add the entity. | 11.052478 | 8.291032 | 1.333064 |
'''
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(p... | def add_entity(self) | Add the entity. All the information got from the post data. | 3.049761 | 2.167531 | 1.407021 |
'''
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(u... | def add_pic(self, post_data) | Adding the picture. | 2.994818 | 2.91574 | 1.027121 |
'''
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.s... | def add_pdf(self, post_data) | Adding the pdf file. | 3.78924 | 3.633313 | 1.042916 |
'''
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... | def add_url(self, post_data) | Adding the URL as entity. | 4.878012 | 4.249803 | 1.147821 |
'''
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}
... | def p_changepassword(self) | Changing password. | 5.484508 | 5.171918 | 1.06044 |
'''
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)
out... | def p_changeinfo(self) | Change Infor via Ajax. | 8.146511 | 6.367929 | 1.279303 |
'''
fetch post accessed data. post_data, and ext_dic.
'''
post_data = {}
ext_dic = {}
for key in self.request.arguments:
if key.startswith('def_'):
ext_dic[key] = self.get_argument(key)
else:
post_data[key] = self.ge... | def fetch_post_data(self) | fetch post accessed data. post_data, and ext_dic. | 4.276234 | 2.720114 | 1.572079 |
'''
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... | def __check_valid(self, post_data) | To check if the user is succesfully created.
Return the status code dict. | 2.243061 | 1.801118 | 1.245371 |
'''
The first char of 'code' stands for the different field.
'1' for user_name
'2' for user_email
'3' for user_pass
'4' for user_role
The seconde char of 'code' stands for different status.
'1' for invalide
'2' for already exists.
'''
... | def json_register(self) | The first char of 'code' stands for the different field.
'1' for user_name
'2' for user_email
'3' for user_pass
'4' for user_role
The seconde char of 'code' stands for different status.
'1' for invalide
'2' for already exists. | 4.168939 | 2.364059 | 1.763467 |
'''
The first char of 'code' stands for the different field.
'1' for user_name
'2' for user_email
'3' for user_pass
'4' for user_role
The seconde char of 'code' stands for different status.
'1' for invalide
'2' for already exists.
'''
... | def json_changeinfo(self) | The first char of 'code' stands for the different field.
'1' for user_name
'2' for user_email
'3' for user_pass
'4' for user_role
The seconde char of 'code' stands for different status.
'1' for invalide
'2' for already exists. | 4.819852 | 2.960843 | 1.627865 |
'''
The first char of 'code' stands for the different field.
'1' for user_name
'2' for user_email
'3' for user_pass
'4' for user_role
The seconde char of 'code' stands for different status.
'1' for invalide
'2' for already exists.
'''
... | def json_changepass(self) | The first char of 'code' stands for the different field.
'1' for user_name
'2' for user_email
'3' for user_pass
'4' for user_role
The seconde char of 'code' stands for different status.
'1' for invalide
'2' for already exists. | 4.952671 | 3.079068 | 1.608497 |
'''
user login.
'''
post_data = self.get_post_data()
if 'next' in post_data:
next_url = post_data['next']
else:
next_url = '/'
u_name = post_data['user_name']
u_pass = post_data['user_pass']
result = MUser.check_user_by_n... | def login(self) | user login. | 3.213739 | 3.149952 | 1.02025 |
'''
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, ) | To find, pager. | 13.673448 | 8.78847 | 1.555839 |
'''
find by keyword.
'''
if not keyword:
self.__to_find__(cur_p)
kwd = {
'pager': '',
'title': '查找结果',
}
self.render(self.wrap_tmpl('user/{sig}user_find_list.html'),
kwd=kwd,
view=MUse... | def find(self, keyword=None, cur_p='') | find by keyword. | 12.461843 | 11.821466 | 1.054171 |
'''
Do reset password
:return:
'''
post_data = self.get_post_data()
if 'email' in post_data:
userinfo = MUser.get_by_email(post_data['email'])
if tools.timestamp() - userinfo.time_reset_passwd < 70:
self.set_status(400)
... | def reset_password(self) | Do reset password
:return: | 3.693774 | 3.617055 | 1.02121 |
'''
reseting password
'''
post_data = self.get_post_data()
userinfo = MUser.get_by_name(post_data['u'])
sub_timestamp = int(post_data['t'])
cur_timestamp = tools.timestamp()
if cur_timestamp - sub_timestamp < 600 and cur_timestamp > sub_timestamp:
... | def gen_passwd(self) | reseting password | 3.077472 | 2.973366 | 1.035013 |
'''
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) | Set the cookie for locale. | 3.160412 | 2.449696 | 1.290124 |
'''
for checkbox
'''
view_zuoxiang = '''
<div class="col-sm-4"><span class="des">{0}</span></div>
<div class="col-sm-8">
'''.format(sig_dic['zh'])
dic_tmp = sig_dic['dic']
for key in dic_tmp.keys():
tmp_str = '''<span class="input_text">
{{% if '{0}' in postinfo.ex... | def gen_radio_view(sig_dic) | for checkbox | 4.289013 | 4.175012 | 1.027306 |
'''
for checkbox
'''
view_zuoxiang = '''
<div class="col-sm-4"><span class="des">{0}</span></div>
<div class="col-sm-8">
'''.format(sig_dic['zh'])
dic_tmp = sig_dic['dic']
for key in dic_tmp.keys():
tmp_str = '''
<span>
{{% if "{0}" in postinfo.extinfo["{1}... | def gen_checkbox_view(sig_dic) | for checkbox | 4.101243 | 4.116076 | 0.996396 |
'''
HTML view, for selection.
'''
option_str = ''
dic_tmp = sig_dic['dic']
for key, val in dic_tmp.items():
tmp_str = '''
{{% if '{sig_en}' in postinfo.extinfo %}}
{{% set tmp_var = postinfo.extinfo["{sig_en}"] %}}
{{% if tmp_var == "{sig_key}" %}}
... | def gen_select_view(sig_dic) | HTML view, for selection. | 3.415179 | 3.2462 | 1.052054 |
'''
For generating List view HTML file for RADIO.
for each item.
'''
view_zuoxiang = '''<span class="iga_pd_val">'''
dic_tmp = sig_dic['dic']
for key in dic_tmp.keys():
tmp_str = '''{{% if postinfo.extinfo['{0}'][0] == "{1}" %}} {2} {{% end %}}
'''.format(sig_dic['en'], key,... | def gen_radio_list(sig_dic) | For generating List view HTML file for RADIO.
for each item. | 7.509722 | 5.270314 | 1.42491 |
'''
For generating List view HTML file for CHECKBOX.
for each item.
'''
view_zuoxiang = '''<span class="iga_pd_val">'''
dic_tmp = sig_dic['dic']
for key in dic_tmp.keys():
tmp_str = '''{{% if "{0}" in postinfo.extinfo["{1}"] %}} {2} {{% end %}}
'''.format(key, sig_dic['en']... | def gen_checkbox_list(sig_dic) | For generating List view HTML file for CHECKBOX.
for each item. | 7.532079 | 5.268412 | 1.429668 |
'''
For generating List view HTML file for SELECT.
for each item.
'''
view_jushi = '''<span class="label label-primary" style="margin-right:10px">'''
dic_tmp = sig_dic['dic']
for key in dic_tmp.keys():
tmp_str = '''{{% if '{0}' in postinfo.extinfo and postinfo.extinfo["{0}"][0] == "... | def gen_select_list(sig_dic) | For generating List view HTML file for SELECT.
for each item. | 5.795949 | 4.152918 | 1.395633 |
'''
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']
)
els... | def gen_input_add(sig_dic) | Adding for HTML Input control. | 3.002796 | 2.48388 | 1.208914 |
'''
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']
)
e... | def gen_input_edit(sig_dic) | Editing for HTML input control. | 2.833171 | 2.462487 | 1.150532 |
'''
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',
... | def gen_input_view(sig_dic) | Viewing the HTML text. | 3.784822 | 3.368173 | 1.123702 |
'''
Adding for HTML radio control.
'''
# html_zuoxiang = '''
# <label for="{0}"><span>
# <a class="glyphicon glyphicon-star" style="color: red;font-size: xx-small;"></a> {1}</span>
# '''.format(sig['en'], sig['zh'])
# each item for radio.
radio_control_str = ''
dic_tmp = sig_dic... | def gen_radio_add(sig_dic) | Adding for HTML radio control. | 3.365309 | 3.081091 | 1.092246 |
'''
editing for HTML radio control.
'''
edit_zuoxiang = '''7
<label for="{0}"><span>
<a class="glyphicon glyphicon-star" style="color: red;font-size: xx-small;">
</a>{1}</span>
'''.format(sig_dic['en'], sig_dic['zh'])
dic_tmp = sig_dic['dic']
for key in dic_tmp.keys():
... | def gen_radio_edit(sig_dic) | editing for HTML radio control. | 4.343089 | 3.973189 | 1.093099 |
'''
for checkbox
'''
html_wuneisheshi = '''<label for="{0}"><span>
<a class="glyphicon glyphicon-star" style="color: red;font-size: xx-small;">
</a>{1}</span>'''.format(sig_dic['en'], sig_dic['zh'])
dic_tmp = sig_dic['dic']
for key in dic_tmp.keys():
tmp_str = '''
<inpu... | def gen_checkbox_add(sig_dic) | for checkbox | 3.771204 | 3.761803 | 1.002499 |
'''
for checkbox
'''
edit_wuneisheshi = '''<label for="{0}"><span>
<a class="glyphicon glyphicon-star" style="color: red;font-size: xx-small;">
</a>{1}</span>
'''.format(sig_dic['en'], sig_dic['zh'])
dic_tmp = sig_dic['dic']
for key in dic_tmp.keys():
tmp_str = '''
... | def gen_checkbox_edit(sig_dic) | for checkbox | 4.50124 | 4.506307 | 0.998875 |
'''
Adding for select control.
:param sig_dic:
html_media_type = {
'en': 'tag_media_type',
'zh': 'Media_type',
'dic': {1: 'Document', 2: 'Data', 3: 'Program'},
'type': 'select',
}
'''
option_str = ''
for key, val in sig_dic['dic'].items():
... | def gen_select_add(sig_dic) | Adding for select control.
:param sig_dic:
html_media_type = {
'en': 'tag_media_type',
'zh': 'Media_type',
'dic': {1: 'Document', 2: 'Data', 3: 'Program'},
'type': 'select',
} | 3.156662 | 1.8807 | 1.678451 |
'''
Query the records from database that recently updated.
:param num: the number that will returned.
:param recent: the number of days recent.
'''
time_that = int(time.time()) - recent * 24 * 3600
return TabPost.select().where(
TabPost.time_update > t... | def query_recent_most(num=8, recent=30) | Query the records from database that recently updated.
:param num: the number that will returned.
:param recent: the number of days recent. | 4.305668 | 2.604944 | 1.652883 |
'''
Delete by uid
'''
q_u1 = TabPostHist.delete().where(TabPostHist.post_id == uid)
q_u1.execute()
q_u2 = TabRel.delete().where(TabRel.post_f_id == uid or TabRel.post_t_id == uid)
q_u2.execute()
q_u3 = TabCollect.delete().where(TabCollect.post_id == uid)
... | def delete(uid) | Delete by uid | 2.283807 | 2.243989 | 1.017744 |
'''
Update the rating for post.
'''
entry = TabPost.update(
rating=rating
).where(TabPost.uid == uid)
entry.execute() | def __update_rating(uid, rating) | Update the rating for post. | 8.809587 | 6.060857 | 1.453522 |
'''
update the kind of post.
'''
entry = TabPost.update(
kind=kind,
).where(TabPost.uid == uid)
entry.execute()
return True | def __update_kind(uid, kind) | update the kind of post. | 9.239129 | 6.567967 | 1.406695 |
'''
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()
).w... | def update_cnt(uid, post_data) | update content. | 5.269962 | 4.799043 | 1.098128 |
'''
Update the order of the posts.
'''
entry = TabPost.update(
order=order
).where(TabPost.uid == uid)
entry.execute() | def update_order(uid, order) | Update the order of the posts. | 8.904836 | 5.589653 | 1.593093 |
'''
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=datetim... | def update(uid, post_data, update_time=False) | update the infor. | 3.095293 | 2.981533 | 1.038155 |
'''
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) | Add or update the post. | 3.847236 | 3.492551 | 1.101555 |
'''
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.... | def create_post(post_uid, post_data) | create the post. | 2.722783 | 2.671168 | 1.019323 |
'''
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... | def query_cat_random(catid, **kwargs) | Get random lists of certain category. | 3.227605 | 2.902864 | 1.111869 |
'''
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_r... | def query_random(**kwargs) | Return the random records of centain kind. | 2.887928 | 2.223306 | 1.298934 |
'''
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 ==... | def query_recent(num=8, **kwargs) | query recent posts. | 1.691724 | 1.648201 | 1.026406 |
'''
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(lim... | def query_all(**kwargs) | query all the posts. | 3.935 | 3.368656 | 1.168122 |
'''
Query keywords, empty.
'''
return TabPost.select().where((TabPost.kind == kind) & (TabPost.keywords == '')) | def query_keywords_empty(kind='1') | Query keywords, empty. | 8.691638 | 5.913408 | 1.469819 |
'''
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') | Query posts recently update. | 4.846052 | 3.498 | 1.385378 |
'''
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') | Query posts, outdate. | 8.605485 | 4.857514 | 1.771582 |
'''
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') | Query most pics. | 5.986784 | 4.911252 | 1.218993 |
'''
Query recent posts of catalog.
'''
if label:
recent_recs = MPost.query_cat_recent_with_label(
cat_id,
label=label,
num=num,
kind=kind,
order=order
)
else:
rece... | def query_cat_recent(cat_id, label=None, num=8, kind='1', order=False) | Query recent posts of catalog. | 2.579736 | 2.30475 | 1.119313 |
'''
Query recent posts of catalog.
'''
return TabPost.select().join(
TabPost2Tag,
on=(TabPost.uid == TabPost2Tag.post_id)
).where(
(TabPost.kind == kind) &
(TabPost2Tag.tag_id == cat_id)
).order_by(
TabPost.time... | def query_by_tag(cat_id, kind='1') | Query recent posts of catalog. | 3.908338 | 3.081942 | 1.268141 |
'''
query_cat_recent_with_label
'''
if order:
sort_criteria = TabPost.order.asc()
else:
sort_criteria = TabPost.time_create.desc()
return TabPost.select().join(
TabPost2Tag,
on=(TabPost.uid == TabPost2Tag.post_id)
)... | def query_cat_recent_with_label(cat_id, label=None, num=8, kind='1', order=False) | query_cat_recent_with_label | 3.454373 | 3.42056 | 1.009885 |
'''
:param cat_id_arr: list of categories. ['0101', '0102']
:param label: the additional label
'''
if label:
return MPost.__query_with_label(
cat_id_arr,
label=label,
num=num,
kind=kind
)
... | def query_total_cat_recent(cat_id_arr, label=None, num=8, kind='1') | :param cat_id_arr: list of categories. ['0101', '0102']
:param label: the additional label | 4.135617 | 2.760714 | 1.498024 |
'''
:param cat_id_arr: list of categories. ['0101', '0102']
'''
return TabPost.select().join(
TabPost2Tag,
on=(TabPost.uid == TabPost2Tag.post_id)
).where(
(TabPost.kind == kind) &
(TabPost2Tag.tag_id << cat_id_arr) & # the "<<" ... | def __query_with_label(cat_id_arr, label=None, num=8, kind='1') | :param cat_id_arr: list of categories. ['0101', '0102'] | 4.814704 | 3.849869 | 1.250615 |
'''
:param cat_id_arr: list of categories. ['0101', '0102']
'''
return TabPost.select().join(
TabPost2Tag,
on=(TabPost.uid == TabPost2Tag.post_id)
).where(
(TabPost.kind == kind) &
(TabPost2Tag.tag_id << cat_id_arr) # the "<<" op... | def query_total_cat_recent_no_label(cat_id_arr, num=8, kind='1') | :param cat_id_arr: list of categories. ['0101', '0102'] | 4.297693 | 3.300534 | 1.30212 |
'''
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') | Query most viewed. | 4.423387 | 3.55074 | 1.245765 |
'''
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['ke... | def update_misc(uid, **kwargs) | update rating, kind, or count | 3.51822 | 2.631382 | 1.337024 |
'''
Update with keywords.
'''
entry = TabPost.update(keywords=inkeywords).where(TabPost.uid == uid)
entry.execute() | def __update_keywords(uid, inkeywords) | Update with keywords. | 11.593722 | 7.493248 | 1.547223 |
'''
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():
... | def get_next_record(in_uid, kind='1') | Get next record by time_create. | 3.754994 | 2.980591 | 1.259815 |
'''
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') | Get All the records. | 5.414061 | 4.141427 | 1.307294 |
'''
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) | Update the json. | 4.760877 | 4.233115 | 1.124675 |
'''
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'
... | def modify_meta(uid, data_dic, extinfo=None) | update meta of the rec. | 2.716053 | 2.642753 | 1.027736 |
'''
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 ... | def modify_init(uid, data_dic) | update when init. | 4.879082 | 4.341226 | 1.123895 |
'''
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()
)
ret... | def query_under_condition(condition, kind='2') | Get All data of certain kind according to the condition | 3.791455 | 3.213892 | 1.179708 |
'''
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') | Get records of certain pager. | 10.100516 | 6.746055 | 1.497248 |
'''
Get the count of certain kind.
'''
recs = TabPost.select().where(TabPost.kind == kind)
return recs.count() | def count_of_certain_kind(kind) | Get the count of certain kind. | 9.988093 | 6.726747 | 1.484833 |
'''
Query pager
'''
return TabPost.select().where(TabPost.kind == kind).order_by(
TabPost.time_create.desc()
).paginate(
current_page_num, CMS_CFG['list_num']
) | def query_pager_by_slug(kind, current_page_num=1) | Query pager | 6.054306 | 5.64895 | 1.071758 |
'''
excel中的数据作为表中的字段,创建表
'''
XLSX_FILE = './database/esheet/20180811.xlsx'
if os.path.exists(XLSX_FILE):
pass
else:
return
fields = []
for sheet_ranges in load_workbook(filename=XLSX_FILE):
for xr in FILTER_COLUMNS:
row1_val = sheet_ranges[xr + "1"... | def gen_xlsx_table() | excel中的数据作为表中的字段,创建表 | 4.360447 | 3.687213 | 1.182586 |
'''
In infor.
'''
self.redirect_kind(postinfo)
if DB_CFG['kind'] == 's':
cat_enum1 = []
else:
ext_catid = postinfo.extinfo['def_cat_uid'] if 'def_cat_uid' in postinfo.extinfo else ''
ext_catid2 = postinfo.extinfo[
'def... | def viewinfo(self, postinfo) | In infor. | 4.812173 | 4.63818 | 1.037513 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.