Skip to content

Commit dc54c98

Browse files
committed
* linting cleanup
1 parent d2f8e7e commit dc54c98

File tree

2 files changed

+40
-38
lines changed

2 files changed

+40
-38
lines changed

index.py

+32-32
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
"""
2+
Generates default index page UI.
3+
"""
4+
15
import datetime
26
import re
37
from html import escape, unescape
48
import psycopg2
59
import psycopg2.extras
6-
from bottle import route, request, get, post, response
10+
from bottle import request, get, response
711
from math import ceil
812
from bs4 import BeautifulSoup
913
import hashlib
@@ -104,25 +108,25 @@ def do_tags():
104108
tags = [t[0] for t in tags_qry]
105109
if request.get_cookie('tasti_bmarks_per_page'):
106110
bmarks_per_page = request.get_cookie('tasti_bmarks_per_page')
107-
if request.query.get('num') and re.match('\d', request.query.get('num')):
111+
if request.query.get('num') and re.match(r'\d', request.query.get('num')):
108112
user_num_bmarks = request.query.get('num')
109113
# 190 days until expiration
110114
cookie_expire = datetime.datetime.now() + datetime.timedelta(days=190)
111-
response.set_cookie('tasti_bmarks_per_page', user_num_bmarks, expires=cookie_expire)
115+
response.set_cookie('tasti_bmarks_per_page', user_num_bmarks, expires=cookie_expire)
112116
limit_sql = ' LIMIT {}'.format(user_num_bmarks)
113-
marker_dict = get_markers(user_num_bmarks)
117+
marker_dict = get_markers(user_num_bmarks)
114118
# pagination setup
115119
page = 1
116120
if request.query.get('page'):
117121
page = int(request.query.get('page'))
118122
prev = int(page) - 1
119-
next = int(page) + 1
123+
next = int(page) + 1 # pylint: W0622
120124
max_results = user_num_bmarks
121125
# Calculate the offset
122126
from_offset = (int(page) * int(max_results)) - int(max_results)
123127
url_get_base = 'tags?{u}'.format(u=request.environ.get('QUERY_STRING'))
124128
tag = tags[0]
125-
bmarks_sql_base = "SELECT id, date(last_update) as last_update, owner, url, notes, name FROM bmarks WHERE tag='{t}' ".format(t=tag)
129+
bmarks_sql_base = f"SELECT id, date(last_update) as last_update, owner, url, notes, name FROM bmarks WHERE tag='{tag}' "
126130
if username and request.query.get('mine') and request.query.get('mine') == 'yes':
127131
bmarks_sql_base += " AND owner='{u}' ".format(u=username)
128132
mine = '&mine=yes'
@@ -142,9 +146,9 @@ def do_tags():
142146
num_bmarks = len(bmarks_qry)
143147
if num_bmarks:
144148
left_td_width = 100 - (22 + len(tag))
145-
return_data += '''<TABLE width="100%"><TR>
146-
<TD width="{lw}%">
147-
<span class="huge">Bookmarks tagged with <B>{t}</B></span></TD>'''.format(lw=left_td_width, t=tag)
149+
return_data += f'''<TABLE width="100%"><TR>
150+
<TD width="{left_td_width}%">
151+
<span class="huge">Bookmarks tagged with <B>{tag}</B></span></TD>'''
148152
# only render the bmarks/page menu on the 'MY BOOKMARKS' page
149153
if hash_check():
150154
return_data += '''<TD valign="top"><div id="menu">
@@ -172,13 +176,13 @@ def do_tags():
172176
notes = escape(bmark_row[4].replace('&amp;quot;', '"').replace('&amp;#039;', "'"), quote=True)
173177
name = bmark_row[5].replace('&amp;quot;', '"').replace('&amp;#039;', "'")
174178
if notes:
175-
notes_string = '<BR><span class="small"><B>{n}</B></span>'.format(n=notes)
179+
notes_string = f'<BR><span class="small"><B>{notes}</B></span>'
176180
if hash_check() and owner == username:
177-
bmark_user_edit_string = '''<BR><A HREF="edit?id={i}&func=edit"><span class="normal"><B>EDIT</B></a>
178-
&nbsp;|&nbsp;<A HREF="bmarks?id={i}&func=del"><B>DELETE</B></a>&nbsp;</span>'''.format(i=bm_id)
181+
bmark_user_edit_string = f'''<BR><A HREF="edit?id={i}&func=edit"><span class="normal"><B>EDIT</B></a>
182+
&nbsp;|&nbsp;<A HREF="bmarks?id={bm_id}&func=del"><B>DELETE</B></a>&nbsp;</span>'''
179183
else:
180-
bmark_user_edit_string = '''<BR><span class="normal">Created by <A HREF="bmarks?whose={o}">
181-
<B>{o}</B></a>&nbsp;</span>'''.format(o=owner)
184+
bmark_user_edit_string = f'''<BR><span class="normal">Created by <A HREF="bmarks?whose={o}">
185+
<B>{owner}</B></a>&nbsp;</span>'''
182186
return_data += '''<TABLE><TR>
183187
<TD valign="top" width="95"><span class="big">{l}&nbsp;&nbsp;&nbsp;</span></TD>
184188
<TD><span class="big"><A HREF="{u}">{n}</a></span>{no}{b}</TD>
@@ -199,9 +203,9 @@ def do_tags():
199203
t=tag_get)
200204
# Create a NEXT link if one is needed
201205
if page < total_pages:
202-
pagination += '''<A STYLE="text-decoration:none" title="NEXT PAGE" HREF="tags?{m}&page={n}&num={u}{t}">
203-
<span class="huge"><H1>&rarr;</H1></span></A>'''.format(m=mine, n=next, u=user_num_bmarks,
204-
t=tag_get)
206+
pagination += f'''<A STYLE="text-decoration:none" title="NEXT PAGE"
207+
HREF="tags?{mine}&page={next}&num={user_num_bmarks}{tag_get}">
208+
<span class="huge"><H1>&rarr;</H1></span></A>'''
205209
else:
206210
# adjust the total count when on the last page since
207211
# it might not have user_num_bmarks items remaining
@@ -210,11 +214,9 @@ def do_tags():
210214
plural = ''
211215
if my_row_count:
212216
plural = 's'
213-
return_data += '''<TABLE width="100%"><TR COLSPAN="1"><TD>&nbsp;</TD></TR>
214-
<TR><TD COLSPAN="9">&nbsp;{m} Tasti bookmark{p}</TD>
215-
<TD class="page" COLSPAN="4"><B>{pa}</B></TD></TR></TABLE><BR>'''.format(m=my_row_count,
216-
p=plural,
217-
pa=pagination)
217+
return_data += f'''<TABLE width="100%"><TR COLSPAN="1"><TD>&nbsp;</TD></TR>
218+
<TR><TD COLSPAN="9">&nbsp;{my_row_count} Tasti bookmark{plural}</TD>
219+
<TD class="page" COLSPAN="4"><B>{pagination}</B></TD></TR></TABLE><BR>'''
218220
else:
219221
return_data += 'No tags selected.<BR><BR><BR>'
220222
return return_data
@@ -224,7 +226,7 @@ def do_bmarks():
224226
"""Bookmark content."""
225227
return_data = ''
226228
auth = auth_check()
227-
229+
228230
if auth['is_authenticated'] and auth['username'] and request.query.get('func') and request.query.get('id'):
229231
username = auth['username']
230232
bmark_id = request.query.get('id')
@@ -313,7 +315,7 @@ def show_bmarks():
313315
return_data = ''
314316
if request.get_cookie('tasti_bmarks_per_page'):
315317
bmarks_per_page = request.get_cookie('tasti_bmarks_per_page')
316-
if request.query.get('num') and re.match('\d', request.query.get('num')):
318+
if request.query.get('num') and re.match(r'\d', request.query.get('num')):
317319
user_num_bmarks = request.query.get('num')
318320
# 190 days until expiration
319321
cookie_expire = datetime.datetime.now() + datetime.timedelta(days=190)
@@ -501,7 +503,7 @@ def add_bmark_form(username):
501503
tags_sql = "SELECT tag FROM tags WHERE owner='{u}' ORDER BY tag LIMIT 150".format(u=username)
502504
tags_qry = db_qry([tags_sql, None], 'select')
503505
# generate add bookmark form
504-
return_data += '''<span class="huge">Add a new bookmark to <B>Tasti</B>:</span><BR><BR>
506+
return_data += '''<span class="huge">Add a new bookmark to <B>Tasti</B>:</span><BR><BR>
505507
<FORM method="POST" action="add" id="add_bmark"><TABLE>'''
506508
return_data += '''<TR><TD>Name/Description*:&nbsp;</TD>
507509
<TD>&nbsp;</TD>
@@ -531,7 +533,7 @@ def add_bmark_form(username):
531533
if tags_qry:
532534
tag_counter = 0
533535
max_tags_per_row = 10
534-
return_data += '''<span class="big">Click below to add one (or more) of your
536+
return_data += '''<span class="big">Click below to add one (or more) of your
535537
pre-existing tags to the new bookmark above:</span><BR><BR>'''
536538
for raw_tag_name in tags_qry:
537539
tag_name = unescape(raw_tag_name[0]).strip()
@@ -744,7 +746,7 @@ def generate_tabs():
744746
t=tag_selected,
745747
c=ie_comment)
746748
return return_data
747-
749+
748750

749751
def tag_rename(username, form_dict):
750752
"""Handle tag rename change."""
@@ -869,7 +871,7 @@ def bmark_import_form():
869871
<INPUT type="submit" name="save" value="IMPORT" />
870872
</CENTER></FORM><BR></div>'''
871873
return return_data
872-
874+
873875

