1
+ """
2
+ Generates default index page UI.
3
+ """
4
+
1
5
import datetime
2
6
import re
3
7
from html import escape , unescape
4
8
import psycopg2
5
9
import psycopg2 .extras
6
- from bottle import route , request , get , post , response
10
+ from bottle import request , get , response
7
11
from math import ceil
8
12
from bs4 import BeautifulSoup
9
13
import hashlib
@@ -104,25 +108,25 @@ def do_tags():
104
108
tags = [t [0 ] for t in tags_qry ]
105
109
if request .get_cookie ('tasti_bmarks_per_page' ):
106
110
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' )):
108
112
user_num_bmarks = request .query .get ('num' )
109
113
# 190 days until expiration
110
114
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 )
112
116
limit_sql = ' LIMIT {}' .format (user_num_bmarks )
113
- marker_dict = get_markers (user_num_bmarks )
117
+ marker_dict = get_markers (user_num_bmarks )
114
118
# pagination setup
115
119
page = 1
116
120
if request .query .get ('page' ):
117
121
page = int (request .query .get ('page' ))
118
122
prev = int (page ) - 1
119
- next = int (page ) + 1
123
+ next = int (page ) + 1 # pylint: W0622
120
124
max_results = user_num_bmarks
121
125
# Calculate the offset
122
126
from_offset = (int (page ) * int (max_results )) - int (max_results )
123
127
url_get_base = 'tags?{u}' .format (u = request .environ .get ('QUERY_STRING' ))
124
128
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 } ' "
126
130
if username and request .query .get ('mine' ) and request .query .get ('mine' ) == 'yes' :
127
131
bmarks_sql_base += " AND owner='{u}' " .format (u = username )
128
132
mine = '&mine=yes'
@@ -142,9 +146,9 @@ def do_tags():
142
146
num_bmarks = len (bmarks_qry )
143
147
if num_bmarks :
144
148
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>'''
148
152
# only render the bmarks/page menu on the 'MY BOOKMARKS' page
149
153
if hash_check ():
150
154
return_data += '''<TD valign="top"><div id="menu">
@@ -172,13 +176,13 @@ def do_tags():
172
176
notes = escape (bmark_row [4 ].replace ('&quot;' , '"' ).replace ('&#039;' , "'" ), quote = True )
173
177
name = bmark_row [5 ].replace ('&quot;' , '"' ).replace ('&#039;' , "'" )
174
178
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>'
176
180
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
- | <A HREF="bmarks?id={i }&func=del"><B>DELETE</B></a> </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
+ | <A HREF="bmarks?id={ bm_id } &func=del"><B>DELETE</B></a> </span>'''
179
183
else :
180
- bmark_user_edit_string = '''<BR><span class="normal">Created by <A HREF="bmarks?whose={o}">
181
- <B>{o }</B></a> </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> </span>'''
182
186
return_data += '''<TABLE><TR>
183
187
<TD valign="top" width="95"><span class="big">{l} </span></TD>
184
188
<TD><span class="big"><A HREF="{u}">{n}</a></span>{no}{b}</TD>
@@ -199,9 +203,9 @@ def do_tags():
199
203
t = tag_get )
200
204
# Create a NEXT link if one is needed
201
205
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>→</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>→</H1></span></A>'''
205
209
else :
206
210
# adjust the total count when on the last page since
207
211
# it might not have user_num_bmarks items remaining
@@ -210,11 +214,9 @@ def do_tags():
210
214
plural = ''
211
215
if my_row_count :
212
216
plural = 's'
213
- return_data += '''<TABLE width="100%"><TR COLSPAN="1"><TD> </TD></TR>
214
- <TR><TD COLSPAN="9"> {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> </TD></TR>
218
+ <TR><TD COLSPAN="9"> { my_row_count } Tasti bookmark{ plural } </TD>
219
+ <TD class="page" COLSPAN="4"><B>{ pagination } </B></TD></TR></TABLE><BR>'''
218
220
else :
219
221
return_data += 'No tags selected.<BR><BR><BR>'
220
222
return return_data
@@ -224,7 +226,7 @@ def do_bmarks():
224
226
"""Bookmark content."""
225
227
return_data = ''
226
228
auth = auth_check ()
227
-
229
+
228
230
if auth ['is_authenticated' ] and auth ['username' ] and request .query .get ('func' ) and request .query .get ('id' ):
229
231
username = auth ['username' ]
230
232
bmark_id = request .query .get ('id' )
@@ -313,7 +315,7 @@ def show_bmarks():
313
315
return_data = ''
314
316
if request .get_cookie ('tasti_bmarks_per_page' ):
315
317
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' )):
317
319
user_num_bmarks = request .query .get ('num' )
318
320
# 190 days until expiration
319
321
cookie_expire = datetime .datetime .now () + datetime .timedelta (days = 190 )
@@ -501,7 +503,7 @@ def add_bmark_form(username):
501
503
tags_sql = "SELECT tag FROM tags WHERE owner='{u}' ORDER BY tag LIMIT 150" .format (u = username )
502
504
tags_qry = db_qry ([tags_sql , None ], 'select' )
503
505
# 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>
505
507
<FORM method="POST" action="add" id="add_bmark"><TABLE>'''
506
508
return_data += '''<TR><TD>Name/Description*: </TD>
507
509
<TD> </TD>
@@ -531,7 +533,7 @@ def add_bmark_form(username):
531
533
if tags_qry :
532
534
tag_counter = 0
533
535
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
535
537
pre-existing tags to the new bookmark above:</span><BR><BR>'''
536
538
for raw_tag_name in tags_qry :
537
539
tag_name = unescape (raw_tag_name [0 ]).strip ()
@@ -744,7 +746,7 @@ def generate_tabs():
744
746
t = tag_selected ,
745
747
c = ie_comment )
746
748
return return_data
747
-
749
+
748
750
749
751
def tag_rename (username , form_dict ):
750
752
"""Handle tag rename change."""
@@ -869,7 +871,7 @@ def bmark_import_form():
869
871
<INPUT type="submit" name="save" value="IMPORT" />
870
872
</CENTER></FORM><BR></div>'''
871
873
return return_data
872
-
874
+
873
875
874
876
def account_details_form (username ):
875
877
"""Render account details form content."""
@@ -928,7 +930,7 @@ def edit_tags(username):
928
930
return_data += '<BR>No tags found<BR>'
929
931
return return_data
930
932
if not tag_list_qry [0 ]:
931
- return_data += '''<BR><span class="huge"> You do not have any tags to edit at this time.
933
+ return_data += '''<BR><span class="huge"> You do not have any tags to edit at this time.
932
934
Try <A HREF="add">adding</a> a bookmark to create new tags</span><BR><BR><BR>'''
933
935
return return_data
934
936
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():
975
977
auth = auth_check ()
976
978
if auth ['username' ] and hash_check ():
977
979
password = ''
978
- name = ''
979
980
email = ''
980
981
fullname = ''
981
982
username = auth ['username' ]
@@ -1010,6 +1011,7 @@ def account_mgmt():
1010
1011
if script == 'account' :
1011
1012
return_data += account_details_form (username )
1012
1013
elif script == 'import' :
1014
+ bmark_file_data = ''
1013
1015
if request .method == 'POST' :
1014
1016
bmark_file_data = request .files .get ('upload_bmark' )
1015
1017
if request .method == 'POST' and bmark_file_data and bmark_file_data .file :
@@ -1212,8 +1214,6 @@ def hash_check():
1212
1214
hash_qry = db_qry ([hash_sql , None ], 'select' )
1213
1215
if len (hash_qry ) and hash_qry [0 ]:
1214
1216
return hash_qry
1215
- else :
1216
- return None
1217
1217
1218
1218
1219
1219
def db_qry (sql_pl , operation ):
0 commit comments