repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1 value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1 value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
bukun/TorCMS | torcms/model/post_model.py | MPost.query_recent | def query_recent(num=8, **kwargs):
'''
query recent posts.
'''
order_by_create = kwargs.get('order_by_create', False)
kind = kwargs.get('kind', None)
if order_by_create:
if kind:
recent_recs = TabPost.select().where(
(TabPost.kind == kind) & (TabPost.valid == 1)
).order_by(
TabPost.time_create.desc()
).limit(num)
else:
recent_recs = TabPost.select().where(
TabPost.valid == 1
).order_by(
TabPost.time_create.desc()
).limit(num)
else:
if kind:
recent_recs = TabPost.select().where(
(TabPost.kind == kind) & (TabPost.valid == 1)
).order_by(
TabPost.time_update.desc()
).limit(num)
else:
recent_recs = TabPost.select().where(
TabPost.valid == 1
).order_by(
TabPost.time_update.desc()
).limit(num)
return recent_recs | python | def query_recent(num=8, **kwargs):
'''
query recent posts.
'''
order_by_create = kwargs.get('order_by_create', False)
kind = kwargs.get('kind', None)
if order_by_create:
if kind:
recent_recs = TabPost.select().where(
(TabPost.kind == kind) & (TabPost.valid == 1)
).order_by(
TabPost.time_create.desc()
).limit(num)
else:
recent_recs = TabPost.select().where(
TabPost.valid == 1
).order_by(
TabPost.time_create.desc()
).limit(num)
else:
if kind:
recent_recs = TabPost.select().where(
(TabPost.kind == kind) & (TabPost.valid == 1)
).order_by(
TabPost.time_update.desc()
).limit(num)
else:
recent_recs = TabPost.select().where(
TabPost.valid == 1
).order_by(
TabPost.time_update.desc()
).limit(num)
return recent_recs | [
"def",
"query_recent",
"(",
"num",
"=",
"8",
",",
"*",
"*",
"kwargs",
")",
":",
"order_by_create",
"=",
"kwargs",
".",
"get",
"(",
"'order_by_create'",
",",
"False",
")",
"kind",
"=",
"kwargs",
".",
"get",
"(",
"'kind'",
",",
"None",
")",
"if",
"orde... | query recent posts. | [
"query",
"recent",
"posts",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L272-L304 |
bukun/TorCMS | torcms/model/post_model.py | MPost.query_all | def query_all(**kwargs):
'''
query all the posts.
'''
kind = kwargs.get('kind', '1')
limit = kwargs.get('limit', 10)
return TabPost.select().where(
(TabPost.kind == kind) &
(TabPost.valid == 1)
).order_by(
TabPost.time_update.desc()
).limit(limit) | python | def query_all(**kwargs):
'''
query all the posts.
'''
kind = kwargs.get('kind', '1')
limit = kwargs.get('limit', 10)
return TabPost.select().where(
(TabPost.kind == kind) &
(TabPost.valid == 1)
).order_by(
TabPost.time_update.desc()
).limit(limit) | [
"def",
"query_all",
"(",
"*",
"*",
"kwargs",
")",
":",
"kind",
"=",
"kwargs",
".",
"get",
"(",
"'kind'",
",",
"'1'",
")",
"limit",
"=",
"kwargs",
".",
"get",
"(",
"'limit'",
",",
"10",
")",
"return",
"TabPost",
".",
"select",
"(",
")",
".",
"wher... | query all the posts. | [
"query",
"all",
"the",
"posts",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L307-L319 |
bukun/TorCMS | torcms/model/post_model.py | MPost.query_keywords_empty | def query_keywords_empty(kind='1'):
'''
Query keywords, empty.
'''
return TabPost.select().where((TabPost.kind == kind) & (TabPost.keywords == '')) | python | def query_keywords_empty(kind='1'):
'''
Query keywords, empty.
'''
return TabPost.select().where((TabPost.kind == kind) & (TabPost.keywords == '')) | [
"def",
"query_keywords_empty",
"(",
"kind",
"=",
"'1'",
")",
":",
"return",
"TabPost",
".",
"select",
"(",
")",
".",
"where",
"(",
"(",
"TabPost",
".",
"kind",
"==",
"kind",
")",
"&",
"(",
"TabPost",
".",
"keywords",
"==",
"''",
")",
")"
] | Query keywords, empty. | [
"Query",
"keywords",
"empty",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L322-L326 |
bukun/TorCMS | torcms/model/post_model.py | MPost.query_recent_edited | def query_recent_edited(timstamp, kind='1'):
'''
Query posts recently update.
'''
return TabPost.select().where(
(TabPost.kind == kind) &
(TabPost.time_update > timstamp)
).order_by(
TabPost.time_update.desc()
) | python | def query_recent_edited(timstamp, kind='1'):
'''
Query posts recently update.
'''
return TabPost.select().where(
(TabPost.kind == kind) &
(TabPost.time_update > timstamp)
).order_by(
TabPost.time_update.desc()
) | [
"def",
"query_recent_edited",
"(",
"timstamp",
",",
"kind",
"=",
"'1'",
")",
":",
"return",
"TabPost",
".",
"select",
"(",
")",
".",
"where",
"(",
"(",
"TabPost",
".",
"kind",
"==",
"kind",
")",
"&",
"(",
"TabPost",
".",
"time_update",
">",
"timstamp",... | Query posts recently update. | [
"Query",
"posts",
"recently",
"update",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L329-L338 |
bukun/TorCMS | torcms/model/post_model.py | MPost.query_dated | def query_dated(num=8, kind='1'):
'''
Query posts, outdate.
'''
return TabPost.select().where(
TabPost.kind == kind
).order_by(
TabPost.time_update.asc()
).limit(num) | python | def query_dated(num=8, kind='1'):
'''
Query posts, outdate.
'''
return TabPost.select().where(
TabPost.kind == kind
).order_by(
TabPost.time_update.asc()
).limit(num) | [
"def",
"query_dated",
"(",
"num",
"=",
"8",
",",
"kind",
"=",
"'1'",
")",
":",
"return",
"TabPost",
".",
"select",
"(",
")",
".",
"where",
"(",
"TabPost",
".",
"kind",
"==",
"kind",
")",
".",
"order_by",
"(",
"TabPost",
".",
"time_update",
".",
"as... | Query posts, outdate. | [
"Query",
"posts",
"outdate",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L341-L349 |
bukun/TorCMS | torcms/model/post_model.py | MPost.query_most_pic | def query_most_pic(num, kind='1'):
'''
Query most pics.
'''
return TabPost.select().where(
(TabPost.kind == kind) & (TabPost.logo != "")
).order_by(TabPost.view_count.desc()).limit(num) | python | def query_most_pic(num, kind='1'):
'''
Query most pics.
'''
return TabPost.select().where(
(TabPost.kind == kind) & (TabPost.logo != "")
).order_by(TabPost.view_count.desc()).limit(num) | [
"def",
"query_most_pic",
"(",
"num",
",",
"kind",
"=",
"'1'",
")",
":",
"return",
"TabPost",
".",
"select",
"(",
")",
".",
"where",
"(",
"(",
"TabPost",
".",
"kind",
"==",
"kind",
")",
"&",
"(",
"TabPost",
".",
"logo",
"!=",
"\"\"",
")",
")",
"."... | Query most pics. | [
"Query",
"most",
"pics",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L352-L358 |
bukun/TorCMS | torcms/model/post_model.py | MPost.query_cat_recent | def query_cat_recent(cat_id, label=None, num=8, kind='1', order=False):
'''
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:
recent_recs = MPost.query_cat_recent_no_label(
cat_id,
num=num,
kind=kind,
order=order
)
return recent_recs | python | def query_cat_recent(cat_id, label=None, num=8, kind='1', order=False):
'''
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:
recent_recs = MPost.query_cat_recent_no_label(
cat_id,
num=num,
kind=kind,
order=order
)
return recent_recs | [
"def",
"query_cat_recent",
"(",
"cat_id",
",",
"label",
"=",
"None",
",",
"num",
"=",
"8",
",",
"kind",
"=",
"'1'",
",",
"order",
"=",
"False",
")",
":",
"if",
"label",
":",
"recent_recs",
"=",
"MPost",
".",
"query_cat_recent_with_label",
"(",
"cat_id",
... | Query recent posts of catalog. | [
"Query",
"recent",
"posts",
"of",
"catalog",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L361-L381 |
bukun/TorCMS | torcms/model/post_model.py | MPost.query_by_tag | def query_by_tag(cat_id, kind='1'):
'''
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_create.desc()
) | python | def query_by_tag(cat_id, kind='1'):
'''
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_create.desc()
) | [
"def",
"query_by_tag",
"(",
"cat_id",
",",
"kind",
"=",
"'1'",
")",
":",
"return",
"TabPost",
".",
"select",
"(",
")",
".",
"join",
"(",
"TabPost2Tag",
",",
"on",
"=",
"(",
"TabPost",
".",
"uid",
"==",
"TabPost2Tag",
".",
"post_id",
")",
")",
".",
... | Query recent posts of catalog. | [
"Query",
"recent",
"posts",
"of",
"catalog",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L384-L397 |
bukun/TorCMS | torcms/model/post_model.py | MPost.query_cat_recent_with_label | def query_cat_recent_with_label(cat_id, label=None, num=8, kind='1', order=False):
'''
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)
).where(
(TabPost.kind == kind) &
(TabPost2Tag.tag_id == cat_id) &
(TabPost.extinfo['def_tag_arr'].contains(label))
).order_by(
sort_criteria
).limit(num) | python | def query_cat_recent_with_label(cat_id, label=None, num=8, kind='1', order=False):
'''
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)
).where(
(TabPost.kind == kind) &
(TabPost2Tag.tag_id == cat_id) &
(TabPost.extinfo['def_tag_arr'].contains(label))
).order_by(
sort_criteria
).limit(num) | [
"def",
"query_cat_recent_with_label",
"(",
"cat_id",
",",
"label",
"=",
"None",
",",
"num",
"=",
"8",
",",
"kind",
"=",
"'1'",
",",
"order",
"=",
"False",
")",
":",
"if",
"order",
":",
"sort_criteria",
"=",
"TabPost",
".",
"order",
".",
"asc",
"(",
"... | query_cat_recent_with_label | [
"query_cat_recent_with_label"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L400-L418 |
bukun/TorCMS | torcms/model/post_model.py | MPost.query_total_cat_recent | 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
'''
if label:
return MPost.__query_with_label(
cat_id_arr,
label=label,
num=num,
kind=kind
)
return MPost.query_total_cat_recent_no_label(cat_id_arr, num=num, kind=kind) | python | 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
'''
if label:
return MPost.__query_with_label(
cat_id_arr,
label=label,
num=num,
kind=kind
)
return MPost.query_total_cat_recent_no_label(cat_id_arr, num=num, kind=kind) | [
"def",
"query_total_cat_recent",
"(",
"cat_id_arr",
",",
"label",
"=",
"None",
",",
"num",
"=",
"8",
",",
"kind",
"=",
"'1'",
")",
":",
"if",
"label",
":",
"return",
"MPost",
".",
"__query_with_label",
"(",
"cat_id_arr",
",",
"label",
"=",
"label",
",",
... | :param cat_id_arr: list of categories. ['0101', '0102']
:param label: the additional label | [
":",
"param",
"cat_id_arr",
":",
"list",
"of",
"categories",
".",
"[",
"0101",
"0102",
"]",
":",
"param",
"label",
":",
"the",
"additional",
"label"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L441-L453 |
bukun/TorCMS | torcms/model/post_model.py | MPost.__query_with_label | def __query_with_label(cat_id_arr, label=None, num=8, kind='1'):
'''
: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 "<<" operator signifies an "IN" query
(TabPost.extinfo['def_tag_arr'].contains(label))
).order_by(
TabPost.time_create.desc()
).limit(num) | python | def __query_with_label(cat_id_arr, label=None, num=8, kind='1'):
'''
: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 "<<" operator signifies an "IN" query
(TabPost.extinfo['def_tag_arr'].contains(label))
).order_by(
TabPost.time_create.desc()
).limit(num) | [
"def",
"__query_with_label",
"(",
"cat_id_arr",
",",
"label",
"=",
"None",
",",
"num",
"=",
"8",
",",
"kind",
"=",
"'1'",
")",
":",
"return",
"TabPost",
".",
"select",
"(",
")",
".",
"join",
"(",
"TabPost2Tag",
",",
"on",
"=",
"(",
"TabPost",
".",
... | :param cat_id_arr: list of categories. ['0101', '0102'] | [
":",
"param",
"cat_id_arr",
":",
"list",
"of",
"categories",
".",
"[",
"0101",
"0102",
"]"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L456-L469 |
bukun/TorCMS | torcms/model/post_model.py | MPost.query_total_cat_recent_no_label | def query_total_cat_recent_no_label(cat_id_arr, num=8, kind='1'):
'''
: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 "<<" operator signifies an "IN" query
).order_by(
TabPost.time_create.desc()
).limit(num) | python | def query_total_cat_recent_no_label(cat_id_arr, num=8, kind='1'):
'''
: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 "<<" operator signifies an "IN" query
).order_by(
TabPost.time_create.desc()
).limit(num) | [
"def",
"query_total_cat_recent_no_label",
"(",
"cat_id_arr",
",",
"num",
"=",
"8",
",",
"kind",
"=",
"'1'",
")",
":",
"return",
"TabPost",
".",
"select",
"(",
")",
".",
"join",
"(",
"TabPost2Tag",
",",
"on",
"=",
"(",
"TabPost",
".",
"uid",
"==",
"TabP... | :param cat_id_arr: list of categories. ['0101', '0102'] | [
":",
"param",
"cat_id_arr",
":",
"list",
"of",
"categories",
".",
"[",
"0101",
"0102",
"]"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L472-L484 |
bukun/TorCMS | torcms/model/post_model.py | MPost.query_most | def query_most(num=8, kind='1'):
'''
Query most viewed.
'''
return TabPost.select().where(
(TabPost.kind == kind) &
(TabPost.valid == 1)
).order_by(
TabPost.view_count.desc()
).limit(num) | python | def query_most(num=8, kind='1'):
'''
Query most viewed.
'''
return TabPost.select().where(
(TabPost.kind == kind) &
(TabPost.valid == 1)
).order_by(
TabPost.view_count.desc()
).limit(num) | [
"def",
"query_most",
"(",
"num",
"=",
"8",
",",
"kind",
"=",
"'1'",
")",
":",
"return",
"TabPost",
".",
"select",
"(",
")",
".",
"where",
"(",
"(",
"TabPost",
".",
"kind",
"==",
"kind",
")",
"&",
"(",
"TabPost",
".",
"valid",
"==",
"1",
")",
")... | Query most viewed. | [
"Query",
"most",
"viewed",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L487-L496 |
bukun/TorCMS | torcms/model/post_model.py | MPost.update_misc | def update_misc(uid, **kwargs):
'''
update rating, kind, or count
'''
if 'rating' in kwargs:
MPost.__update_rating(uid, kwargs['rating'])
elif 'kind' in kwargs:
MPost.__update_kind(uid, kwargs['kind'])
elif 'keywords' in kwargs:
MPost.__update_keywords(uid, kwargs['keywords'])
elif 'count' in kwargs:
MPost.__update_view_count(uid) | python | def update_misc(uid, **kwargs):
'''
update rating, kind, or count
'''
if 'rating' in kwargs:
MPost.__update_rating(uid, kwargs['rating'])
elif 'kind' in kwargs:
MPost.__update_kind(uid, kwargs['kind'])
elif 'keywords' in kwargs:
MPost.__update_keywords(uid, kwargs['keywords'])
elif 'count' in kwargs:
MPost.__update_view_count(uid) | [
"def",
"update_misc",
"(",
"uid",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"'rating'",
"in",
"kwargs",
":",
"MPost",
".",
"__update_rating",
"(",
"uid",
",",
"kwargs",
"[",
"'rating'",
"]",
")",
"elif",
"'kind'",
"in",
"kwargs",
":",
"MPost",
".",
"_... | update rating, kind, or count | [
"update",
"rating",
"kind",
"or",
"count"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L499-L510 |
bukun/TorCMS | torcms/model/post_model.py | MPost.__update_keywords | def __update_keywords(uid, inkeywords):
'''
Update with keywords.
'''
entry = TabPost.update(keywords=inkeywords).where(TabPost.uid == uid)
entry.execute() | python | def __update_keywords(uid, inkeywords):
'''
Update with keywords.
'''
entry = TabPost.update(keywords=inkeywords).where(TabPost.uid == uid)
entry.execute() | [
"def",
"__update_keywords",
"(",
"uid",
",",
"inkeywords",
")",
":",
"entry",
"=",
"TabPost",
".",
"update",
"(",
"keywords",
"=",
"inkeywords",
")",
".",
"where",
"(",
"TabPost",
".",
"uid",
"==",
"uid",
")",
"entry",
".",
"execute",
"(",
")"
] | Update with keywords. | [
"Update",
"with",
"keywords",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L524-L529 |
bukun/TorCMS | torcms/model/post_model.py | MPost.get_next_record | def get_next_record(in_uid, kind='1'):
'''
Get next record by time_create.
'''
current_rec = MPost.get_by_uid(in_uid)
recs = TabPost.select().where(
(TabPost.kind == kind) &
(TabPost.time_create < current_rec.time_create)
).order_by(TabPost.time_create.desc())
if recs.count():
return recs.get()
return None | python | def get_next_record(in_uid, kind='1'):
'''
Get next record by time_create.
'''
current_rec = MPost.get_by_uid(in_uid)
recs = TabPost.select().where(
(TabPost.kind == kind) &
(TabPost.time_create < current_rec.time_create)
).order_by(TabPost.time_create.desc())
if recs.count():
return recs.get()
return None | [
"def",
"get_next_record",
"(",
"in_uid",
",",
"kind",
"=",
"'1'",
")",
":",
"current_rec",
"=",
"MPost",
".",
"get_by_uid",
"(",
"in_uid",
")",
"recs",
"=",
"TabPost",
".",
"select",
"(",
")",
".",
"where",
"(",
"(",
"TabPost",
".",
"kind",
"==",
"ki... | Get next record by time_create. | [
"Get",
"next",
"record",
"by",
"time_create",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L532-L543 |
bukun/TorCMS | torcms/model/post_model.py | MPost.get_all | def get_all(kind='2'):
'''
Get All the records.
'''
return TabPost.select().where(
(TabPost.kind == kind) &
(TabPost.valid == 1)
).order_by(
TabPost.time_update.desc()
) | python | def get_all(kind='2'):
'''
Get All the records.
'''
return TabPost.select().where(
(TabPost.kind == kind) &
(TabPost.valid == 1)
).order_by(
TabPost.time_update.desc()
) | [
"def",
"get_all",
"(",
"kind",
"=",
"'2'",
")",
":",
"return",
"TabPost",
".",
"select",
"(",
")",
".",
"where",
"(",
"(",
"TabPost",
".",
"kind",
"==",
"kind",
")",
"&",
"(",
"TabPost",
".",
"valid",
"==",
"1",
")",
")",
".",
"order_by",
"(",
... | Get All the records. | [
"Get",
"All",
"the",
"records",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L560-L569 |
bukun/TorCMS | torcms/model/post_model.py | MPost.update_jsonb | def update_jsonb(uid, extinfo):
'''
Update the json.
'''
cur_extinfo = MPost.get_by_uid(uid).extinfo
for key in extinfo:
cur_extinfo[key] = extinfo[key]
entry = TabPost.update(
extinfo=cur_extinfo,
).where(TabPost.uid == uid)
entry.execute()
return uid | python | def update_jsonb(uid, extinfo):
'''
Update the json.
'''
cur_extinfo = MPost.get_by_uid(uid).extinfo
for key in extinfo:
cur_extinfo[key] = extinfo[key]
entry = TabPost.update(
extinfo=cur_extinfo,
).where(TabPost.uid == uid)
entry.execute()
return uid | [
"def",
"update_jsonb",
"(",
"uid",
",",
"extinfo",
")",
":",
"cur_extinfo",
"=",
"MPost",
".",
"get_by_uid",
"(",
"uid",
")",
".",
"extinfo",
"for",
"key",
"in",
"extinfo",
":",
"cur_extinfo",
"[",
"key",
"]",
"=",
"extinfo",
"[",
"key",
"]",
"entry",
... | Update the json. | [
"Update",
"the",
"json",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L572-L583 |
bukun/TorCMS | torcms/model/post_model.py | MPost.modify_meta | def modify_meta(uid, data_dic, extinfo=None):
'''
update meta of the rec.
'''
if extinfo is None:
extinfo = {}
title = data_dic['title'].strip()
if len(title) < 2:
return False
cur_info = MPost.get_by_uid(uid)
if cur_info:
# ToDo: should not do this. Not for 's'
if DB_CFG['kind'] == 's':
entry = TabPost.update(
title=title,
user_name=data_dic['user_name'],
keywords='',
time_update=tools.timestamp(),
date=datetime.now(),
cnt_md=data_dic['cnt_md'],
memo=data_dic['memo'] if 'memo' in data_dic else '',
logo=data_dic['logo'],
order=data_dic['order'],
cnt_html=tools.markdown2html(data_dic['cnt_md']),
valid=data_dic['valid']
).where(TabPost.uid == uid)
entry.execute()
else:
cur_extinfo = cur_info.extinfo
# Update the extinfo, Not replace
for key in extinfo:
cur_extinfo[key] = extinfo[key]
entry = TabPost.update(
title=title,
user_name=data_dic['user_name'],
keywords='',
time_update=tools.timestamp(),
date=datetime.now(),
cnt_md=data_dic['cnt_md'],
memo=data_dic['memo'] if 'memo' in data_dic else '',
logo=data_dic['logo'],
order=data_dic['order'] if 'order' in data_dic else '',
cnt_html=tools.markdown2html(data_dic['cnt_md']),
extinfo=cur_extinfo,
valid=data_dic['valid']
).where(TabPost.uid == uid)
entry.execute()
else:
return MPost.add_meta(uid, data_dic, extinfo)
return uid | python | def modify_meta(uid, data_dic, extinfo=None):
'''
update meta of the rec.
'''
if extinfo is None:
extinfo = {}
title = data_dic['title'].strip()
if len(title) < 2:
return False
cur_info = MPost.get_by_uid(uid)
if cur_info:
# ToDo: should not do this. Not for 's'
if DB_CFG['kind'] == 's':
entry = TabPost.update(
title=title,
user_name=data_dic['user_name'],
keywords='',
time_update=tools.timestamp(),
date=datetime.now(),
cnt_md=data_dic['cnt_md'],
memo=data_dic['memo'] if 'memo' in data_dic else '',
logo=data_dic['logo'],
order=data_dic['order'],
cnt_html=tools.markdown2html(data_dic['cnt_md']),
valid=data_dic['valid']
).where(TabPost.uid == uid)
entry.execute()
else:
cur_extinfo = cur_info.extinfo
# Update the extinfo, Not replace
for key in extinfo:
cur_extinfo[key] = extinfo[key]
entry = TabPost.update(
title=title,
user_name=data_dic['user_name'],
keywords='',
time_update=tools.timestamp(),
date=datetime.now(),
cnt_md=data_dic['cnt_md'],
memo=data_dic['memo'] if 'memo' in data_dic else '',
logo=data_dic['logo'],
order=data_dic['order'] if 'order' in data_dic else '',
cnt_html=tools.markdown2html(data_dic['cnt_md']),
extinfo=cur_extinfo,
valid=data_dic['valid']
).where(TabPost.uid == uid)
entry.execute()
else:
return MPost.add_meta(uid, data_dic, extinfo)
return uid | [
"def",
"modify_meta",
"(",
"uid",
",",
"data_dic",
",",
"extinfo",
"=",
"None",
")",
":",
"if",
"extinfo",
"is",
"None",
":",
"extinfo",
"=",
"{",
"}",
"title",
"=",
"data_dic",
"[",
"'title'",
"]",
".",
"strip",
"(",
")",
"if",
"len",
"(",
"title"... | update meta of the rec. | [
"update",
"meta",
"of",
"the",
"rec",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L586-L637 |
bukun/TorCMS | torcms/model/post_model.py | MPost.modify_init | def modify_init(uid, data_dic):
'''
update when init.
'''
postinfo = MPost.get_by_uid(uid)
entry = TabPost.update(
time_update=tools.timestamp(),
date=datetime.now(),
kind=data_dic['kind'] if 'kind' in data_dic else postinfo.kind,
keywords=data_dic['keywords'] if 'keywords' in data_dic else postinfo.keywords,
).where(TabPost.uid == uid)
entry.execute()
return uid | python | def modify_init(uid, data_dic):
'''
update when init.
'''
postinfo = MPost.get_by_uid(uid)
entry = TabPost.update(
time_update=tools.timestamp(),
date=datetime.now(),
kind=data_dic['kind'] if 'kind' in data_dic else postinfo.kind,
keywords=data_dic['keywords'] if 'keywords' in data_dic else postinfo.keywords,
).where(TabPost.uid == uid)
entry.execute()
return uid | [
"def",
"modify_init",
"(",
"uid",
",",
"data_dic",
")",
":",
"postinfo",
"=",
"MPost",
".",
"get_by_uid",
"(",
"uid",
")",
"entry",
"=",
"TabPost",
".",
"update",
"(",
"time_update",
"=",
"tools",
".",
"timestamp",
"(",
")",
",",
"date",
"=",
"datetime... | update when init. | [
"update",
"when",
"init",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L640-L652 |
bukun/TorCMS | torcms/model/post_model.py | MPost.query_under_condition | def query_under_condition(condition, kind='2'):
'''
Get All data of certain kind according to the condition
'''
if DB_CFG['kind'] == 's':
return TabPost.select().where(
(TabPost.kind == kind) & (TabPost.valid == 1)
).order_by(
TabPost.time_update.desc()
)
return TabPost.select().where(
(TabPost.kind == kind) &
(TabPost.valid == 1) &
TabPost.extinfo.contains(condition)
).order_by(TabPost.time_update.desc()) | python | def query_under_condition(condition, kind='2'):
'''
Get All data of certain kind according to the condition
'''
if DB_CFG['kind'] == 's':
return TabPost.select().where(
(TabPost.kind == kind) & (TabPost.valid == 1)
).order_by(
TabPost.time_update.desc()
)
return TabPost.select().where(
(TabPost.kind == kind) &
(TabPost.valid == 1) &
TabPost.extinfo.contains(condition)
).order_by(TabPost.time_update.desc()) | [
"def",
"query_under_condition",
"(",
"condition",
",",
"kind",
"=",
"'2'",
")",
":",
"if",
"DB_CFG",
"[",
"'kind'",
"]",
"==",
"'s'",
":",
"return",
"TabPost",
".",
"select",
"(",
")",
".",
"where",
"(",
"(",
"TabPost",
".",
"kind",
"==",
"kind",
")"... | Get All data of certain kind according to the condition | [
"Get",
"All",
"data",
"of",
"certain",
"kind",
"according",
"to",
"the",
"condition"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L771-L786 |
bukun/TorCMS | torcms/model/post_model.py | MPost.query_list_pager | def query_list_pager(con, idx, kind='2'):
'''
Get records of certain pager.
'''
all_list = MPost.query_under_condition(con, kind=kind)
return all_list[(idx - 1) * CMS_CFG['list_num']: idx * CMS_CFG['list_num']] | python | def query_list_pager(con, idx, kind='2'):
'''
Get records of certain pager.
'''
all_list = MPost.query_under_condition(con, kind=kind)
return all_list[(idx - 1) * CMS_CFG['list_num']: idx * CMS_CFG['list_num']] | [
"def",
"query_list_pager",
"(",
"con",
",",
"idx",
",",
"kind",
"=",
"'2'",
")",
":",
"all_list",
"=",
"MPost",
".",
"query_under_condition",
"(",
"con",
",",
"kind",
"=",
"kind",
")",
"return",
"all_list",
"[",
"(",
"idx",
"-",
"1",
")",
"*",
"CMS_C... | Get records of certain pager. | [
"Get",
"records",
"of",
"certain",
"pager",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L830-L835 |
bukun/TorCMS | torcms/model/post_model.py | MPost.count_of_certain_kind | def count_of_certain_kind(kind):
'''
Get the count of certain kind.
'''
recs = TabPost.select().where(TabPost.kind == kind)
return recs.count() | python | def count_of_certain_kind(kind):
'''
Get the count of certain kind.
'''
recs = TabPost.select().where(TabPost.kind == kind)
return recs.count() | [
"def",
"count_of_certain_kind",
"(",
"kind",
")",
":",
"recs",
"=",
"TabPost",
".",
"select",
"(",
")",
".",
"where",
"(",
"TabPost",
".",
"kind",
"==",
"kind",
")",
"return",
"recs",
".",
"count",
"(",
")"
] | Get the count of certain kind. | [
"Get",
"the",
"count",
"of",
"certain",
"kind",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L838-L845 |
bukun/TorCMS | torcms/model/post_model.py | MPost.query_pager_by_slug | def query_pager_by_slug(kind, current_page_num=1):
'''
Query pager
'''
return TabPost.select().where(TabPost.kind == kind).order_by(
TabPost.time_create.desc()
).paginate(
current_page_num, CMS_CFG['list_num']
) | python | def query_pager_by_slug(kind, current_page_num=1):
'''
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",
")",
":",
"return",
"TabPost",
".",
"select",
"(",
")",
".",
"where",
"(",
"TabPost",
".",
"kind",
"==",
"kind",
")",
".",
"order_by",
"(",
"TabPost",
".",
"time_create",
".",
... | Query pager | [
"Query",
"pager"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L855-L863 |
bukun/TorCMS | ext_script/script_gen_xlsx.py | gen_xlsx_table | def gen_xlsx_table():
'''
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"].value
row2_val = sheet_ranges[xr + "2"].value
row3_val = sheet_ranges[xr + "3"].value
row4_val = sheet_ranges[xr + "4"].value
if row1_val and row1_val.strip() != '':
desc = {
'slug': row1_val,
'name': row2_val,
'type': row3_val,
'display_mode': row4_val
}
fields.append(desc)
create_tab(fields) | python | def gen_xlsx_table():
'''
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"].value
row2_val = sheet_ranges[xr + "2"].value
row3_val = sheet_ranges[xr + "3"].value
row4_val = sheet_ranges[xr + "4"].value
if row1_val and row1_val.strip() != '':
desc = {
'slug': row1_val,
'name': row2_val,
'type': row3_val,
'display_mode': row4_val
}
fields.append(desc)
create_tab(fields) | [
"def",
"gen_xlsx_table",
"(",
")",
":",
"XLSX_FILE",
"=",
"'./database/esheet/20180811.xlsx'",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"XLSX_FILE",
")",
":",
"pass",
"else",
":",
"return",
"fields",
"=",
"[",
"]",
"for",
"sheet_ranges",
"in",
"load_work... | excel中的数据作为表中的字段,创建表 | [
"excel中的数据作为表中的字段,创建表"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/ext_script/script_gen_xlsx.py#L10-L40 |
bukun/TorCMS | torcms/handlers/leaf_handler.py | LeafHandler.viewinfo | def viewinfo(self, postinfo):
'''
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_cat_uid'] if 'def_cat_uid' in postinfo.extinfo else None
cat_enum1 = MCategory.get_qian2(ext_catid2[:2]) if ext_catid else []
catinfo = None
p_catinfo = None
post2catinfo = MPost2Catalog.get_first_category(postinfo.uid)
catalog_infors = None
if post2catinfo:
catinfo = MCategory.get_by_uid(post2catinfo.tag_id)
if catinfo:
p_catinfo = MCategory.get_by_uid(catinfo.pid)
catalog_infors = MPost2Catalog.query_pager_by_slug(catinfo.slug,
current_page_num=1,
order=True)
kwd = self._the_view_kwd(postinfo)
MPost.update_misc(postinfo.uid, count=True)
if self.get_current_user():
MUsage.add_or_update(self.userinfo.uid, postinfo.uid, postinfo.kind)
tmpl = 'post_{0}/leaf_view.html'.format(self.kind)
logger.info('The Info Template: {0}'.format(tmpl))
self.render(tmpl,
kwd=dict(kwd, **self.ext_view_kwd(postinfo)),
postinfo=postinfo,
userinfo=self.userinfo,
catinfo=catinfo,
pcatinfo=p_catinfo,
ad_switch=random.randint(1, 18),
tag_info=MPost2Label.get_by_uid(postinfo.uid),
catalog_infos=catalog_infors,
cat_enum=cat_enum1) | python | def viewinfo(self, postinfo):
'''
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_cat_uid'] if 'def_cat_uid' in postinfo.extinfo else None
cat_enum1 = MCategory.get_qian2(ext_catid2[:2]) if ext_catid else []
catinfo = None
p_catinfo = None
post2catinfo = MPost2Catalog.get_first_category(postinfo.uid)
catalog_infors = None
if post2catinfo:
catinfo = MCategory.get_by_uid(post2catinfo.tag_id)
if catinfo:
p_catinfo = MCategory.get_by_uid(catinfo.pid)
catalog_infors = MPost2Catalog.query_pager_by_slug(catinfo.slug,
current_page_num=1,
order=True)
kwd = self._the_view_kwd(postinfo)
MPost.update_misc(postinfo.uid, count=True)
if self.get_current_user():
MUsage.add_or_update(self.userinfo.uid, postinfo.uid, postinfo.kind)
tmpl = 'post_{0}/leaf_view.html'.format(self.kind)
logger.info('The Info Template: {0}'.format(tmpl))
self.render(tmpl,
kwd=dict(kwd, **self.ext_view_kwd(postinfo)),
postinfo=postinfo,
userinfo=self.userinfo,
catinfo=catinfo,
pcatinfo=p_catinfo,
ad_switch=random.randint(1, 18),
tag_info=MPost2Label.get_by_uid(postinfo.uid),
catalog_infos=catalog_infors,
cat_enum=cat_enum1) | [
"def",
"viewinfo",
"(",
"self",
",",
"postinfo",
")",
":",
"self",
".",
"redirect_kind",
"(",
"postinfo",
")",
"if",
"DB_CFG",
"[",
"'kind'",
"]",
"==",
"'s'",
":",
"cat_enum1",
"=",
"[",
"]",
"else",
":",
"ext_catid",
"=",
"postinfo",
".",
"extinfo",
... | In infor. | [
"In",
"infor",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/leaf_handler.py#L69-L117 |
bukun/TorCMS | torcms/script/autocrud/gen_html_file.py | __get_view_tmpl | def __get_view_tmpl(tag_key):
'''
根据分类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 | python | def __get_view_tmpl(tag_key):
'''
根据分类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",
")",
":",
"the_view_file_4",
"=",
"'./templates/tmpl_{0}/tpl_view_{1}.html'",
".",
"format",
"(",
"KIND_DICS",
"[",
"'kind_'",
"+",
"tag_key",
".",
"split",
"(",
"'_'",
")",
"[",
"-",
"1",
"]",
"]",
",",
"tag_key",
"... | 根据分类uid的4位编码来找模板。如果4位的存在,则使用4位的;不然找其父类;再不然则使用通用模板
只有View需要,edit, list使用通用模板
:return String. | [
"根据分类uid的4位编码来找模板。如果4位的存在,则使用4位的;不然找其父类;再不然则使用通用模板",
"只有View需要,edit",
"list使用通用模板",
":",
"return",
"String",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/script/autocrud/gen_html_file.py#L29-L49 |
bukun/TorCMS | torcms/script/autocrud/gen_html_file.py | __gen_select_filter | def __gen_select_filter(bl_str):
'''
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 | python | def __gen_select_filter(bl_str):
'''
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",
")",
":",
"bianliang",
"=",
"HTML_DICS",
"[",
"bl_str",
"]",
"# bianliang = eval('html_vars.' + bl_str)",
"html_out",
"=",
"'''<li class=\"list-group-item\">\n <div class=\"row\"><div class=\"col-sm-3\">{0}</div><div class=\"col-sm-9\">\n... | Convert to html.
:return String. | [
"Convert",
"to",
"html",
".",
":",
"return",
"String",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/script/autocrud/gen_html_file.py#L52-L71 |
bukun/TorCMS | torcms/script/autocrud/gen_html_file.py | generate_html_files | def generate_html_files(*args):
'''
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) | python | def generate_html_files(*args):
'''
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",
")",
":",
"_",
"=",
"args",
"for",
"tag_key",
",",
"tag_list",
"in",
"SWITCH_DICS",
".",
"items",
"(",
")",
":",
"if",
"tag_key",
".",
"startswith",
"(",
"'dic_'",
")",
"and",
"(",
"not",
"tag_key",
".",
... | Generate the templates for adding, editing, viewing.
:return: None | [
"Generate",
"the",
"templates",
"for",
"adding",
"editing",
"viewing",
".",
":",
"return",
":",
"None"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/script/autocrud/gen_html_file.py#L74-L87 |
bukun/TorCMS | torcms/script/autocrud/gen_html_file.py | __write_edit_tmpl | 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
'''
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) | python | 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
'''
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",
")",
":",
"edit_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"OUT_DIR",
",",
"'edit'",
",",
"'edit_'",
"+",
"tag_key",
".",
"split",
"(",
"'_'",
")",
"[",
"1",
"]",
"+",
"'.html'",
")",... | Generate the HTML file for editing.
:param tag_key: key of the tags.
:param tag_list: list of the tags.
:return: None | [
"Generate",
"the",
"HTML",
"file",
"for",
"editing",
".",
":",
"param",
"tag_key",
":",
"key",
"of",
"the",
"tags",
".",
":",
"param",
"tag_list",
":",
"list",
"of",
"the",
"tags",
".",
":",
"return",
":",
"None"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/script/autocrud/gen_html_file.py#L90-L130 |
bukun/TorCMS | torcms/script/autocrud/gen_html_file.py | __write_view_tmpl | 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
'''
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) | python | 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
'''
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",
")",
":",
"view_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"OUT_DIR",
",",
"'view'",
",",
"'view_'",
"+",
"tag_key",
".",
"split",
"(",
"'_'",
")",
"[",
"1",
"]",
"+",
"'.html'",
")",... | Generate the HTML file for viewing.
:param tag_key: key of the tags.
:param tag_list: list of the tags.
:return: None | [
"Generate",
"the",
"HTML",
"file",
"for",
"viewing",
".",
":",
"param",
"tag_key",
":",
"key",
"of",
"the",
"tags",
".",
":",
"param",
"tag_list",
":",
"list",
"of",
"the",
"tags",
".",
":",
"return",
":",
"None"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/script/autocrud/gen_html_file.py#L133-L180 |
bukun/TorCMS | torcms/script/autocrud/gen_html_file.py | __write_add_tmpl | 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
'''
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) | python | 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
'''
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",
")",
":",
"add_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"OUT_DIR",
",",
"'add'",
",",
"'add_'",
"+",
"tag_key",
".",
"split",
"(",
"'_'",
")",
"[",
"1",
"]",
"+",
"'.html'",
")",
"... | Generate the HTML file for adding.
:param tag_key: key of the tags.
:param tag_list: list of the tags.
:return: None | [
"Generate",
"the",
"HTML",
"file",
"for",
"adding",
".",
":",
"param",
"tag_key",
":",
"key",
"of",
"the",
"tags",
".",
":",
"param",
"tag_list",
":",
"list",
"of",
"the",
"tags",
".",
":",
"return",
":",
"None"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/script/autocrud/gen_html_file.py#L183-L224 |
bukun/TorCMS | torcms/script/autocrud/gen_html_file.py | __write_filter_tmpl | def __write_filter_tmpl(html_tpl):
'''
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) | python | def __write_filter_tmpl(html_tpl):
'''
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",
")",
":",
"out_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"getcwd",
"(",
")",
",",
"CRUD_PATH",
",",
"'list'",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"out_dir",
")",
":",
"pa... | doing for directory. | [
"doing",
"for",
"directory",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/script/autocrud/gen_html_file.py#L227-L266 |
bukun/TorCMS | torcms/script/autocrud/gen_html_file.py | __write_list_tmpl | def __write_list_tmpl(html_tpl):
'''
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) | python | def __write_list_tmpl(html_tpl):
'''
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",
")",
":",
"out_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"getcwd",
"(",
")",
",",
"CRUD_PATH",
",",
"'infolist'",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"out_dir",
")",
":",
"... | doing for directory. | [
"doing",
"for",
"directory",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/script/autocrud/gen_html_file.py#L269-L312 |
bukun/TorCMS | torcms/handlers/user_info_list_handler.py | UserListHandler.list_app | def list_app(self):
'''
List the apps.
'''
kwd = {
'pager': '',
'title': ''
}
self.render('user/info_list/list_app.html', kwd=kwd,
userinfo=self.userinfo) | python | def list_app(self):
'''
List the apps.
'''
kwd = {
'pager': '',
'title': ''
}
self.render('user/info_list/list_app.html', kwd=kwd,
userinfo=self.userinfo) | [
"def",
"list_app",
"(",
"self",
")",
":",
"kwd",
"=",
"{",
"'pager'",
":",
"''",
",",
"'title'",
":",
"''",
"}",
"self",
".",
"render",
"(",
"'user/info_list/list_app.html'",
",",
"kwd",
"=",
"kwd",
",",
"userinfo",
"=",
"self",
".",
"userinfo",
")"
] | List the apps. | [
"List",
"the",
"apps",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/user_info_list_handler.py#L36-L45 |
bukun/TorCMS | torcms/handlers/user_info_list_handler.py | UserListHandler.user_most | def user_most(self):
'''
User most used.
'''
kwd = {
'pager': '',
'title': '',
}
self.render('user/info_list/user_most.html',
kwd=kwd,
user_name=self.get_current_user(),
userinfo=self.userinfo) | python | def user_most(self):
'''
User most used.
'''
kwd = {
'pager': '',
'title': '',
}
self.render('user/info_list/user_most.html',
kwd=kwd,
user_name=self.get_current_user(),
userinfo=self.userinfo) | [
"def",
"user_most",
"(",
"self",
")",
":",
"kwd",
"=",
"{",
"'pager'",
":",
"''",
",",
"'title'",
":",
"''",
",",
"}",
"self",
".",
"render",
"(",
"'user/info_list/user_most.html'",
",",
"kwd",
"=",
"kwd",
",",
"user_name",
"=",
"self",
".",
"get_curre... | User most used. | [
"User",
"most",
"used",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/user_info_list_handler.py#L48-L59 |
bukun/TorCMS | torcms/handlers/user_info_list_handler.py | UserListHandler.user_recent | def user_recent(self):
'''
User used recently.
'''
kwd = {
'pager': '',
'title': ''
}
self.render('user/info_list/user_recent.html',
kwd=kwd,
user_name=self.get_current_user(),
userinfo=self.userinfo) | python | def user_recent(self):
'''
User used recently.
'''
kwd = {
'pager': '',
'title': ''
}
self.render('user/info_list/user_recent.html',
kwd=kwd,
user_name=self.get_current_user(),
userinfo=self.userinfo) | [
"def",
"user_recent",
"(",
"self",
")",
":",
"kwd",
"=",
"{",
"'pager'",
":",
"''",
",",
"'title'",
":",
"''",
"}",
"self",
".",
"render",
"(",
"'user/info_list/user_recent.html'",
",",
"kwd",
"=",
"kwd",
",",
"user_name",
"=",
"self",
".",
"get_current_... | User used recently. | [
"User",
"used",
"recently",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/user_info_list_handler.py#L62-L73 |
bukun/TorCMS | torcms/handlers/user_info_list_handler.py | UserListHandler.to_find | def to_find(self):
'''
Todo: the name should be changed.
list the infors.
'''
kwd = {'pager': ''}
self.render('user/info_list/most.html',
topmenu='',
userinfo=self.userinfo,
kwd=kwd) | python | def to_find(self):
'''
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",
")",
":",
"kwd",
"=",
"{",
"'pager'",
":",
"''",
"}",
"self",
".",
"render",
"(",
"'user/info_list/most.html'",
",",
"topmenu",
"=",
"''",
",",
"userinfo",
"=",
"self",
".",
"userinfo",
",",
"kwd",
"=",
"kwd",
")"
] | Todo: the name should be changed.
list the infors. | [
"Todo",
":",
"the",
"name",
"should",
"be",
"changed",
".",
"list",
"the",
"infors",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/user_info_list_handler.py#L75-L84 |
bukun/TorCMS | torcms/handlers/user_info_list_handler.py | UserListHandler.list_recent | def list_recent(self):
'''
List the recent.
'''
recs = MPost.query_recent(20)
kwd = {
'pager': '',
'title': '',
}
self.render('user/info_list/list.html',
kwd=kwd,
rand_eqs=MPost.query_random(),
recs=recs,
userinfo=self.userinfo) | python | def list_recent(self):
'''
List the recent.
'''
recs = MPost.query_recent(20)
kwd = {
'pager': '',
'title': '',
}
self.render('user/info_list/list.html',
kwd=kwd,
rand_eqs=MPost.query_random(),
recs=recs,
userinfo=self.userinfo) | [
"def",
"list_recent",
"(",
"self",
")",
":",
"recs",
"=",
"MPost",
".",
"query_recent",
"(",
"20",
")",
"kwd",
"=",
"{",
"'pager'",
":",
"''",
",",
"'title'",
":",
"''",
",",
"}",
"self",
".",
"render",
"(",
"'user/info_list/list.html'",
",",
"kwd",
... | List the recent. | [
"List",
"the",
"recent",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/user_info_list_handler.py#L86-L99 |
bukun/TorCMS | torcms/handlers/user_info_list_handler.py | UserListHandler.find | def find(self):
'''
find the infors.
'''
keyword = self.get_argument('keyword').strip()
kwd = {
'pager': '',
'title': 'Searching Result',
}
self.render('user/info_list/find_list.html',
userinfo=self.userinfo,
kwd=kwd,
recs=MPost.get_by_keyword(keyword)) | python | def find(self):
'''
find the infors.
'''
keyword = self.get_argument('keyword').strip()
kwd = {
'pager': '',
'title': 'Searching Result',
}
self.render('user/info_list/find_list.html',
userinfo=self.userinfo,
kwd=kwd,
recs=MPost.get_by_keyword(keyword)) | [
"def",
"find",
"(",
"self",
")",
":",
"keyword",
"=",
"self",
".",
"get_argument",
"(",
"'keyword'",
")",
".",
"strip",
"(",
")",
"kwd",
"=",
"{",
"'pager'",
":",
"''",
",",
"'title'",
":",
"'Searching Result'",
",",
"}",
"self",
".",
"render",
"(",
... | find the infors. | [
"find",
"the",
"infors",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/user_info_list_handler.py#L101-L114 |
bukun/TorCMS | torcms/handlers/relation_handler.py | RelHandler.add_relation | def add_relation(self, url_arr):
'''
Add relationship.
'''
if MPost.get_by_uid(url_arr[1]):
pass
else:
return False
last_post_id = self.get_secure_cookie('last_post_uid')
if last_post_id:
last_post_id = last_post_id.decode('utf-8')
last_app_id = self.get_secure_cookie('use_app_uid')
if last_app_id:
last_app_id = last_app_id.decode('utf-8')
if url_arr[0] == 'info':
if last_post_id:
MRelation.add_relation(last_post_id, url_arr[1], 2)
MRelation.add_relation(url_arr[1], last_post_id, 1)
if url_arr[0] == 'post':
if last_app_id:
MRelation.add_relation(last_app_id, url_arr[1], 2)
MRelation.add_relation(url_arr[1], last_app_id, 1) | python | def add_relation(self, url_arr):
'''
Add relationship.
'''
if MPost.get_by_uid(url_arr[1]):
pass
else:
return False
last_post_id = self.get_secure_cookie('last_post_uid')
if last_post_id:
last_post_id = last_post_id.decode('utf-8')
last_app_id = self.get_secure_cookie('use_app_uid')
if last_app_id:
last_app_id = last_app_id.decode('utf-8')
if url_arr[0] == 'info':
if last_post_id:
MRelation.add_relation(last_post_id, url_arr[1], 2)
MRelation.add_relation(url_arr[1], last_post_id, 1)
if url_arr[0] == 'post':
if last_app_id:
MRelation.add_relation(last_app_id, url_arr[1], 2)
MRelation.add_relation(url_arr[1], last_app_id, 1) | [
"def",
"add_relation",
"(",
"self",
",",
"url_arr",
")",
":",
"if",
"MPost",
".",
"get_by_uid",
"(",
"url_arr",
"[",
"1",
"]",
")",
":",
"pass",
"else",
":",
"return",
"False",
"last_post_id",
"=",
"self",
".",
"get_secure_cookie",
"(",
"'last_post_uid'",
... | Add relationship. | [
"Add",
"relationship",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/relation_handler.py#L25-L50 |
bukun/TorCMS | torcms/handlers/reply_handler.py | ReplyHandler.list | def list(self, cur_p=''):
'''
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
) | python | def list(self, cur_p=''):
'''
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",
"=",
"''",
")",
":",
"if",
"cur_p",
"==",
"''",
":",
"current_page_number",
"=",
"1",
"else",
":",
"current_page_number",
"=",
"int",
"(",
"cur_p",
")",
"current_page_number",
"=",
"1",
"if",
"current_page_number",... | List the replies. | [
"List",
"the",
"replies",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/reply_handler.py#L43-L64 |
bukun/TorCMS | torcms/handlers/reply_handler.py | ReplyHandler.get_by_id | def get_by_id(self, reply_id):
'''
Get the reply by id.
'''
reply = MReply.get_by_uid(reply_id)
logger.info('get_reply: {0}'.format(reply_id))
self.render('misc/reply/show_reply.html',
reply=reply,
username=reply.user_name,
date=reply.date,
vote=reply.vote,
uid=reply.uid,
userinfo=self.userinfo,
kwd={}) | python | def get_by_id(self, reply_id):
'''
Get the reply by id.
'''
reply = MReply.get_by_uid(reply_id)
logger.info('get_reply: {0}'.format(reply_id))
self.render('misc/reply/show_reply.html',
reply=reply,
username=reply.user_name,
date=reply.date,
vote=reply.vote,
uid=reply.uid,
userinfo=self.userinfo,
kwd={}) | [
"def",
"get_by_id",
"(",
"self",
",",
"reply_id",
")",
":",
"reply",
"=",
"MReply",
".",
"get_by_uid",
"(",
"reply_id",
")",
"logger",
".",
"info",
"(",
"'get_reply: {0}'",
".",
"format",
"(",
"reply_id",
")",
")",
"self",
".",
"render",
"(",
"'misc/repl... | Get the reply by id. | [
"Get",
"the",
"reply",
"by",
"id",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/reply_handler.py#L66-L80 |
bukun/TorCMS | torcms/handlers/reply_handler.py | ReplyHandler.add | def add(self, post_id):
'''
Adding reply to a post.
'''
post_data = self.get_post_data()
post_data['user_name'] = self.userinfo.user_name
post_data['user_id'] = self.userinfo.uid
post_data['post_id'] = post_id
replyid = MReply.create_reply(post_data)
if replyid:
out_dic = {'pinglun': post_data['cnt_reply'],
'uid': replyid}
logger.info('add reply result dic: {0}'.format(out_dic))
return json.dump(out_dic, self) | python | def add(self, post_id):
'''
Adding reply to a post.
'''
post_data = self.get_post_data()
post_data['user_name'] = self.userinfo.user_name
post_data['user_id'] = self.userinfo.uid
post_data['post_id'] = post_id
replyid = MReply.create_reply(post_data)
if replyid:
out_dic = {'pinglun': post_data['cnt_reply'],
'uid': replyid}
logger.info('add reply result dic: {0}'.format(out_dic))
return json.dump(out_dic, self) | [
"def",
"add",
"(",
"self",
",",
"post_id",
")",
":",
"post_data",
"=",
"self",
".",
"get_post_data",
"(",
")",
"post_data",
"[",
"'user_name'",
"]",
"=",
"self",
".",
"userinfo",
".",
"user_name",
"post_data",
"[",
"'user_id'",
"]",
"=",
"self",
".",
"... | Adding reply to a post. | [
"Adding",
"reply",
"to",
"a",
"post",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/reply_handler.py#L82-L96 |
bukun/TorCMS | torcms/handlers/reply_handler.py | ReplyHandler.zan | def zan(self, id_reply):
'''
先在外部表中更新,然后更新内部表字段的值。
有冗余,但是查看的时候避免了联合查询
'''
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) | python | def zan(self, id_reply):
'''
先在外部表中更新,然后更新内部表字段的值。
有冗余,但是查看的时候避免了联合查询
'''
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",
")",
":",
"logger",
".",
"info",
"(",
"'zan: {0}'",
".",
"format",
"(",
"id_reply",
")",
")",
"MReply2User",
".",
"create_reply",
"(",
"self",
".",
"userinfo",
".",
"uid",
",",
"id_reply",
")",
"cur_count",
"... | 先在外部表中更新,然后更新内部表字段的值。
有冗余,但是查看的时候避免了联合查询 | [
"先在外部表中更新,然后更新内部表字段的值。",
"有冗余,但是查看的时候避免了联合查询"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/reply_handler.py#L99-L116 |
bukun/TorCMS | torcms/handlers/reply_handler.py | ReplyHandler.delete | def delete(self, del_id):
'''
Delete the id
'''
if MReply2User.delete(del_id):
output = {'del_zan': 1}
else:
output = {'del_zan': 0}
return json.dump(output, self) | python | def delete(self, del_id):
'''
Delete the id
'''
if MReply2User.delete(del_id):
output = {'del_zan': 1}
else:
output = {'del_zan': 0}
return json.dump(output, self) | [
"def",
"delete",
"(",
"self",
",",
"del_id",
")",
":",
"if",
"MReply2User",
".",
"delete",
"(",
"del_id",
")",
":",
"output",
"=",
"{",
"'del_zan'",
":",
"1",
"}",
"else",
":",
"output",
"=",
"{",
"'del_zan'",
":",
"0",
"}",
"return",
"json",
".",
... | Delete the id | [
"Delete",
"the",
"id"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/reply_handler.py#L118-L126 |
bukun/TorCMS | torcms/model/catalog_model.py | MCatalog.query_by_slug | def query_by_slug(slug):
'''
查询全部章节
'''
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 | python | def query_by_slug(slug):
'''
查询全部章节
'''
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",
")",
":",
"cat_rec",
"=",
"MCategory",
".",
"get_by_slug",
"(",
"slug",
")",
"if",
"cat_rec",
":",
"cat_id",
"=",
"cat_rec",
".",
"uid",
"else",
":",
"return",
"None",
"if",
"cat_id",
".",
"endswith",
"(",
"'00'",
"... | 查询全部章节 | [
"查询全部章节"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/catalog_model.py#L23-L47 |
bukun/TorCMS | torcms/model/catalog_model.py | MCatalog.query_all | def query_all():
'''
查询大类记录
'''
recs = TabTag.select().where(TabTag.uid.endswith('00')).order_by(TabTag.uid)
return recs | python | def query_all():
'''
查询大类记录
'''
recs = TabTag.select().where(TabTag.uid.endswith('00')).order_by(TabTag.uid)
return recs | [
"def",
"query_all",
"(",
")",
":",
"recs",
"=",
"TabTag",
".",
"select",
"(",
")",
".",
"where",
"(",
"TabTag",
".",
"uid",
".",
"endswith",
"(",
"'00'",
")",
")",
".",
"order_by",
"(",
"TabTag",
".",
"uid",
")",
"return",
"recs"
] | 查询大类记录 | [
"查询大类记录"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/catalog_model.py#L50-L56 |
bukun/TorCMS | torcms/handlers/wiki_history_manager.py | WikiHistoryHandler.update | def update(self, uid):
'''
Update the post via ID.
'''
if self.userinfo.role[0] > '0':
pass
else:
return False
post_data = self.get_post_data()
post_data['user_name'] = self.userinfo.user_name if self.userinfo else ''
cur_info = MWiki.get_by_uid(uid)
MWikiHist.create_wiki_history(cur_info)
MWiki.update_cnt(uid, post_data)
if cur_info.kind == '1':
self.redirect('/wiki/{0}'.format(cur_info.title))
elif cur_info.kind == '2':
self.redirect('/page/{0}.html'.format(cur_info.uid)) | python | def update(self, uid):
'''
Update the post via ID.
'''
if self.userinfo.role[0] > '0':
pass
else:
return False
post_data = self.get_post_data()
post_data['user_name'] = self.userinfo.user_name if self.userinfo else ''
cur_info = MWiki.get_by_uid(uid)
MWikiHist.create_wiki_history(cur_info)
MWiki.update_cnt(uid, post_data)
if cur_info.kind == '1':
self.redirect('/wiki/{0}'.format(cur_info.title))
elif cur_info.kind == '2':
self.redirect('/page/{0}.html'.format(cur_info.uid)) | [
"def",
"update",
"(",
"self",
",",
"uid",
")",
":",
"if",
"self",
".",
"userinfo",
".",
"role",
"[",
"0",
"]",
">",
"'0'",
":",
"pass",
"else",
":",
"return",
"False",
"post_data",
"=",
"self",
".",
"get_post_data",
"(",
")",
"post_data",
"[",
"'us... | Update the post via ID. | [
"Update",
"the",
"post",
"via",
"ID",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/wiki_history_manager.py#L26-L43 |
bukun/TorCMS | torcms/handlers/wiki_history_manager.py | WikiHistoryHandler.to_edit | def to_edit(self, postid):
'''
Try to edit the Post.
'''
if self.userinfo.role[0] > '0':
pass
else:
return False
kwd = {}
self.render('man_info/wiki_man_edit.html',
userinfo=self.userinfo,
postinfo=MWiki.get_by_uid(postid),
kwd=kwd) | python | def to_edit(self, postid):
'''
Try to edit the Post.
'''
if self.userinfo.role[0] > '0':
pass
else:
return False
kwd = {}
self.render('man_info/wiki_man_edit.html',
userinfo=self.userinfo,
postinfo=MWiki.get_by_uid(postid),
kwd=kwd) | [
"def",
"to_edit",
"(",
"self",
",",
"postid",
")",
":",
"if",
"self",
".",
"userinfo",
".",
"role",
"[",
"0",
"]",
">",
"'0'",
":",
"pass",
"else",
":",
"return",
"False",
"kwd",
"=",
"{",
"}",
"self",
".",
"render",
"(",
"'man_info/wiki_man_edit.htm... | Try to edit the Post. | [
"Try",
"to",
"edit",
"the",
"Post",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/wiki_history_manager.py#L46-L58 |
bukun/TorCMS | torcms/handlers/wiki_history_manager.py | WikiHistoryHandler.delete | def delete(self, uid):
'''
Delete the history of certain ID.
'''
if self.check_post_role()['DELETE']:
pass
else:
return False
histinfo = MWikiHist.get_by_uid(uid)
if histinfo:
pass
else:
return False
postinfo = MWiki.get_by_uid(histinfo.wiki_id)
MWikiHist.delete(uid)
self.redirect('/wiki_man/view/{0}'.format(postinfo.uid)) | python | def delete(self, uid):
'''
Delete the history of certain ID.
'''
if self.check_post_role()['DELETE']:
pass
else:
return False
histinfo = MWikiHist.get_by_uid(uid)
if histinfo:
pass
else:
return False
postinfo = MWiki.get_by_uid(histinfo.wiki_id)
MWikiHist.delete(uid)
self.redirect('/wiki_man/view/{0}'.format(postinfo.uid)) | [
"def",
"delete",
"(",
"self",
",",
"uid",
")",
":",
"if",
"self",
".",
"check_post_role",
"(",
")",
"[",
"'DELETE'",
"]",
":",
"pass",
"else",
":",
"return",
"False",
"histinfo",
"=",
"MWikiHist",
".",
"get_by_uid",
"(",
"uid",
")",
"if",
"histinfo",
... | Delete the history of certain ID. | [
"Delete",
"the",
"history",
"of",
"certain",
"ID",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/wiki_history_manager.py#L61-L78 |
bukun/TorCMS | torcms/handlers/wiki_history_manager.py | WikiHistoryHandler.restore | def restore(self, hist_uid):
'''
Restore by ID
'''
if self.check_post_role()['ADMIN']:
pass
else:
return False
histinfo = MWikiHist.get_by_uid(hist_uid)
if histinfo:
pass
else:
return False
postinfo = MWiki.get_by_uid(histinfo.wiki_id)
cur_cnt = tornado.escape.xhtml_unescape(postinfo.cnt_md)
old_cnt = tornado.escape.xhtml_unescape(histinfo.cnt_md)
MWiki.update_cnt(
histinfo.wiki_id,
{'cnt_md': old_cnt, 'user_name': self.userinfo.user_name}
)
MWikiHist.update_cnt(
histinfo.uid,
{'cnt_md': cur_cnt, 'user_name': postinfo.user_name}
)
if postinfo.kind == '1':
self.redirect('/wiki/{0}'.format(postinfo.title))
elif postinfo.kind == '2':
self.redirect('/page/{0}.html'.format(postinfo.uid)) | python | def restore(self, hist_uid):
'''
Restore by ID
'''
if self.check_post_role()['ADMIN']:
pass
else:
return False
histinfo = MWikiHist.get_by_uid(hist_uid)
if histinfo:
pass
else:
return False
postinfo = MWiki.get_by_uid(histinfo.wiki_id)
cur_cnt = tornado.escape.xhtml_unescape(postinfo.cnt_md)
old_cnt = tornado.escape.xhtml_unescape(histinfo.cnt_md)
MWiki.update_cnt(
histinfo.wiki_id,
{'cnt_md': old_cnt, 'user_name': self.userinfo.user_name}
)
MWikiHist.update_cnt(
histinfo.uid,
{'cnt_md': cur_cnt, 'user_name': postinfo.user_name}
)
if postinfo.kind == '1':
self.redirect('/wiki/{0}'.format(postinfo.title))
elif postinfo.kind == '2':
self.redirect('/page/{0}.html'.format(postinfo.uid)) | [
"def",
"restore",
"(",
"self",
",",
"hist_uid",
")",
":",
"if",
"self",
".",
"check_post_role",
"(",
")",
"[",
"'ADMIN'",
"]",
":",
"pass",
"else",
":",
"return",
"False",
"histinfo",
"=",
"MWikiHist",
".",
"get_by_uid",
"(",
"hist_uid",
")",
"if",
"hi... | Restore by ID | [
"Restore",
"by",
"ID"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/wiki_history_manager.py#L124-L155 |
bukun/TorCMS | torcms/model/log_model.py | MLog.add | def add(data_dic):
'''
Insert new record.
'''
uid = data_dic['uid']
TabLog.create(
uid=uid,
current_url=data_dic['url'],
refer_url=data_dic['refer'],
user_id=data_dic['user_id'],
time_create=data_dic['timein'],
time_out=data_dic['timeOut'],
time=data_dic['timeon']
)
return uid | python | def add(data_dic):
'''
Insert new record.
'''
uid = data_dic['uid']
TabLog.create(
uid=uid,
current_url=data_dic['url'],
refer_url=data_dic['refer'],
user_id=data_dic['user_id'],
time_create=data_dic['timein'],
time_out=data_dic['timeOut'],
time=data_dic['timeon']
)
return uid | [
"def",
"add",
"(",
"data_dic",
")",
":",
"uid",
"=",
"data_dic",
"[",
"'uid'",
"]",
"TabLog",
".",
"create",
"(",
"uid",
"=",
"uid",
",",
"current_url",
"=",
"data_dic",
"[",
"'url'",
"]",
",",
"refer_url",
"=",
"data_dic",
"[",
"'refer'",
"]",
",",
... | Insert new record. | [
"Insert",
"new",
"record",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/log_model.py#L20-L35 |
bukun/TorCMS | torcms/model/log_model.py | MLog.query_pager_by_user | def query_pager_by_user(userid, current_page_num=1):
'''
Query pager
'''
return TabLog.select().where(TabLog.user_id == userid).order_by(
TabLog.time_create.desc()
).paginate(
current_page_num, CMS_CFG['list_num']
) | python | def query_pager_by_user(userid, current_page_num=1):
'''
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",
")",
":",
"return",
"TabLog",
".",
"select",
"(",
")",
".",
"where",
"(",
"TabLog",
".",
"user_id",
"==",
"userid",
")",
".",
"order_by",
"(",
"TabLog",
".",
"time_create",
"... | Query pager | [
"Query",
"pager"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/log_model.py#L38-L46 |
bukun/TorCMS | torcms/model/log_model.py | MLog.query_all_user | def query_all_user():
'''
查询所有登录用户的访问记录
ToDo: ``None`` ?
'''
return TabLog.select().where(TabLog.user_id != 'None').distinct(TabLog.user_id).order_by(
TabLog.user_id
) | python | def query_all_user():
'''
查询所有登录用户的访问记录
ToDo: ``None`` ?
'''
return TabLog.select().where(TabLog.user_id != 'None').distinct(TabLog.user_id).order_by(
TabLog.user_id
) | [
"def",
"query_all_user",
"(",
")",
":",
"return",
"TabLog",
".",
"select",
"(",
")",
".",
"where",
"(",
"TabLog",
".",
"user_id",
"!=",
"'None'",
")",
".",
"distinct",
"(",
"TabLog",
".",
"user_id",
")",
".",
"order_by",
"(",
"TabLog",
".",
"user_id",
... | 查询所有登录用户的访问记录
ToDo: ``None`` ? | [
"查询所有登录用户的访问记录",
"ToDo",
":",
"None",
"?"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/log_model.py#L49-L56 |
bukun/TorCMS | torcms/model/log_model.py | MLog.query_all | def query_all(current_page_num=1):
'''
查询所有未登录用户的访问记录
ToDo: ``None`` ?
'''
return TabLog.select().where(TabLog.user_id == 'None').order_by(TabLog.time_out.desc()).paginate(
current_page_num, CMS_CFG['list_num']
) | python | def query_all(current_page_num=1):
'''
查询所有未登录用户的访问记录
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",
")",
":",
"return",
"TabLog",
".",
"select",
"(",
")",
".",
"where",
"(",
"TabLog",
".",
"user_id",
"==",
"'None'",
")",
".",
"order_by",
"(",
"TabLog",
".",
"time_out",
".",
"desc",
"(",
")",
")... | 查询所有未登录用户的访问记录
ToDo: ``None`` ? | [
"查询所有未登录用户的访问记录",
"ToDo",
":",
"None",
"?"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/log_model.py#L59-L66 |
bukun/TorCMS | torcms/model/log_model.py | MLog.query_all_pageview | def query_all_pageview(current_page_num=1):
'''
查询所有页面(current_url),分页
'''
return TabLog.select().distinct(TabLog.current_url).order_by(TabLog.current_url).paginate(
current_page_num, CMS_CFG['list_num']
) | python | def query_all_pageview(current_page_num=1):
'''
查询所有页面(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",
")",
":",
"return",
"TabLog",
".",
"select",
"(",
")",
".",
"distinct",
"(",
"TabLog",
".",
"current_url",
")",
".",
"order_by",
"(",
"TabLog",
".",
"current_url",
")",
".",
"paginate",
"(",
... | 查询所有页面(current_url),分页 | [
"查询所有页面(current_url),分页"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/log_model.py#L69-L75 |
bukun/TorCMS | torcms/model/log_model.py | MLog.count_of_current_url | def count_of_current_url(current_url):
'''
长询制订页面(current_url)的访问量
'''
res = TabLog.select().where(TabLog.current_url == current_url)
return res.count() | python | def count_of_current_url(current_url):
'''
长询制订页面(current_url)的访问量
'''
res = TabLog.select().where(TabLog.current_url == current_url)
return res.count() | [
"def",
"count_of_current_url",
"(",
"current_url",
")",
":",
"res",
"=",
"TabLog",
".",
"select",
"(",
")",
".",
"where",
"(",
"TabLog",
".",
"current_url",
"==",
"current_url",
")",
"return",
"res",
".",
"count",
"(",
")"
] | 长询制订页面(current_url)的访问量 | [
"长询制订页面(current_url)的访问量"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/log_model.py#L85-L90 |
bukun/TorCMS | torcms/script/script_check200.py | run_check200 | def run_check200(_):
'''
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.') | python | def run_check200(_):
'''
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",
"(",
"_",
")",
":",
"tstr",
"=",
"''",
"idx",
"=",
"1",
"for",
"kind",
"in",
"config",
".",
"router_post",
".",
"keys",
"(",
")",
":",
"posts",
"=",
"MPost",
".",
"query_all",
"(",
"kind",
"=",
"kind",
",",
"limit",
"=",
"2... | Running the script. | [
"Running",
"the",
"script",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/script/script_check200.py#L29-L60 |
bukun/TorCMS | torcms/model/collect_model.py | MCollect.get_by_signature | def get_by_signature(user_id, app_id):
'''
Get the collection.
'''
try:
return TabCollect.get(
(TabCollect.user_id == user_id) &
(TabCollect.post_id == app_id)
)
except:
return None | python | def get_by_signature(user_id, app_id):
'''
Get the collection.
'''
try:
return TabCollect.get(
(TabCollect.user_id == user_id) &
(TabCollect.post_id == app_id)
)
except:
return None | [
"def",
"get_by_signature",
"(",
"user_id",
",",
"app_id",
")",
":",
"try",
":",
"return",
"TabCollect",
".",
"get",
"(",
"(",
"TabCollect",
".",
"user_id",
"==",
"user_id",
")",
"&",
"(",
"TabCollect",
".",
"post_id",
"==",
"app_id",
")",
")",
"except",
... | Get the collection. | [
"Get",
"the",
"collection",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/collect_model.py#L42-L52 |
bukun/TorCMS | torcms/model/collect_model.py | MCollect.count_of_user | def count_of_user(user_id):
'''
Get the cound of views.
'''
return TabCollect.select(
TabCollect, TabPost.uid.alias('post_uid'),
TabPost.title.alias('post_title'),
TabPost.view_count.alias('post_view_count')
).where(
TabCollect.user_id == user_id
).join(
TabPost, on=(TabCollect.post_id == TabPost.uid)
).count() | python | def count_of_user(user_id):
'''
Get the cound of views.
'''
return TabCollect.select(
TabCollect, TabPost.uid.alias('post_uid'),
TabPost.title.alias('post_title'),
TabPost.view_count.alias('post_view_count')
).where(
TabCollect.user_id == user_id
).join(
TabPost, on=(TabCollect.post_id == TabPost.uid)
).count() | [
"def",
"count_of_user",
"(",
"user_id",
")",
":",
"return",
"TabCollect",
".",
"select",
"(",
"TabCollect",
",",
"TabPost",
".",
"uid",
".",
"alias",
"(",
"'post_uid'",
")",
",",
"TabPost",
".",
"title",
".",
"alias",
"(",
"'post_title'",
")",
",",
"TabP... | Get the cound of views. | [
"Get",
"the",
"cound",
"of",
"views",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/collect_model.py#L55-L67 |
bukun/TorCMS | torcms/model/collect_model.py | MCollect.add_or_update | def add_or_update(user_id, app_id):
'''
Add the collection or update.
'''
rec = MCollect.get_by_signature(user_id, app_id)
if rec:
entry = TabCollect.update(
timestamp=int(time.time())
).where(TabCollect.uid == rec.uid)
entry.execute()
else:
TabCollect.create(
uid=tools.get_uuid(),
user_id=user_id,
post_id=app_id,
timestamp=int(time.time()),
) | python | def add_or_update(user_id, app_id):
'''
Add the collection or update.
'''
rec = MCollect.get_by_signature(user_id, app_id)
if rec:
entry = TabCollect.update(
timestamp=int(time.time())
).where(TabCollect.uid == rec.uid)
entry.execute()
else:
TabCollect.create(
uid=tools.get_uuid(),
user_id=user_id,
post_id=app_id,
timestamp=int(time.time()),
) | [
"def",
"add_or_update",
"(",
"user_id",
",",
"app_id",
")",
":",
"rec",
"=",
"MCollect",
".",
"get_by_signature",
"(",
"user_id",
",",
"app_id",
")",
"if",
"rec",
":",
"entry",
"=",
"TabCollect",
".",
"update",
"(",
"timestamp",
"=",
"int",
"(",
"time",
... | Add the collection or update. | [
"Add",
"the",
"collection",
"or",
"update",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/collect_model.py#L87-L105 |
bukun/TorCMS | torcms/core/libs/deprecation.py | deprecated | def deprecated(deprecated_in=None, removed_in=None, current_version=None, details=""):
"""Decorate a function to signify its deprecation
This function wraps a method that will soon be removed and does two things:
* The docstring of the method will be modified to include a notice
about deprecation, e.g., "Deprecated since 0.9.11. Use foo instead."
* Raises a :class:`~deprecation.DeprecatedWarning`
via the :mod:`warnings` module, which is a subclass of the built-in
:class:`DeprecationWarning`. Note that built-in
:class:`DeprecationWarning`\\s are ignored by default, so for users
to be informed of said warnings they will need to enable them--see
the :mod:`warnings` module documentation for more details.
:param deprecated_in: The version at which the decorated method is
considered deprecated. This will usually be the
next version to be released when the decorator is
added. The default is **None**, which effectively
means immediate deprecation. If this is not
specified, then the `removed_in` and
`current_version` arguments are ignored.
:param removed_in: The version when the decorated method will be removed.
The default is **None**, specifying that the function
is not currently planned to be removed.
Note: This cannot be set to a value if
`deprecated_in=None`.
:param current_version: The source of version information for the
currently running code. This will usually be
a `__version__` attribute on your library.
The default is `None`.
When `current_version=None` the automation to
determine if the wrapped function is actually
in a period of deprecation or time for removal
does not work, causing a
:class:`~deprecation.DeprecatedWarning`
to be raised in all cases.
:param details: Extra details to be added to the method docstring and
warning. For example, the details may point users to
a replacement method, such as "Use the foo_bar
method instead". By default there are no details.
"""
# You can't just jump to removal. It's weird, unfair, and also makes
# building up the docstring weird.
if deprecated_in is None and removed_in is not None:
raise TypeError("Cannot set removed_in to a value "
"without also setting deprecated_in")
# Only warn when it's appropriate. There may be cases when it makes sense
# to add this decorator before a formal deprecation period begins.
# In CPython, PendingDeprecatedWarning gets used in that period,
# so perhaps mimick that at some point.
is_deprecated = False
is_unsupported = False
# StrictVersion won't take a None or a "", so make whatever goes to it
# is at least *something*.
if current_version:
current_version = version.StrictVersion(current_version)
if removed_in and current_version >= version.StrictVersion(removed_in):
is_unsupported = True
elif deprecated_in and current_version >= version.StrictVersion(deprecated_in):
is_deprecated = True
else:
# If we can't actually calculate that we're in a period of
# deprecation...well, they used the decorator, so it's deprecated.
# This will cover the case of someone just using
# @deprecated("1.0") without the other advantages.
is_deprecated = True
should_warn = any([is_deprecated, is_unsupported])
def _function_wrapper(function):
if should_warn:
# Everything *should* have a docstring, but just in case...
existing_docstring = function.__doc__ or ""
# The various parts of this decorator being optional makes for
# a number of ways the deprecation notice could go. The following
# makes for a nicely constructed sentence with or without any
# of the parts.
parts = {
"deprecated_in":
" in %s" % deprecated_in if deprecated_in else "",
"removed_in":
", to be removed in %s" % removed_in if removed_in else "",
"period":
"." if deprecated_in or removed_in or details else "",
"details":
" %s" % details if details else ""}
deprecation_note = ("*Deprecated{deprecated_in}{removed_in}"
"{period}{details}*".format(**parts))
function.__doc__ = "\n\n".join([existing_docstring,
deprecation_note])
@functools.wraps(function)
def _inner(*args, **kwargs):
if should_warn:
if is_unsupported:
cls = UnsupportedWarning
else:
cls = DeprecatedWarning
the_warning = cls(function.__name__, deprecated_in,
removed_in, details)
warnings.warn(the_warning)
return function(*args, **kwargs)
return _inner
return _function_wrapper | python | def deprecated(deprecated_in=None, removed_in=None, current_version=None, details=""):
"""Decorate a function to signify its deprecation
This function wraps a method that will soon be removed and does two things:
* The docstring of the method will be modified to include a notice
about deprecation, e.g., "Deprecated since 0.9.11. Use foo instead."
* Raises a :class:`~deprecation.DeprecatedWarning`
via the :mod:`warnings` module, which is a subclass of the built-in
:class:`DeprecationWarning`. Note that built-in
:class:`DeprecationWarning`\\s are ignored by default, so for users
to be informed of said warnings they will need to enable them--see
the :mod:`warnings` module documentation for more details.
:param deprecated_in: The version at which the decorated method is
considered deprecated. This will usually be the
next version to be released when the decorator is
added. The default is **None**, which effectively
means immediate deprecation. If this is not
specified, then the `removed_in` and
`current_version` arguments are ignored.
:param removed_in: The version when the decorated method will be removed.
The default is **None**, specifying that the function
is not currently planned to be removed.
Note: This cannot be set to a value if
`deprecated_in=None`.
:param current_version: The source of version information for the
currently running code. This will usually be
a `__version__` attribute on your library.
The default is `None`.
When `current_version=None` the automation to
determine if the wrapped function is actually
in a period of deprecation or time for removal
does not work, causing a
:class:`~deprecation.DeprecatedWarning`
to be raised in all cases.
:param details: Extra details to be added to the method docstring and
warning. For example, the details may point users to
a replacement method, such as "Use the foo_bar
method instead". By default there are no details.
"""
# You can't just jump to removal. It's weird, unfair, and also makes
# building up the docstring weird.
if deprecated_in is None and removed_in is not None:
raise TypeError("Cannot set removed_in to a value "
"without also setting deprecated_in")
# Only warn when it's appropriate. There may be cases when it makes sense
# to add this decorator before a formal deprecation period begins.
# In CPython, PendingDeprecatedWarning gets used in that period,
# so perhaps mimick that at some point.
is_deprecated = False
is_unsupported = False
# StrictVersion won't take a None or a "", so make whatever goes to it
# is at least *something*.
if current_version:
current_version = version.StrictVersion(current_version)
if removed_in and current_version >= version.StrictVersion(removed_in):
is_unsupported = True
elif deprecated_in and current_version >= version.StrictVersion(deprecated_in):
is_deprecated = True
else:
# If we can't actually calculate that we're in a period of
# deprecation...well, they used the decorator, so it's deprecated.
# This will cover the case of someone just using
# @deprecated("1.0") without the other advantages.
is_deprecated = True
should_warn = any([is_deprecated, is_unsupported])
def _function_wrapper(function):
if should_warn:
# Everything *should* have a docstring, but just in case...
existing_docstring = function.__doc__ or ""
# The various parts of this decorator being optional makes for
# a number of ways the deprecation notice could go. The following
# makes for a nicely constructed sentence with or without any
# of the parts.
parts = {
"deprecated_in":
" in %s" % deprecated_in if deprecated_in else "",
"removed_in":
", to be removed in %s" % removed_in if removed_in else "",
"period":
"." if deprecated_in or removed_in or details else "",
"details":
" %s" % details if details else ""}
deprecation_note = ("*Deprecated{deprecated_in}{removed_in}"
"{period}{details}*".format(**parts))
function.__doc__ = "\n\n".join([existing_docstring,
deprecation_note])
@functools.wraps(function)
def _inner(*args, **kwargs):
if should_warn:
if is_unsupported:
cls = UnsupportedWarning
else:
cls = DeprecatedWarning
the_warning = cls(function.__name__, deprecated_in,
removed_in, details)
warnings.warn(the_warning)
return function(*args, **kwargs)
return _inner
return _function_wrapper | [
"def",
"deprecated",
"(",
"deprecated_in",
"=",
"None",
",",
"removed_in",
"=",
"None",
",",
"current_version",
"=",
"None",
",",
"details",
"=",
"\"\"",
")",
":",
"# You can't just jump to removal. It's weird, unfair, and also makes",
"# building up the docstring weird.",
... | Decorate a function to signify its deprecation
This function wraps a method that will soon be removed and does two things:
* The docstring of the method will be modified to include a notice
about deprecation, e.g., "Deprecated since 0.9.11. Use foo instead."
* Raises a :class:`~deprecation.DeprecatedWarning`
via the :mod:`warnings` module, which is a subclass of the built-in
:class:`DeprecationWarning`. Note that built-in
:class:`DeprecationWarning`\\s are ignored by default, so for users
to be informed of said warnings they will need to enable them--see
the :mod:`warnings` module documentation for more details.
:param deprecated_in: The version at which the decorated method is
considered deprecated. This will usually be the
next version to be released when the decorator is
added. The default is **None**, which effectively
means immediate deprecation. If this is not
specified, then the `removed_in` and
`current_version` arguments are ignored.
:param removed_in: The version when the decorated method will be removed.
The default is **None**, specifying that the function
is not currently planned to be removed.
Note: This cannot be set to a value if
`deprecated_in=None`.
:param current_version: The source of version information for the
currently running code. This will usually be
a `__version__` attribute on your library.
The default is `None`.
When `current_version=None` the automation to
determine if the wrapped function is actually
in a period of deprecation or time for removal
does not work, causing a
:class:`~deprecation.DeprecatedWarning`
to be raised in all cases.
:param details: Extra details to be added to the method docstring and
warning. For example, the details may point users to
a replacement method, such as "Use the foo_bar
method instead". By default there are no details. | [
"Decorate",
"a",
"function",
"to",
"signify",
"its",
"deprecation"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/core/libs/deprecation.py#L78-L190 |
bukun/TorCMS | torcms/core/libs/deprecation.py | fail_if_not_removed | def fail_if_not_removed(method):
"""Decorate a test method to track removal of deprecated code
This decorator catches :class:`~deprecation.UnsupportedWarning`
warnings that occur during testing and causes unittests to fail,
making it easier to keep track of when code should be removed.
:raises: :class:`AssertionError` if an
:class:`~deprecation.UnsupportedWarning`
is raised while running the test method.
"""
def _inner(*args, **kwargs):
with warnings.catch_warnings(record=True) as caught_warnings:
warnings.simplefilter("always")
rval = method(*args, **kwargs)
for warning in caught_warnings:
if warning.category == UnsupportedWarning:
raise AssertionError(
("%s uses a function that should be removed: %s" %
(method, str(warning.message))))
return rval
return _inner | python | def fail_if_not_removed(method):
"""Decorate a test method to track removal of deprecated code
This decorator catches :class:`~deprecation.UnsupportedWarning`
warnings that occur during testing and causes unittests to fail,
making it easier to keep track of when code should be removed.
:raises: :class:`AssertionError` if an
:class:`~deprecation.UnsupportedWarning`
is raised while running the test method.
"""
def _inner(*args, **kwargs):
with warnings.catch_warnings(record=True) as caught_warnings:
warnings.simplefilter("always")
rval = method(*args, **kwargs)
for warning in caught_warnings:
if warning.category == UnsupportedWarning:
raise AssertionError(
("%s uses a function that should be removed: %s" %
(method, str(warning.message))))
return rval
return _inner | [
"def",
"fail_if_not_removed",
"(",
"method",
")",
":",
"def",
"_inner",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"with",
"warnings",
".",
"catch_warnings",
"(",
"record",
"=",
"True",
")",
"as",
"caught_warnings",
":",
"warnings",
".",
"simpl... | Decorate a test method to track removal of deprecated code
This decorator catches :class:`~deprecation.UnsupportedWarning`
warnings that occur during testing and causes unittests to fail,
making it easier to keep track of when code should be removed.
:raises: :class:`AssertionError` if an
:class:`~deprecation.UnsupportedWarning`
is raised while running the test method. | [
"Decorate",
"a",
"test",
"method",
"to",
"track",
"removal",
"of",
"deprecated",
"code"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/core/libs/deprecation.py#L193-L217 |
bukun/TorCMS | ext_script/script_gen_xlsx_info.py | gen_xlsx_table_info | def gen_xlsx_table_info():
'''
向表中插入数据
'''
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) + " 行数据") | python | def gen_xlsx_table_info():
'''
向表中插入数据
'''
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",
"(",
")",
":",
"XLSX_FILE",
"=",
"'./database/esheet/20180811.xlsx'",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"XLSX_FILE",
")",
":",
"pass",
"else",
":",
"return",
"RAW_LIST",
"=",
"[",
"'A'",
",",
"'B'",
",",
"'C'",
",",... | 向表中插入数据 | [
"向表中插入数据"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/ext_script/script_gen_xlsx_info.py#L10-L57 |
bukun/TorCMS | torcms/core/base_handler.py | BaseHandler.get_post_data | def get_post_data(self):
'''
Get all the arguments from post request. Only get the first argument by default.
'''
post_data = {}
for key in self.request.arguments:
post_data[key] = self.get_arguments(key)[0]
return post_data | python | def get_post_data(self):
'''
Get all the arguments from post request. Only get the first argument by default.
'''
post_data = {}
for key in self.request.arguments:
post_data[key] = self.get_arguments(key)[0]
return post_data | [
"def",
"get_post_data",
"(",
"self",
")",
":",
"post_data",
"=",
"{",
"}",
"for",
"key",
"in",
"self",
".",
"request",
".",
"arguments",
":",
"post_data",
"[",
"key",
"]",
"=",
"self",
".",
"get_arguments",
"(",
"key",
")",
"[",
"0",
"]",
"return",
... | Get all the arguments from post request. Only get the first argument by default. | [
"Get",
"all",
"the",
"arguments",
"from",
"post",
"request",
".",
"Only",
"get",
"the",
"first",
"argument",
"by",
"default",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/core/base_handler.py#L36-L43 |
bukun/TorCMS | torcms/core/base_handler.py | BaseHandler.check_post_role | def check_post_role(self):
'''
check the user role for docs.
'''
priv_dic = {'ADD': False, 'EDIT': False, 'DELETE': False, 'ADMIN': False}
if self.userinfo:
if self.userinfo.role[1] > '0':
priv_dic['ADD'] = True
if self.userinfo.role[1] >= '1':
priv_dic['EDIT'] = True
if self.userinfo.role[1] >= '3':
priv_dic['DELETE'] = True
if self.userinfo.role[1] >= '2':
priv_dic['ADMIN'] = True
return priv_dic | python | def check_post_role(self):
'''
check the user role for docs.
'''
priv_dic = {'ADD': False, 'EDIT': False, 'DELETE': False, 'ADMIN': False}
if self.userinfo:
if self.userinfo.role[1] > '0':
priv_dic['ADD'] = True
if self.userinfo.role[1] >= '1':
priv_dic['EDIT'] = True
if self.userinfo.role[1] >= '3':
priv_dic['DELETE'] = True
if self.userinfo.role[1] >= '2':
priv_dic['ADMIN'] = True
return priv_dic | [
"def",
"check_post_role",
"(",
"self",
")",
":",
"priv_dic",
"=",
"{",
"'ADD'",
":",
"False",
",",
"'EDIT'",
":",
"False",
",",
"'DELETE'",
":",
"False",
",",
"'ADMIN'",
":",
"False",
"}",
"if",
"self",
".",
"userinfo",
":",
"if",
"self",
".",
"useri... | check the user role for docs. | [
"check",
"the",
"user",
"role",
"for",
"docs",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/core/base_handler.py#L55-L69 |
bukun/TorCMS | torcms/core/base_handler.py | BaseHandler.get_user_locale | def get_user_locale(self):
'''
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') | python | def get_user_locale(self):
'''
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",
")",
":",
"locale_id",
"=",
"self",
".",
"get_cookie",
"(",
"'ulocale'",
")",
"if",
"locale_id",
":",
"return",
"tornado",
".",
"locale",
".",
"get",
"(",
"locale_id",
")",
"else",
":",
"return",
"tornado",
".",
"lo... | Override the function, to control the UI language. | [
"Override",
"the",
"function",
"to",
"control",
"the",
"UI",
"language",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/core/base_handler.py#L80-L88 |
bukun/TorCMS | torcms/core/base_handler.py | BaseHandler.get_browser_locale | def get_browser_locale(self):
'''
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') | python | def get_browser_locale(self):
'''
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",
")",
":",
"locale_id",
"=",
"self",
".",
"get_cookie",
"(",
"'blocale'",
")",
"if",
"locale_id",
":",
"return",
"tornado",
".",
"locale",
".",
"get",
"(",
"locale_id",
")",
"else",
":",
"return",
"tornado",
".",
... | Override the function, to control the UI language. | [
"Override",
"the",
"function",
"to",
"control",
"the",
"UI",
"language",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/core/base_handler.py#L90-L98 |
bukun/TorCMS | torcms/core/base_handler.py | BaseHandler.wrap_tmpl | def wrap_tmpl(self, tmpl):
'''
return the warpped template path.
:param tmpl:
'''
return 'admin/' + tmpl.format(sig='p') if self.is_p else tmpl.format(sig='') | python | def wrap_tmpl(self, tmpl):
'''
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",
"'admin/'",
"+",
"tmpl",
".",
"format",
"(",
"sig",
"=",
"'p'",
")",
"if",
"self",
".",
"is_p",
"else",
"tmpl",
".",
"format",
"(",
"sig",
"=",
"''",
")"
] | return the warpped template path.
:param tmpl: | [
"return",
"the",
"warpped",
"template",
"path",
".",
":",
"param",
"tmpl",
":"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/core/base_handler.py#L122-L127 |
bukun/TorCMS | torcms/model/entity_model.py | MEntity.get_id_by_impath | def get_id_by_impath(path):
'''
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 | python | def get_id_by_impath(path):
'''
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",
")",
":",
"logger",
".",
"info",
"(",
"'Get Entiry, Path: {0}'",
".",
"format",
"(",
"path",
")",
")",
"entity_list",
"=",
"TabEntity",
".",
"select",
"(",
")",
".",
"where",
"(",
"TabEntity",
".",
"path",
"==",
"p... | The the entity id by the path. | [
"The",
"the",
"entity",
"id",
"by",
"the",
"path",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/entity_model.py#L48-L64 |
bukun/TorCMS | torcms/model/entity_model.py | MEntity.create_entity | def create_entity(uid='', path='', desc='', kind='1'):
'''
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 | python | def create_entity(uid='', path='', desc='', kind='1'):
'''
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'",
")",
":",
"if",
"path",
":",
"pass",
"else",
":",
"return",
"False",
"if",
"uid",
":",
"pass",
"else",
":",
"uid",
"=",
"get... | create entity record in the database. | [
"create",
"entity",
"record",
"in",
"the",
"database",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/entity_model.py#L67-L91 |
bukun/TorCMS | ext_script/autocrud/gen_html_file.py | generate_html_files | def generate_html_files(*args):
'''
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) | python | def generate_html_files(*args):
'''
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",
")",
":",
"_",
"=",
"args",
"for",
"tag_key",
",",
"tag_list",
"in",
"SWITCH_DICS",
".",
"items",
"(",
")",
":",
"if",
"tag_key",
".",
"startswith",
"(",
"'dic_'",
")",
":",
"__write_view_tmpl",
"(",
"tag_l... | Generate the templates for adding, editing, viewing.
:return: None | [
"Generate",
"the",
"templates",
"for",
"adding",
"editing",
"viewing",
".",
":",
"return",
":",
"None"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/ext_script/autocrud/gen_html_file.py#L54-L66 |
bukun/TorCMS | torcms/handlers/index.py | IndexHandler.index | def index(self):
'''
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={}, ) | python | def index(self):
'''
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",
")",
":",
"self",
".",
"render",
"(",
"'index/index.html'",
",",
"userinfo",
"=",
"self",
".",
"userinfo",
",",
"catalog_info",
"=",
"MCategory",
".",
"query_all",
"(",
"by_order",
"=",
"True",
")",
",",
"link",
"=",
"MLink",... | Index funtion. | [
"Index",
"funtion",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/index.py#L26-L36 |
bukun/TorCMS | torcms/handlers/collect_handler.py | CollectHandler.add_or_update | def add_or_update(self, app_id):
'''
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) | python | def add_or_update(self, app_id):
'''
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",
")",
":",
"logger",
".",
"info",
"(",
"'Collect info: user-{0}, uid-{1}'",
".",
"format",
"(",
"self",
".",
"userinfo",
".",
"uid",
",",
"app_id",
")",
")",
"MCollect",
".",
"add_or_update",
"(",
"self",
... | Add or update the category. | [
"Add",
"or",
"update",
"the",
"category",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/collect_handler.py#L44-L51 |
bukun/TorCMS | torcms/handlers/collect_handler.py | CollectHandler.show_list | def show_list(self, the_list, cur_p=''):
'''
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) | python | def show_list(self, the_list, cur_p=''):
'''
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",
"=",
"''",
")",
":",
"current_page_num",
"=",
"int",
"(",
"cur_p",
")",
"if",
"cur_p",
"else",
"1",
"current_page_num",
"=",
"1",
"if",
"current_page_num",
"<",
"1",
"else",
"current_page_num"... | List of the user collections. | [
"List",
"of",
"the",
"user",
"collections",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/collect_handler.py#L54-L76 |
bukun/TorCMS | torcms/model/wiki_model.py | MWiki.create_wiki | def create_wiki(post_data):
'''
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) | python | def create_wiki(post_data):
'''
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",
")",
":",
"logger",
".",
"info",
"(",
"'Call create wiki'",
")",
"title",
"=",
"post_data",
"[",
"'title'",
"]",
".",
"strip",
"(",
")",
"if",
"len",
"(",
"title",
")",
"<",
"2",
":",
"logger",
".",
"info",
"("... | Create the wiki. | [
"Create",
"the",
"wiki",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/wiki_model.py#L80-L99 |
bukun/TorCMS | torcms/model/wiki_model.py | MWiki.create_page | def create_page(slug, post_data):
'''
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) | python | def create_page(slug, post_data):
'''
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",
")",
":",
"logger",
".",
"info",
"(",
"'Call create Page'",
")",
"if",
"MWiki",
".",
"get_by_uid",
"(",
"slug",
")",
":",
"return",
"False",
"title",
"=",
"post_data",
"[",
"'title'",
"]",
".",
"strip"... | The page would be created with slug. | [
"The",
"page",
"would",
"be",
"created",
"with",
"slug",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/wiki_model.py#L102-L113 |
bukun/TorCMS | torcms/model/wiki_model.py | MWiki.__create_rec | def __create_rec(*args, **kwargs):
'''
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 | python | def __create_rec(*args, **kwargs):
'''
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",
")",
":",
"uid",
"=",
"args",
"[",
"0",
"]",
"kind",
"=",
"args",
"[",
"1",
"]",
"post_data",
"=",
"kwargs",
"[",
"'post_data'",
"]",
"try",
":",
"TabWiki",
".",
"create",
"(",
"ui... | Create the record. | [
"Create",
"the",
"record",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/wiki_model.py#L116-L139 |
bukun/TorCMS | torcms/model/wiki_model.py | MWiki.query_dated | def query_dated(num=10, kind='1'):
'''
List the wiki of dated.
'''
return TabWiki.select().where(
TabWiki.kind == kind
).order_by(
TabWiki.time_update.desc()
).limit(num) | python | def query_dated(num=10, kind='1'):
'''
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'",
")",
":",
"return",
"TabWiki",
".",
"select",
"(",
")",
".",
"where",
"(",
"TabWiki",
".",
"kind",
"==",
"kind",
")",
".",
"order_by",
"(",
"TabWiki",
".",
"time_update",
".",
"d... | List the wiki of dated. | [
"List",
"the",
"wiki",
"of",
"dated",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/wiki_model.py#L142-L150 |
bukun/TorCMS | torcms/model/wiki_model.py | MWiki.query_most | def query_most(num=8, kind='1'):
'''
List the most viewed wiki.
'''
return TabWiki.select().where(
TabWiki.kind == kind
).order_by(
TabWiki.view_count.desc()
).limit(num) | python | def query_most(num=8, kind='1'):
'''
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'",
")",
":",
"return",
"TabWiki",
".",
"select",
"(",
")",
".",
"where",
"(",
"TabWiki",
".",
"kind",
"==",
"kind",
")",
".",
"order_by",
"(",
"TabWiki",
".",
"view_count",
".",
"desc... | List the most viewed wiki. | [
"List",
"the",
"most",
"viewed",
"wiki",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/wiki_model.py#L153-L161 |
bukun/TorCMS | torcms/model/wiki_model.py | MWiki.update_view_count | def update_view_count(citiao):
'''
view count of the wiki, plus 1. By wiki
'''
entry = TabWiki.update(
view_count=TabWiki.view_count + 1
).where(
TabWiki.title == citiao
)
entry.execute() | python | def update_view_count(citiao):
'''
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",
")",
":",
"entry",
"=",
"TabWiki",
".",
"update",
"(",
"view_count",
"=",
"TabWiki",
".",
"view_count",
"+",
"1",
")",
".",
"where",
"(",
"TabWiki",
".",
"title",
"==",
"citiao",
")",
"entry",
".",
"execute",
... | view count of the wiki, plus 1. By wiki | [
"view",
"count",
"of",
"the",
"wiki",
"plus",
"1",
".",
"By",
"wiki"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/wiki_model.py#L164-L173 |
bukun/TorCMS | torcms/model/wiki_model.py | MWiki.update_view_count_by_uid | def update_view_count_by_uid(uid):
'''
update the count of wiki, by uid.
'''
entry = TabWiki.update(
view_count=TabWiki.view_count + 1
).where(
TabWiki.uid == uid
)
entry.execute() | python | def update_view_count_by_uid(uid):
'''
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",
")",
":",
"entry",
"=",
"TabWiki",
".",
"update",
"(",
"view_count",
"=",
"TabWiki",
".",
"view_count",
"+",
"1",
")",
".",
"where",
"(",
"TabWiki",
".",
"uid",
"==",
"uid",
")",
"entry",
".",
"execute",
"... | update the count of wiki, by uid. | [
"update",
"the",
"count",
"of",
"wiki",
"by",
"uid",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/wiki_model.py#L176-L185 |
bukun/TorCMS | torcms/model/wiki_model.py | MWiki.get_by_wiki | def get_by_wiki(citiao):
'''
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() | python | def get_by_wiki(citiao):
'''
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",
")",
":",
"q_res",
"=",
"TabWiki",
".",
"select",
"(",
")",
".",
"where",
"(",
"TabWiki",
".",
"title",
"==",
"citiao",
")",
"the_count",
"=",
"q_res",
".",
"count",
"(",
")",
"if",
"the_count",
"==",
"0",
"or",
... | Get the wiki record by title. | [
"Get",
"the",
"wiki",
"record",
"by",
"title",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/wiki_model.py#L188-L198 |
bukun/TorCMS | torcms/model/wiki_model.py | MWiki.view_count_plus | def view_count_plus(slug):
'''
View count plus one.
'''
entry = TabWiki.update(
view_count=TabWiki.view_count + 1,
).where(TabWiki.uid == slug)
entry.execute() | python | def view_count_plus(slug):
'''
View count plus one.
'''
entry = TabWiki.update(
view_count=TabWiki.view_count + 1,
).where(TabWiki.uid == slug)
entry.execute() | [
"def",
"view_count_plus",
"(",
"slug",
")",
":",
"entry",
"=",
"TabWiki",
".",
"update",
"(",
"view_count",
"=",
"TabWiki",
".",
"view_count",
"+",
"1",
",",
")",
".",
"where",
"(",
"TabWiki",
".",
"uid",
"==",
"slug",
")",
"entry",
".",
"execute",
"... | View count plus one. | [
"View",
"count",
"plus",
"one",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/wiki_model.py#L208-L215 |
bukun/TorCMS | torcms/model/wiki_model.py | MWiki.query_all | def query_all(**kwargs):
'''
Qeury recent wiki.
'''
kind = kwargs.get('kind', '1')
limit = kwargs.get('limit', 50)
return TabWiki.select().where(TabWiki.kind == kind).limit(limit) | python | def query_all(**kwargs):
'''
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",
")",
":",
"kind",
"=",
"kwargs",
".",
"get",
"(",
"'kind'",
",",
"'1'",
")",
"limit",
"=",
"kwargs",
".",
"get",
"(",
"'limit'",
",",
"50",
")",
"return",
"TabWiki",
".",
"select",
"(",
")",
".",
"wher... | Qeury recent wiki. | [
"Qeury",
"recent",
"wiki",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/wiki_model.py#L218-L225 |
bukun/TorCMS | torcms/model/wiki_model.py | MWiki.query_random | def query_random(num=6, kind='1'):
'''
Query wikis randomly.
'''
return TabWiki.select().where(
TabWiki.kind == kind
).order_by(
peewee.fn.Random()
).limit(num) | python | def query_random(num=6, kind='1'):
'''
Query wikis randomly.
'''
return TabWiki.select().where(
TabWiki.kind == kind
).order_by(
peewee.fn.Random()
).limit(num) | [
"def",
"query_random",
"(",
"num",
"=",
"6",
",",
"kind",
"=",
"'1'",
")",
":",
"return",
"TabWiki",
".",
"select",
"(",
")",
".",
"where",
"(",
"TabWiki",
".",
"kind",
"==",
"kind",
")",
".",
"order_by",
"(",
"peewee",
".",
"fn",
".",
"Random",
... | Query wikis randomly. | [
"Query",
"wikis",
"randomly",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/wiki_model.py#L228-L236 |
bukun/TorCMS | torcms/model/wiki_model.py | MWiki.query_pager_by_kind | def query_pager_by_kind(kind, current_page_num=1):
'''
Query pager
'''
return TabWiki.select().where(TabWiki.kind == kind).order_by(TabWiki.time_create.desc()).paginate(current_page_num, CMS_CFG['list_num']) | python | def query_pager_by_kind(kind, current_page_num=1):
'''
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",
")",
":",
"return",
"TabWiki",
".",
"select",
"(",
")",
".",
"where",
"(",
"TabWiki",
".",
"kind",
"==",
"kind",
")",
".",
"order_by",
"(",
"TabWiki",
".",
"time_create",
".",
... | Query pager | [
"Query",
"pager"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/wiki_model.py#L254-L258 |
bukun/TorCMS | torcms/model/wiki_model.py | MWiki.count_of_certain_kind | def count_of_certain_kind(kind):
'''
Get the count of certain kind.
'''
recs = TabWiki.select().where(TabWiki.kind == kind)
return recs.count() | python | def count_of_certain_kind(kind):
'''
Get the count of certain kind.
'''
recs = TabWiki.select().where(TabWiki.kind == kind)
return recs.count() | [
"def",
"count_of_certain_kind",
"(",
"kind",
")",
":",
"recs",
"=",
"TabWiki",
".",
"select",
"(",
")",
".",
"where",
"(",
"TabWiki",
".",
"kind",
"==",
"kind",
")",
"return",
"recs",
".",
"count",
"(",
")"
] | Get the count of certain kind. | [
"Get",
"the",
"count",
"of",
"certain",
"kind",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/wiki_model.py#L261-L268 |
bukun/TorCMS | torcms/model/label_model.py | MLabel.get_id_by_name | def get_id_by_name(tag_name, kind='z'):
'''
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 | python | def get_id_by_name(tag_name, kind='z'):
'''
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'",
")",
":",
"recs",
"=",
"TabTag",
".",
"select",
"(",
")",
".",
"where",
"(",
"(",
"TabTag",
".",
"name",
"==",
"tag_name",
")",
"&",
"(",
"TabTag",
".",
"kind",
"==",
"kind",
")",
... | Get ID by tag_name of the label. | [
"Get",
"ID",
"by",
"tag_name",
"of",
"the",
"label",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/label_model.py#L22-L46 |
bukun/TorCMS | torcms/model/label_model.py | MLabel.get_by_slug | def get_by_slug(tag_slug):
'''
Get label by slug.
'''
label_recs = TabTag.select().where(TabTag.slug == tag_slug)
return label_recs.get() if label_recs else False | python | def get_by_slug(tag_slug):
'''
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",
")",
":",
"label_recs",
"=",
"TabTag",
".",
"select",
"(",
")",
".",
"where",
"(",
"TabTag",
".",
"slug",
"==",
"tag_slug",
")",
"return",
"label_recs",
".",
"get",
"(",
")",
"if",
"label_recs",
"else",
"False"
] | Get label by slug. | [
"Get",
"label",
"by",
"slug",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/label_model.py#L53-L58 |
bukun/TorCMS | torcms/model/label_model.py | MLabel.create_tag | def create_tag(tag_name, kind='z'):
'''
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 | python | def create_tag(tag_name, kind='z'):
'''
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'",
")",
":",
"cur_recs",
"=",
"TabTag",
".",
"select",
"(",
")",
".",
"where",
"(",
"(",
"TabTag",
".",
"name",
"==",
"tag_name",
")",
"&",
"(",
"TabTag",
".",
"kind",
"==",
"kind",
")",
... | Create tag record by tag_name | [
"Create",
"tag",
"record",
"by",
"tag_name"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/label_model.py#L61-L91 |
bukun/TorCMS | torcms/model/label_model.py | MPost2Label.get_by_uid | def get_by_uid(post_id):
'''
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')
) | python | def get_by_uid(post_id):
'''
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",
")",
":",
"return",
"TabPost2Tag",
".",
"select",
"(",
"TabPost2Tag",
",",
"TabTag",
".",
"name",
".",
"alias",
"(",
"'tag_name'",
")",
",",
"TabTag",
".",
"uid",
".",
"alias",
"(",
"'tag_uid'",
")",
")",
".",
"join... | Get records by post id. | [
"Get",
"records",
"by",
"post",
"id",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/label_model.py#L147-L159 |
bukun/TorCMS | torcms/model/label_model.py | MPost2Label.add_record | def add_record(post_id, tag_name, order=1, kind='z'):
'''
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 | python | def add_record(post_id, tag_name, order=1, kind='z'):
'''
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'",
")",
":",
"logger",
".",
"info",
"(",
"'Add label kind: {0}'",
".",
"format",
"(",
"kind",
")",
")",
"tag_id",
"=",
"MLabel",
".",
"get_id_by_name",
... | Add the record. | [
"Add",
"the",
"record",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/label_model.py#L190-L209 |
bukun/TorCMS | torcms/model/label_model.py | MPost2Label.total_number | def total_number(slug, kind='1'):
'''
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() | python | def total_number(slug, kind='1'):
'''
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",
"TabPost",
".",
"select",
"(",
")",
".",
"join",
"(",
"TabPost2Tag",
",",
"on",
"=",
"(",
"TabPost",
".",
"uid",
"==",
"TabPost2Tag",
".",
"post_id",
")",
")",
".",
"w... | Return the number of certian slug. | [
"Return",
"the",
"number",
"of",
"certian",
"slug",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/label_model.py#L212-L221 |
bukun/TorCMS | torcms/model/label_model.py | MPost2Label.query_pager_by_slug | def query_pager_by_slug(slug, kind='1', current_page_num=1):
'''
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']) | python | def query_pager_by_slug(slug, kind='1', current_page_num=1):
'''
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",
")",
":",
"return",
"TabPost",
".",
"select",
"(",
")",
".",
"join",
"(",
"TabPost2Tag",
",",
"on",
"=",
"(",
"TabPost",
".",
"uid",
"==",
"TabPost2T... | Query pager | [
"Query",
"pager"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/label_model.py#L224-L233 |
bukun/TorCMS | torcms/handlers/evaluation_handler.py | EvaluationHandler.add_or_update | 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.
'''
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) | python | 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.
'''
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",
")",
":",
"MEvaluation",
".",
"add_or_update",
"(",
"self",
".",
"userinfo",
".",
"uid",
",",
"app_id",
",",
"value",
")",
"out_dic",
"=",
"{",
"'eval0'",
":",
"MEvaluation",
".",
"app_eva... | Adding or updating the evalution.
:param app_id: the ID of the post.
:param value: the evaluation
:return: in JSON format. | [
"Adding",
"or",
"updating",
"the",
"evalution",
".",
":",
"param",
"app_id",
":",
"the",
"ID",
"of",
"the",
"post",
".",
":",
"param",
"value",
":",
"the",
"evaluation",
":",
"return",
":",
"in",
"JSON",
"format",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/handlers/evaluation_handler.py#L34-L48 |
bukun/TorCMS | torcms/script/command.py | entry | def entry(argv):
'''
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.') | python | def entry(argv):
'''
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_dic",
"=",
"{",
"'migrate'",
":",
"run_migrate",
",",
"'init'",
":",
"run_init",
",",
"'send_nologin'",
":",
"run_send_nologin",
",",
"'send_all'",
":",
"run_send_all",
",",
"'review'",
":",
"run_review",
",",
... | Command entry | [
"Command",
"entry"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/script/command.py#L24-L74 |
bukun/TorCMS | torcms/model/entity2user_model.py | MEntity2User.create_entity2user | def create_entity2user(enti_uid, user_id):
'''
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()
) | python | def create_entity2user(enti_uid, user_id):
'''
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",
")",
":",
"record",
"=",
"TabEntity2User",
".",
"select",
"(",
")",
".",
"where",
"(",
"(",
"TabEntity2User",
".",
"entity_id",
"==",
"enti_uid",
")",
"&",
"(",
"TabEntity2User",
".",
"user_id",
... | create entity2user record in the database. | [
"create",
"entity2user",
"record",
"in",
"the",
"database",
"."
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/entity2user_model.py#L66-L84 |
bukun/TorCMS | torcms/script/tmplchecker/__init__.py | check_html | def check_html(html_file, begin):
'''
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 | python | def check_html(html_file, begin):
'''
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",
")",
":",
"sig",
"=",
"False",
"for",
"html_line",
"in",
"open",
"(",
"html_file",
")",
".",
"readlines",
"(",
")",
":",
"# uu = x.find('{% extends')",
"uuu",
"=",
"pack_str",
"(",
"html_line",
")",
".",... | Checking the HTML | [
"Checking",
"the",
"HTML"
] | train | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/script/tmplchecker/__init__.py#L39-L94 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.