Skip to content

Commit

Permalink
根据pep8修改。
Browse files Browse the repository at this point in the history
  • Loading branch information
bukun committed Jan 19, 2021
1 parent 0e9ae56 commit 676f8f3
Show file tree
Hide file tree
Showing 23 changed files with 51 additions and 67 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# polib Makefile, useful for developers only.
# Make sure you have pep8 and tox python modules installed.
# Makefile, useful for developers only.
# Make sure you have pycodestyle and tox python modules installed.

.PHONY: clean lint test dist

Expand All @@ -21,4 +21,4 @@ test:
dist: clean
@python setup.py register
@python setup.py sdist upload
@python setup.py bdist_wheel upload
@python setup.py bdist_wheel upload
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,17 @@ would generate the picture for the relationship of the template files.
Unit Tests
=========================================

First you should install pytest with ``pip`` ,
First you should install ``pytest``, ``coverage`` and ``pytest-cov`` with ``pip`` ,

::

pip3 install pytest
pip3 install pytest pytest-cov coverage

then run as follow:

::

python3 -m pytest tester
python3 -m pytest tester --cov=./tester --cov-report=html



Expand Down
1 change: 0 additions & 1 deletion doc/BeforeYouPush.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

GitHub中TorCMS代码提交操作规范
=================================

Expand Down
2 changes: 2 additions & 0 deletions doc/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ openpyxl
requests
pytest
coverage
pytest-cov
# css_html_js_minify # replaced with htmlmin since it needs Python 3.6 above.
htmlmin
# celery
Expand All @@ -34,3 +35,4 @@ pylint
selenium
pycodestyle
tox

4 changes: 3 additions & 1 deletion runtest.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh
python3 -m pytest tester

python3 -m pytest tester --cov=./tester --cov-report=html

# if which coverage > /dev/null; then
# coverage run tester
# coverage report
Expand Down
2 changes: 1 addition & 1 deletion torcms/core/base_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from config import kind_arr, post_type


class BaseHandler(tornado.web.RequestHandler):
'''
The base class for handlers.
Expand All @@ -33,7 +34,6 @@ def initialize(self, **kwargs):
self.is_p = False # True, if partially rendered.
self.is_j = False # True, if json would be returned.


def get_post_data(self):
'''
Get all the arguments from post request. Only get the first argument by default.
Expand Down
5 changes: 0 additions & 5 deletions torcms/core/tool/sqlite_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,13 @@ def add(post_id):

ts1d, ts7d, ts30d = ts_helper()


# 使用毫秒作为ID。
millis = int(round(time.time() * 1000))

db_file = './database/log_access.db'
conn = sqlite3.connect(db_file)
cursor = conn.cursor()



try:
cursor.execute('CREATE TABLE TabAccess (uid BIGINT PRIMARY KEY NOT NULL ,'
'post_id VARCHAR(5));')
Expand Down Expand Up @@ -82,8 +79,6 @@ def add(post_id):

conn.commit()



# cursor.execute('SELECT * FROM TabAccess;')
# conn.commit()

Expand Down
8 changes: 4 additions & 4 deletions torcms/core/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ def check_username_valid(username):
>>> check_username_valid('/sadf')
False
>>> check_username_valid('\s.adf')
>>> check_username_valid('\\s.adf')
False
>>> check_username_valid('')
False
>>> check_username_valid(' ')
False
'''
if re.match('^[a-zA-Z][a-zA-Z0-9_]{3,19}', username) != None:
if re.match('^[a-zA-Z][a-zA-Z0-9_]{3,19}', username) is not None:
return True
return False

Expand All @@ -128,8 +128,8 @@ def check_email_valid(email_str):
>>> check_email_valid('[email protected]')
False
'''
if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$",
email_str) != None:
ck_str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"
if re.match(ck_str, email_str) is not None:
return True

return False
Expand Down
4 changes: 1 addition & 3 deletions torcms/handlers/comment_hander.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ def get_pager_idx():
'current_page': current_page_num,
'count': num_of_cat,


}
self.render('static_pages/comment/index.html',
postinfo=MComment.query_pager_by_comment(current_page_num),
userinfo=self.userinfo,
cfg=CMS_CFG,
kwd=kwd,
router_post= router_post)

router_post=router_post)
8 changes: 2 additions & 6 deletions torcms/handlers/entity_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,8 @@ def down(self, down_uid):
userip = self.get_host_ip()

if ment_id:

MEntity2User.create_entity2user(ment_id, self.userinfo.uid, userip)


