1
0
mirror of https://github.com/aquatix/digimarks.git synced 2025-12-06 23:05:10 +01:00

Lots of indentation and other readability & lintian fixes

This commit is contained in:
2018-03-17 16:14:52 +01:00
parent 88eee28b88
commit 1e14163d42

View File

@@ -363,18 +363,16 @@ class Bookmark(BaseModel):
else: else:
return [] return []
def to_dict(self): def to_dict(self):
result = { result = {
'title': self.title, 'title': self.title,
'url': self.url, 'url': self.url,
'created': self.created_date.strftime('%Y-%m-%d %H:%M:%S'), 'created': self.created_date.strftime('%Y-%m-%d %H:%M:%S'),
'url_hash': self.url_hash, 'url_hash': self.url_hash,
'tags': self.tags, 'tags': self.tags,
} }
return result return result
@property @property
def serialize(self): def serialize(self):
return self.to_dict() return self.to_dict()
@@ -467,7 +465,7 @@ def get_bookmarks(userkey, filtermethod=None, sortmethod=None):
Bookmark.status == Bookmark.VISIBLE).order_by(Bookmark.created_date.desc()) Bookmark.status == Bookmark.VISIBLE).order_by(Bookmark.created_date.desc())
elif filter_starred: elif filter_starred:
bookmarks = Bookmark.select().where(Bookmark.userkey == userkey, bookmarks = Bookmark.select().where(Bookmark.userkey == userkey,
Bookmark.starred == True).order_by(Bookmark.created_date.desc()) Bookmark.starred).order_by(Bookmark.created_date.desc())
elif filter_broken: elif filter_broken:
bookmarks = Bookmark.select().where(Bookmark.userkey == userkey, bookmarks = Bookmark.select().where(Bookmark.userkey == userkey,
Bookmark.http_status != 200).order_by(Bookmark.created_date.desc()) Bookmark.http_status != 200).order_by(Bookmark.created_date.desc())
@@ -475,7 +473,10 @@ def get_bookmarks(userkey, filtermethod=None, sortmethod=None):
bookmarks = Bookmark.select().where(Bookmark.userkey == userkey, bookmarks = Bookmark.select().where(Bookmark.userkey == userkey,
Bookmark.note != '').order_by(Bookmark.created_date.desc()) Bookmark.note != '').order_by(Bookmark.created_date.desc())
else: else:
bookmarks = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.status == Bookmark.VISIBLE).order_by(Bookmark.created_date.desc()) bookmarks = Bookmark.select().where(
Bookmark.userkey == userkey,
Bookmark.status == Bookmark.VISIBLE
).order_by(Bookmark.created_date.desc())
return bookmarks, bookmarktags, filter_text, message return bookmarks, bookmarktags, filter_text, message
@@ -486,16 +487,17 @@ def get_bookmarks(userkey, filtermethod=None, sortmethod=None):
def bookmarks_page(userkey, filtermethod=None, sortmethod=None): def bookmarks_page(userkey, filtermethod=None, sortmethod=None):
bookmarks, bookmarktags, filter_text, message = get_bookmarks(userkey, filtermethod, sortmethod) bookmarks, bookmarktags, filter_text, message = get_bookmarks(userkey, filtermethod, sortmethod)
theme = get_theme(userkey) theme = get_theme(userkey)
return render_template('bookmarks.html', return render_template(
bookmarks=bookmarks, 'bookmarks.html',
userkey=userkey, bookmarks=bookmarks,
tags=bookmarktags, userkey=userkey,
filter_text=filter_text, tags=bookmarktags,
message=message, filter_text=filter_text,
theme=theme, message=message,
editable=True, # bookmarks can be edited theme=theme,
showtags=True, # tags should be shown with the bookmarks editable=True, # bookmarks can be edited
) showtags=True, # tags should be shown with the bookmarks
)
@app.route('/api/v1/<userkey>', methods=['GET', 'POST']) @app.route('/api/v1/<userkey>', methods=['GET', 'POST'])
@@ -525,7 +527,11 @@ def bookmarks_json(userkey, filtermethod=None, sortmethod=None):
@app.route('/<userkey>/<urlhash>/json') @app.route('/<userkey>/<urlhash>/json')
def viewbookmarkjson(userkey, urlhash): def viewbookmarkjson(userkey, urlhash):
""" Serialise bookmark to json """ """ Serialise bookmark to json """
bookmark = Bookmark.select(Bookmark.url_hash == urlhash, Bookmark.userkey == userkey, Bookmark.status == Bookmark.VISIBLE)[0] bookmark = Bookmark.select(
Bookmark.url_hash == urlhash,
Bookmark.userkey == userkey,
Bookmark.status == Bookmark.VISIBLE
)[0]
return jsonify(bookmark.to_dict()) return jsonify(bookmark.to_dict())
@@ -544,7 +550,16 @@ def editbookmark(userkey, urlhash):
# Workaround for when an existing bookmark has a null note # Workaround for when an existing bookmark has a null note
bookmark.note = '' bookmark.note = ''
theme = get_theme(userkey) theme = get_theme(userkey)
return render_template('edit.html', action='Edit bookmark', userkey=userkey, bookmark=bookmark, message=message, formaction='edit', tags=tags, theme=theme) return render_template(
'edit.html',
action='Edit bookmark',
userkey=userkey,
bookmark=bookmark,
message=message,
formaction='edit',
tags=tags,
theme=theme
)
@app.route('/<userkey>/add') @app.route('/<userkey>/add')
@@ -559,7 +574,15 @@ def addbookmark(userkey):
message = request.args.get('message') message = request.args.get('message')
tags = get_cached_tags(userkey) tags = get_cached_tags(userkey)
theme = get_theme(userkey) theme = get_theme(userkey)
return render_template('edit.html', action='Add bookmark', userkey=userkey, bookmark=bookmark, tags=tags, message=message, theme=theme) return render_template(
'edit.html',
action='Add bookmark',
userkey=userkey,
bookmark=bookmark,
tags=tags,
message=message,
theme=theme
)
def updatebookmark(userkey, request, urlhash = None): def updatebookmark(userkey, request, urlhash = None):
@@ -647,11 +670,15 @@ def editingbookmark(userkey, urlhash):
@app.route('/<userkey>/<urlhash>/delete', methods=['GET', 'POST']) @app.route('/<userkey>/<urlhash>/delete', methods=['GET', 'POST'])
def deletingbookmark(userkey, urlhash): def deletingbookmark(userkey, urlhash):
""" Delete the bookmark from form submit by <urlhash>/delete """ """ Delete the bookmark from form submit by <urlhash>/delete """
query = Bookmark.update(status=Bookmark.DELETED).where(Bookmark.userkey==userkey, Bookmark.url_hash==urlhash) query = Bookmark.update(status=Bookmark.DELETED).where(Bookmark.userkey == userkey, Bookmark.url_hash == urlhash)
query.execute() query.execute()
query = Bookmark.update(deleted_date = datetime.datetime.now()).where(Bookmark.userkey==userkey, Bookmark.url_hash==urlhash) query = Bookmark.update(deleted_date = datetime.datetime.now()).where(Bookmark.userkey == userkey, Bookmark.url_hash == urlhash)
query.execute() query.execute()
message = 'Bookmark deleted. <a href="{}">Undo deletion</a>'.format(url_for('undeletebookmark', userkey=userkey, urlhash=urlhash)) message = 'Bookmark deleted. <a href="{}">Undo deletion</a>'.format(url_for(
'undeletebookmark',
userkey=userkey,
urlhash=urlhash
))
all_tags[userkey] = get_tags_for_user(userkey) all_tags[userkey] = get_tags_for_user(userkey)
return redirect(url_for('bookmarks', userkey=userkey, message=message)) return redirect(url_for('bookmarks', userkey=userkey, message=message))
@@ -659,7 +686,7 @@ def deletingbookmark(userkey, urlhash):
@app.route('/<userkey>/<urlhash>/undelete') @app.route('/<userkey>/<urlhash>/undelete')
def undeletebookmark(userkey, urlhash): def undeletebookmark(userkey, urlhash):
""" Undo deletion of the bookmark identified by urlhash """ """ Undo deletion of the bookmark identified by urlhash """
query = Bookmark.update(status=Bookmark.VISIBLE).where(Bookmark.userkey==userkey, Bookmark.url_hash==urlhash) query = Bookmark.update(status=Bookmark.VISIBLE).where(Bookmark.userkey == userkey, Bookmark.url_hash == urlhash)
query.execute() query.execute()
message = 'Bookmark restored' message = 'Bookmark restored'
all_tags[userkey] = get_tags_for_user(userkey) all_tags[userkey] = get_tags_for_user(userkey)
@@ -678,25 +705,43 @@ def tags(userkey):
except PublicTag.DoesNotExist: except PublicTag.DoesNotExist:
publictag = None publictag = None
total = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.tags.contains(tag), Bookmark.status == Bookmark.VISIBLE).count() total = Bookmark.select().where(
Bookmark.userkey == userkey,
Bookmark.tags.contains(tag),
Bookmark.status == Bookmark.VISIBLE
).count()
alltags.append({'tag': tag, 'publictag': publictag, 'total': total}) alltags.append({'tag': tag, 'publictag': publictag, 'total': total})
totaltags = len(alltags) totaltags = len(alltags)
totalbookmarks = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.status == Bookmark.VISIBLE).count() totalbookmarks = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.status == Bookmark.VISIBLE).count()
totalpublic = PublicTag.select().where(PublicTag.userkey == userkey).count() totalpublic = PublicTag.select().where(PublicTag.userkey == userkey).count()
totalstarred = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.starred == True).count() totalstarred = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.starred).count()
totaldeleted = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.status == Bookmark.DELETED).count() totaldeleted = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.status == Bookmark.DELETED).count()
totalnotes = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.note != '').count() totalnotes = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.note != '').count()
totalhttperrorstatus = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.http_status != 200).count() totalhttperrorstatus = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.http_status != 200).count()
theme = get_theme(userkey) theme = get_theme(userkey)
return render_template('tags.html', tags=alltags, totaltags=totaltags, totalpublic=totalpublic, totalbookmarks=totalbookmarks, return render_template(
totaldeleted=totaldeleted, totalstarred=totalstarred, totalhttperrorstatus=totalhttperrorstatus, 'tags.html',
totalnotes=totalnotes, userkey=userkey, theme=theme) tags=alltags,
totaltags=totaltags,
totalpublic=totalpublic,
totalbookmarks=totalbookmarks,
totaldeleted=totaldeleted,
totalstarred=totalstarred,
totalhttperrorstatus=totalhttperrorstatus,
totalnotes=totalnotes,
userkey=userkey,
theme=theme
)
@app.route('/<userkey>/tag/<tag>') @app.route('/<userkey>/tag/<tag>')
def tag(userkey, tag): def tag(userkey, tag):
""" Overview of all bookmarks with a certain tag """ """ Overview of all bookmarks with a certain tag """
bookmarks = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.tags.contains(tag), Bookmark.status == Bookmark.VISIBLE).order_by(Bookmark.created_date.desc()) bookmarks = Bookmark.select().where(
Bookmark.userkey == userkey,
Bookmark.tags.contains(tag),
Bookmark.status == Bookmark.VISIBLE
).order_by(Bookmark.created_date.desc())
tags = get_cached_tags(userkey) tags = get_cached_tags(userkey)
pageheader = 'tag: ' + tag pageheader = 'tag: ' + tag
message = request.args.get('message') message = request.args.get('message')
@@ -707,8 +752,17 @@ def tag(userkey, tag):
publictag = None publictag = None
theme = get_theme(userkey) theme = get_theme(userkey)
return render_template('bookmarks.html', bookmarks=bookmarks, userkey=userkey, tags=tags, tag=tag, publictag=publictag, action=pageheader, return render_template(
message=message, theme=theme) 'bookmarks.html',
bookmarks=bookmarks,
userkey=userkey,
tags=tags,
tag=tag,
publictag=publictag,
action=pageheader,
message=message,
theme=theme
)
@app.route('/pub/<tagkey>') @app.route('/pub/<tagkey>')
@@ -717,9 +771,20 @@ def publictag(tagkey):
#this_tag = get_object_or_404(PublicTag.select().where(PublicTag.tagkey == tagkey)) #this_tag = get_object_or_404(PublicTag.select().where(PublicTag.tagkey == tagkey))
try: try:
this_tag = PublicTag.get(PublicTag.tagkey == tagkey) this_tag = PublicTag.get(PublicTag.tagkey == tagkey)
bookmarks = Bookmark.select().where(Bookmark.userkey == this_tag.userkey, Bookmark.tags.contains(this_tag.tag), Bookmark.status == Bookmark.VISIBLE).order_by(Bookmark.created_date.desc()) bookmarks = Bookmark.select().where(
Bookmark.userkey == this_tag.userkey,
Bookmark.tags.contains(this_tag.tag),
Bookmark.status == Bookmark.VISIBLE
).order_by(Bookmark.created_date.desc())
theme = themes[DEFAULT_THEME] theme = themes[DEFAULT_THEME]
return render_template('publicbookmarks.html', bookmarks=bookmarks, tag=tag, action=this_tag.tag, tagkey=tagkey, theme=theme) return render_template(
'publicbookmarks.html',
bookmarks=bookmarks,
tag=tag,
action=this_tag.tag,
tagkey=tagkey,
theme=theme
)
except PublicTag.DoesNotExist: except PublicTag.DoesNotExist:
abort(404) abort(404)
@@ -729,7 +794,11 @@ def publictagjson(tagkey):
""" json representation of the Read-only overview of the bookmarks in the userkey/tag of this PublicTag """ """ json representation of the Read-only overview of the bookmarks in the userkey/tag of this PublicTag """
try: try:
this_tag = PublicTag.get(PublicTag.tagkey == tagkey) this_tag = PublicTag.get(PublicTag.tagkey == tagkey)
bookmarks = Bookmark.select().where(Bookmark.userkey == this_tag.userkey, Bookmark.tags.contains(this_tag.tag), Bookmark.status == Bookmark.VISIBLE) bookmarks = Bookmark.select().where(
Bookmark.userkey == this_tag.userkey,
Bookmark.tags.contains(this_tag.tag),
Bookmark.status == Bookmark.VISIBLE
)
result = {'count': len(bookmarks), 'items': []} result = {'count': len(bookmarks), 'items': []}
for bookmark in bookmarks: for bookmark in bookmarks:
result['items'].append(bookmark.to_dict()) result['items'].append(bookmark.to_dict())
@@ -743,18 +812,24 @@ def publictagfeed(tagkey):
""" rss/atom representation of the Read-only overview of the bookmarks in the userkey/tag of this PublicTag """ """ rss/atom representation of the Read-only overview of the bookmarks in the userkey/tag of this PublicTag """
try: try:
this_tag = PublicTag.get(PublicTag.tagkey == tagkey) this_tag = PublicTag.get(PublicTag.tagkey == tagkey)
bookmarks = Bookmark.select().where(Bookmark.userkey == this_tag.userkey, Bookmark.tags.contains(this_tag.tag), Bookmark.status == Bookmark.VISIBLE).limit(15) bookmarks = Bookmark.select().where(
Bookmark.userkey == this_tag.userkey,
Bookmark.tags.contains(this_tag.tag),
Bookmark.status == Bookmark.VISIBLE
).limit(15)
feed = AtomFeed(this_tag.tag, feed_url=request.url, url=make_external(url_for('publictag', tagkey=tagkey))) feed = AtomFeed(this_tag.tag, feed_url=request.url, url=make_external(url_for('publictag', tagkey=tagkey)))
for bookmark in bookmarks: for bookmark in bookmarks:
updated_date = bookmark.modified_date updated_date = bookmark.modified_date
if not bookmark.modified_date: if not bookmark.modified_date:
updated_date = bookmark.created_date updated_date = bookmark.created_date
feed.add(bookmark.title, feed.add(
content_type='html', bookmark.title,
author='digimarks', content_type='html',
url=bookmark.url, author='digimarks',
updated=updated_date, url=bookmark.url,
published=bookmark.created_date) updated=updated_date,
published=bookmark.created_date
)
return feed.get_response() return feed.get_response()
except PublicTag.DoesNotExist: except PublicTag.DoesNotExist:
abort(404) abort(404)
@@ -780,9 +855,9 @@ def addpublictag(userkey, tag):
message = 'Public link to this tag created' message = 'Public link to this tag created'
return redirect(url_for('tag', userkey=userkey, tag=tag, message=message)) return redirect(url_for('tag', userkey=userkey, tag=tag, message=message))
else:
message = 'Public link already existed' message = 'Public link already existed'
return redirect(url_for('tag', userkey=userkey, tag=tag, message=message)) return redirect(url_for('tag', userkey=userkey, tag=tag, message=message))
@app.route('/<userkey>/<tag>/removepublic/<tagkey>', methods=['GET', 'POST']) @app.route('/<userkey>/<tag>/removepublic/<tagkey>', methods=['GET', 'POST'])