Compare commits
2 Commits
343bb26536
...
ce68bc9786
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce68bc9786 | ||
|
|
383db050c2 |
51
app.py
51
app.py
@ -24,6 +24,36 @@ login_manager.login_view = 'login'
|
|||||||
login_manager.init_app(app)
|
login_manager.init_app(app)
|
||||||
|
|
||||||
|
|
||||||
|
def rgb_to_hex(rgb_string):
|
||||||
|
# Split the RGB string into individual components
|
||||||
|
rgb_list = rgb_string.split(',')
|
||||||
|
|
||||||
|
# Convert each component to an integer
|
||||||
|
r = int(rgb_list[0])
|
||||||
|
g = int(rgb_list[1])
|
||||||
|
b = int(rgb_list[2])
|
||||||
|
|
||||||
|
# Convert the integers to hexadecimal strings and concatenate them
|
||||||
|
hex_string = "#{:02x}{:02x}{:02x}".format(r, g, b)
|
||||||
|
|
||||||
|
return hex_string
|
||||||
|
|
||||||
|
def hex_to_rgb(hex_string):
|
||||||
|
# Remove the '#' character if present
|
||||||
|
hex_string = hex_string.lstrip('#')
|
||||||
|
|
||||||
|
# Convert the hexadecimal string to integers
|
||||||
|
r = int(hex_string[0:2], 16)
|
||||||
|
g = int(hex_string[2:4], 16)
|
||||||
|
b = int(hex_string[4:6], 16)
|
||||||
|
|
||||||
|
# Create the RGB string
|
||||||
|
rgb_string = "{},{},{}".format(r, g, b)
|
||||||
|
|
||||||
|
return rgb_string
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@login_manager.user_loader
|
@login_manager.user_loader
|
||||||
def load_user(user_id):
|
def load_user(user_id):
|
||||||
return User.get(user_id)
|
return User.get(user_id)
|
||||||
@ -297,12 +327,12 @@ def habit_list_create():
|
|||||||
@app.route('/profile')
|
@app.route('/profile')
|
||||||
@login_required
|
@login_required
|
||||||
def profile():
|
def profile():
|
||||||
print(current_user.name, current_user.email)
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"profile.html",
|
"profile.html",
|
||||||
name=current_user.name,
|
name=current_user.name,
|
||||||
email=current_user.email,
|
email=current_user.email,
|
||||||
profile_image_url=current_user.profile_image,
|
profile_image_url=current_user.profile_image,
|
||||||
|
color = rgb_to_hex(current_user.heatmap_color),
|
||||||
title="Profil",
|
title="Profil",
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -324,6 +354,7 @@ def profile_change():
|
|||||||
name=current_user.name,
|
name=current_user.name,
|
||||||
email=current_user.email,
|
email=current_user.email,
|
||||||
profile_image_url=current_user.profile_image,
|
profile_image_url=current_user.profile_image,
|
||||||
|
color=rgb_to_hex(current_user.heatmap_color),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -468,6 +499,7 @@ def password_change():
|
|||||||
name=current_user.name,
|
name=current_user.name,
|
||||||
email=current_user.email,
|
email=current_user.email,
|
||||||
profile_image_url=current_user.profile_image,
|
profile_image_url=current_user.profile_image,
|
||||||
|
color=rgb_to_hex(current_user.heatmap_color),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -541,6 +573,23 @@ def upload_profile_image():
|
|||||||
return redirect(url_for('profile'))
|
return redirect(url_for('profile'))
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/save_color', methods=['POST'])
|
||||||
|
def save_heatmap_color():
|
||||||
|
# Get the color value from the form
|
||||||
|
new_color = request.form['color']
|
||||||
|
current_user.heatmap_color = hex_to_rgb(new_color)
|
||||||
|
current_user.update()
|
||||||
|
|
||||||
|
# Back to profile
|
||||||
|
return render_template(
|
||||||
|
"profile.html",
|
||||||
|
name=current_user.name,
|
||||||
|
email=current_user.email,
|
||||||
|
profile_image_url=current_user.profile_image,
|
||||||
|
color=rgb_to_hex(current_user.heatmap_color),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/check', methods=['POST'])
|
@app.route('/check', methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def check_habit():
|
def check_habit():
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
// Get elements
|
// Get elements
|
||||||
const profileImage = document.getElementById("profileImage");
|
const profileImage = document.getElementById("profileImage");
|
||||||
|
|||||||
@ -31,6 +31,15 @@
|
|||||||
Bearbeiten
|
Bearbeiten
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<form id="colorForm" action="/save_color" method="POST">
|
||||||
|
<div class="ml-5" style="margin-left: 50px;">
|
||||||
|
<h5 class="card-title">Heatmap Farbe</h5>
|
||||||
|
<div style="display: flex; align-items: center;">
|
||||||
|
<input type="color" name="color" class="form-control form-control-color" id="exampleColorInput" value="{{color}}" title="Choose your color" style="margin-right: 10px;">
|
||||||
|
<button type="submit" class="btn btn-primary">Speichern</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user