else:

MEntity.create_entity(uid='', path=down_url, desc='', kind=kind)
ment_id = MEntity.get_id_by_impath(down_url)
if ment_id:
Expand Down Expand Up @@ -208,7 +204,7 @@ def add_pic(self, post_data):
path_save,
post_data['desc'] if 'desc' in post_data else '',
kind=post_data['kind'] if 'kind' in post_data else '1')
if self.entity_ajax == False:
if self.entity_ajax is False:
self.redirect('/entity/{0}_m.jpg'.format(sig_save))
else:
if create_pic:
Expand Down Expand Up @@ -247,7 +243,7 @@ def add_pdf(self, post_data):
path_save = os.path.join(signature[:2], outfilename)
create_pdf = MEntity.create_entity(signature, path_save, img_desc,
kind=post_data['kind'] if 'kind' in post_data else '2')
if self.entity_ajax == False:
if self.entity_ajax is False:
self.redirect('/entity/{0}{1}'.format(sig_save, hou.lower()))
else:
if create_pdf:
Expand Down
7 changes: 3 additions & 4 deletions torcms/handlers/filter_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ def echo_html(self, url_str):
url_arr = self.parse_url(url_str)
sig = url_arr[0]


post_data = self.get_post_data()
sort_option = post_data.get('sort', '')

num = (len(url_arr) - 2) // 2

catinfo = MCategory.get_by_uid(sig)
Expand All @@ -159,10 +158,10 @@ def echo_html(self, url_str):
condition[ckey] = cval

if url_arr[1] == 'con':
infos = MPost.query_list_pager(condition, fenye_num, kind=catinfo.kind,sort_option = sort_option)
infos = MPost.query_list_pager(condition, fenye_num, kind=catinfo.kind, sort_option=sort_option)
self.echo_html_list_str(sig, infos, catinfo)
elif url_arr[1] == 'num':
allinfos = MPost.query_under_condition(condition, kind=catinfo.kind,sort_option = sort_option)
allinfos = MPost.query_under_condition(condition, kind=catinfo.kind, sort_option=sort_option)
self.write(
tornado.escape.xhtml_unescape(
echo_html_fenye_str(
Expand Down
6 changes: 5 additions & 1 deletion torcms/handlers/label_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ def list(self, kind, tag_slug, cur_p=''):
else:
try:
current_page_number = int(cur_p)
except:
except TypeError:
current_page_number = 1
except Exception as e:
print(e.args)
print(str(e))
print(repr(e))

current_page_number = 1 if current_page_number < 1 else current_page_number

Expand Down
2 changes: 0 additions & 2 deletions torcms/handlers/leaf_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ def post(self, *args, **kwargs):
else:
self.show404()


@tornado.web.authenticated
@privilege.auth_edit
def update_order(self, uid, order):
'''
update the order of the posts.
'''
MPost.update_order(uid, order)

2 changes: 0 additions & 2 deletions torcms/handlers/list_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,8 @@ def get_pager_idx():
'kind': cat_rec.kind,
'tag': tag}


# Todo: review the following codes.


if self.order:
tmpl = 'list/catalog_list.html'
else:
Expand Down
3 changes: 1 addition & 2 deletions torcms/handlers/nullify_info_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def get(self, *args, **kwargs):

self.list(url_arr[0], cur_p=url_arr[1])


def list(self, list, **kwargs):
'''
List the replies.
Expand Down Expand Up @@ -45,4 +44,4 @@ def get_pager_idx():
userinfo=self.userinfo,
cfg=CMS_CFG,
kwd=kwd,
router_post= router_post)
router_post=router_post)
7 changes: 4 additions & 3 deletions torcms/handlers/page_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def to_add(self, citiao):
'''
To Add page.
'''
if re.match('^[a-zA-Z][a-zA-Z0-9_]{3,19}', citiao) != None:
if re.match('^[a-zA-Z][a-zA-Z0-9_]{3,19}', citiao) is not None:
kwd = {
'cats': MCategory.query_all(),
'slug': citiao,
Expand All @@ -90,11 +90,12 @@ def to_add(self, citiao):
self.render('wiki_page/page_add.html',
kwd=kwd,
userinfo=self.userinfo)

else:
logger.info(' ' * 4 + 'Slug contains special characters')
kwd = {
'info': 'Slug contains special characters,Slug must be a combination of letters or alphanumeric or alphanumeric underscores (letters).',
'info': '''Slug contains special characters,
Slug must be a combination of letters or
alphanumeric or alphanumeric underscores (letters).''',
'link': '/',
}
self.render('misc/html/404.html',
Expand Down
2 changes: 1 addition & 1 deletion torcms/handlers/post_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def get(self, *args, **kwargs):
self._to_add(uid=url_arr[1])
else:
self._to_add()
elif len(url_arr) == 1 and len(url_str) in [4,5,7,8]:
elif len(url_arr) == 1 and len(url_str) in [4, 5, 7, 8]:
if url_str.startswith('cn_'):
url_str = url_str[3:]
self._view_or_add(url_str)
Expand Down
10 changes: 3 additions & 7 deletions torcms/model/post_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ def add_meta(uid, data_dic, extinfo=None):
return uid

@staticmethod
def query_under_condition(condition, kind='9',sort_option=''):
def query_under_condition(condition, kind='9', sort_option=''):
'''
Get All data of certain kind according to the condition
'''
Expand All @@ -846,13 +846,9 @@ def query_under_condition(condition, kind='9',sort_option=''):
sort_criteria = TabPost.access_30d.desc()
else:
sort_criteria = TabPost.view_count.desc()


else:
sort_criteria = TabPost.time_update.desc()



return TabPost.select().where(
(TabPost.kind == kind) &
(TabPost.valid == 1) &
Expand Down Expand Up @@ -902,12 +898,12 @@ def addata_init(data_dic, ext_dic=None):
)

@staticmethod
def query_list_pager(con, idx, kind='2',sort_option = ''):
def query_list_pager(con, idx, kind='2', sort_option=''):
'''
Get records of certain pager.
'''
if sort_option:
all_list = MPost.query_under_condition(con, kind=kind,sort_option = sort_option)
all_list = MPost.query_under_condition(con, kind=kind, sort_option=sort_option)
else:
all_list = MPost.query_under_condition(con, kind=kind)
return all_list[(idx - 1) * CMS_CFG['list_num']: idx * CMS_CFG['list_num']]
Expand Down
3 changes: 1 addition & 2 deletions torcms/modules/category_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ def render(self, *args, **kwargs):
'glyph': glyph,
'catid': catid,
'cat_id': cat_id

}
if second == False:
if second is False:
return self.render_string(
'modules/category/showsubcat_list.html',
recs=recs,
Expand Down
14 changes: 7 additions & 7 deletions torcms/modules/widget_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class BaiduShare(tornado.web.UIModule):
'''

def render(self, *args, **kwargs):
en = kwargs.get('en',False)
return self.render_string('modules/widget/baidu_share.html',en=en)
en = kwargs.get('en', False)
return self.render_string('modules/widget/baidu_share.html', en=en)


class ReplyPanel(tornado.web.UIModule):
Expand Down Expand Up @@ -64,11 +64,11 @@ def render(self, *args, **kwargs):
router = args[0]
uid = args[1]
userinfo = args[2]
review = kwargs.get('review',True)
delete = kwargs.get('delete',False)
nullify = kwargs.get('nullify',False)
reclass = kwargs.get('reclass',True)
url = kwargs.get('url','')
review = kwargs.get('review', True)
delete = kwargs.get('delete', False)
nullify = kwargs.get('nullify', False)
reclass = kwargs.get('reclass', True)
url = kwargs.get('url', '')
if 'catid' in kwargs:
catid = kwargs['catid']
else:
Expand Down
7 changes: 0 additions & 7 deletions torcms/script/script_init_tabels.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
initialize table.s
'''


from playhouse import migrate
from playhouse.postgres_ext import BinaryJSONField

Expand Down Expand Up @@ -62,12 +61,6 @@ def run_migrate(*args):
migrate.migrate(torcms_migrator.drop_column('tabtag', 'role_mask'))
'''

'''
在psql状态下查询表结构
\d
tablename
'''

try:
conn = config.DB_CON
cur = conn.cursor()
Expand Down
2 changes: 1 addition & 1 deletion torcms/script/script_zero.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def run_zero():
if "'" in DB_CFG['pass']:
print("There should be no ``'`` in password. Be careful.")

the_str = '''CREATE USER {db} WITH PASSWORD '{passwd}' ;
the_str = r'''CREATE USER {db} WITH PASSWORD '{passwd}' ;
CREATE DATABASE {db} OWNER {db} ;
GRANT ALL PRIVILEGES ON DATABASE {db} to {db} ;
\c {db} ;
Expand Down
Loading

0 comments on commit 676f8f3

Please sign in to comment.