874876
def account_details_form(username):
875877
"""Render account details form content."""
@@ -928,7 +930,7 @@ def edit_tags(username):
928930
return_data += '<BR>No tags found<BR>'
929931
return return_data
930932
if not tag_list_qry[0]:
931-
return_data += '''<BR><span class="huge">&nbsp;You do not have any tags to edit at this time.
933+
return_data += '''<BR><span class="huge">&nbsp;You do not have any tags to edit at this time.
932934
Try <A HREF="add">adding</a> a bookmark to create new tags</span><BR><BR><BR>'''
933935
return return_data
934936
return_data += '''<BR><span class="huge">Edit the tags that you wish to rename, or check the tags that you wish to delete:</span>
@@ -975,7 +977,6 @@ def account_mgmt():
975977
auth = auth_check()
976978
if auth['username'] and hash_check():
977979
password = ''
978-
name = ''
979980
email = ''
980981
fullname = ''
981982
username = auth['username']
@@ -1010,6 +1011,7 @@ def account_mgmt():
10101011
if script == 'account':
10111012
return_data += account_details_form(username)
10121013
elif script == 'import':
1014+
bmark_file_data = ''
10131015
if request.method == 'POST':
10141016
bmark_file_data = request.files.get('upload_bmark')
10151017
if request.method == 'POST' and bmark_file_data and bmark_file_data.file:
@@ -1212,8 +1214,6 @@ def hash_check():
12121214
hash_qry = db_qry([hash_sql, None], 'select')
12131215
if len(hash_qry) and hash_qry[0]:
12141216
return hash_qry
1215-
else:
1216-
return None
12171217

12181218

12191219
def db_qry(sql_pl, operation):

tastiapp.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
from bottle import route, template, error, request, static_file, get, post
1+
"""
2+
Top level app routing definitions.
3+
"""
4+
from bottle import route, error, static_file, get
25
from index import get_index
36
from bmarks import get_bmarks
47
from tags import get_tags
58
from add import add_tags
69
from bmarklet import get_bmarklet
7-
from account import get_account
810
from edit_tags import get_edit_tags
911
from importbm import get_import_bm
1012
from edit import do_edit
@@ -67,22 +69,22 @@ def bmarks():
6769
return return_data
6870

6971
# serve css
70-
@get('/<filename:re:.*\.css>')
72+
@get(r'/<filename:re:.*\.css>')
7173
def send_css(filename):
7274
return static_file(filename, root='css')
7375

7476
# serve javascript
75-
@get('/<filename:re:.*\.js>')
77+
@get(r'/<filename:re:.*\.js>')
7678
def send_js(filename):
7779
return static_file(filename, root='js')
7880

7981
# serve images
80-
@get('<filename:re:.*\.png>')
82+
@get(r'<filename:re:.*\.png>')
8183
def send_img(filename):
8284
return static_file(filename, root='images')
8385

8486
# serve fonts
85-
@get('<filename:re:.*\.(woff|woff2)>')
87+
@get(r'<filename:re:.*\.(woff|woff2)>')
8688
def send_font(filename):
8789
return static_file(filename, root='fonts')
8890

0 commit comments

Comments
 (0)