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

Theme support, with default 'green'

This commit is contained in:
2017-07-22 21:11:09 +02:00
parent 133a139b79
commit 652e3a89af
5 changed files with 63 additions and 28 deletions

View File

@@ -15,6 +15,25 @@ from flask_peewee.db import Database
#from flask_peewee.utils import get_object_or_404
from peewee import * # noqa
themes = {
'green': {
'BODY': 'grey lighten-4',
'NAV': 'green darken-3',
'PAGEHEADER': 'grey-text lighten-5',
'MESSAGE_BACKGROUND': 'orange lighten-2',
'MESSAGE_TEXT': 'white-text',
'ERRORMESSAGE_BACKGROUND': 'red darken-1',
'ERRORMESSAGE_TEXT': 'white-text',
'CARD_BACKGROUND': 'green darken-3',
'CARD_TEXT': 'white-text',
'FAB': 'red',
'STAR': 'yellow-text',
'PROBLEM': 'red-text',
'COMMENT': '',
}
}
try:
import settings
except ImportError:
@@ -294,6 +313,14 @@ def get_cached_tags(userkey):
return []
def get_theme(userkey):
try:
usertheme = settings[userkey]['theme']
return themes[usertheme]
except KeyError:
return themes['green'] # default
def make_external(url):
return urljoin(request.url_root, url)
@@ -306,7 +333,8 @@ def page_not_found(e):
@app.route('/')
def index():
""" Homepage, point visitors to project page """
return render_template('index.html')
default_theme = themes['green']
return render_template('index.html', theme=default_theme)
@app.route('/<userkey>', methods=['GET', 'POST'])
@@ -355,7 +383,8 @@ def bookmarks(userkey, filtermethod = None, sortmethod = None):
else:
bookmarks = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.status == Bookmark.VISIBLE).order_by(Bookmark.created_date.desc())
return render_template('bookmarks.html', bookmarks=bookmarks, userkey=userkey, tags=tags, filter_text=filter_text, message=message)
theme = get_theme(userkey)
return render_template('bookmarks.html', bookmarks=bookmarks, userkey=userkey, tags=tags, filter_text=filter_text, message=message, theme=theme)
@@ -387,7 +416,8 @@ def editbookmark(userkey, urlhash):
if not bookmark.note:
# Workaround for when an existing bookmark has a null note
bookmark.note = ''
return render_template('edit.html', action='Edit bookmark', userkey=userkey, bookmark=bookmark, message=message, formaction='edit', tags=tags)
theme = get_theme(userkey)
return render_template('edit.html', action='Edit bookmark', userkey=userkey, bookmark=bookmark, message=message, formaction='edit', tags=tags, theme=theme)
@app.route('/<userkey>/add')
@@ -401,7 +431,8 @@ def addbookmark(userkey):
bookmark = Bookmark(title='', url=url, tags='')
message = request.args.get('message')
tags = get_cached_tags(userkey)
return render_template('edit.html', action='Add bookmark', userkey=userkey, bookmark=bookmark, tags=tags, message=message)
theme = get_theme(userkey)
return render_template('edit.html', action='Add bookmark', userkey=userkey, bookmark=bookmark, tags=tags, message=message, theme=theme)
def updatebookmark(userkey, request, urlhash = None):
@@ -529,9 +560,10 @@ def tags(userkey):
totaldeleted = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.status == Bookmark.DELETED).count()
totalnotes = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.note != '').count()
totalhttperrorstatus = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.http_status != 200).count()
theme = get_theme(userkey)
return render_template('tags.html', tags=alltags, totaltags=totaltags, totalpublic=totalpublic, totalbookmarks=totalbookmarks,
totaldeleted=totaldeleted, totalstarred=totalstarred, totalhttperrorstatus=totalhttperrorstatus,
totalnotes=totalnotes, userkey=userkey)
totalnotes=totalnotes, userkey=userkey, theme=theme)
@app.route('/<userkey>/tag/<tag>')
@@ -547,7 +579,8 @@ def tag(userkey, tag):
except PublicTag.DoesNotExist:
publictag = None
return render_template('bookmarks.html', bookmarks=bookmarks, userkey=userkey, tags=tags, tag=tag, publictag=publictag, action=pageheader, message=message)
theme = get_theme(userkey)
return render_template('bookmarks.html', bookmarks=bookmarks, userkey=userkey, tags=tags, tag=tag, publictag=publictag, action=pageheader, message=message, theme=theme)
@app.route('/pub/<tagkey>')
@@ -557,7 +590,8 @@ def publictag(tagkey):
try:
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())
return render_template('publicbookmarks.html', bookmarks=bookmarks, tag=tag, action=this_tag.tag, tagkey=tagkey)
theme = get_theme(userkey)
return render_template('publicbookmarks.html', bookmarks=bookmarks, tag=tag, action=this_tag.tag, tagkey=tagkey, theme=theme)
except PublicTag.DoesNotExist:
abort(404)