Implemented more generic themes options, allowing between 'default' and 'darkly' themes
This commit is contained in:
parent
61f5080910
commit
1dab258335
5 changed files with 26 additions and 15 deletions
13
Tweeder.py
13
Tweeder.py
|
@ -68,7 +68,7 @@ def profile(name=None):
|
|||
posts = list(timeline.user_posts_by_username(name))
|
||||
return render_template('profile.html',
|
||||
user=accounts.account_details(name),
|
||||
logged_in=logged_in, darktheme=accounts.get_dark_theme(logged_in),
|
||||
logged_in=logged_in, theme=accounts.get_theme(logged_in),
|
||||
following=accounts.is_following(logged_in, name),
|
||||
posts=posts)
|
||||
|
||||
|
@ -108,7 +108,10 @@ def user_settings():
|
|||
if 'username' in session.keys():
|
||||
logged_in = accounts.account_details(session['username'])['displayname']
|
||||
account = accounts.account_details(session['username'])
|
||||
return render_template('settings.html', logged_in=logged_in, account=account)
|
||||
return render_template('settings.html',
|
||||
logged_in=logged_in,
|
||||
account=account,
|
||||
theme=accounts.get_theme(session['username'].lower()))
|
||||
else:
|
||||
return redirect(url_for('login'))
|
||||
elif request.method == "POST":
|
||||
|
@ -119,10 +122,12 @@ def user_settings():
|
|||
'gender': request.form['gender'],
|
||||
'location': request.form['location']
|
||||
}
|
||||
darktheme = request.form['darktheme']
|
||||
if request.form['theme'] == "darkly":
|
||||
accounts.set_theme(session['username'].lower(), "darkly")
|
||||
elif request.form['theme'] == "default":
|
||||
accounts.set_theme(session['username'].lower(), "default")
|
||||
username = session['username']
|
||||
accounts.update_profile(username, profile)
|
||||
accounts.set_dark_theme(username, darktheme)
|
||||
return redirect(url_for('profile'))
|
||||
|
||||
|
||||
|
|
|
@ -5,14 +5,14 @@ client = MongoClient()
|
|||
accounts_db = client.tweeder.accounts
|
||||
|
||||
|
||||
def get_dark_theme(username):
|
||||
def get_theme(username):
|
||||
username = username.lower()
|
||||
return accounts_db.find_one({"username": username})['darktheme']
|
||||
return accounts_db.find_one({"username": username})['theme']
|
||||
|
||||
|
||||
def set_dark_theme(username, value):
|
||||
def set_theme(username, value):
|
||||
username = username.lower()
|
||||
accounts_db.update_one({'username': username}, {"$set": {"darktheme": value}})
|
||||
accounts_db.update_one({'username': username}, {"$set": {"theme": value}})
|
||||
|
||||
|
||||
def get_display_name(username):
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<script src="{{ url_for('static', filename = 'jquery-3.2.1.min.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename = 'bootstrap4.min.js') }}" ></script>
|
||||
<script src="{{ url_for('static', filename ='fontawesome-all.js') }}"></script>
|
||||
{% if darktheme %}<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename = 'dark.css') }}"></script>{% endif %}
|
||||
{% if theme=="darkly" %}<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename = 'darkly.css') }}" />{% endif %}
|
||||
<title>{{ title }} - Tweeder</title>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -27,12 +27,18 @@
|
|||
<input type="text" name="gender" class="form-control" placeholder="Gender" aria-describedby="basic-addon1" value="{{ account.profile.gender }}">
|
||||
</div>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<div class="custom-control custom-checkbox">
|
||||
<input type="checkbox" class="custom-control-input" id="customCheck1" name="darktheme" {% if account.darktheme %}checked{% endif %}>
|
||||
<label class="custom-control-label" for="customCheck1">Use Dark Theme</label>
|
||||
</div>
|
||||
</div>
|
||||
<h2>Site Theme</h2>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<div class="custom-control custom-radio custom-control-inline">
|
||||
<input type="radio" id="customRadioInline1" name="theme" value="default" class="custom-control-input" {% if theme=="default" %}checked{% endif %}>
|
||||
<label class="custom-control-label" for="customRadioInline1">Default</label>
|
||||
</div>
|
||||
<div class="custom-control custom-radio custom-control-inline">
|
||||
<input type="radio" id="customRadioInline2" name="theme" value="darkly" class="custom-control-input" {% if theme=="darkly" %}checked{% endif %}>
|
||||
<label class="custom-control-label" for="customRadioInline2">Darkly</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue