Skip to content

Commit

Permalink
Fix code and add text display for progress bars
Browse files Browse the repository at this point in the history
  • Loading branch information
lulunac27a committed Oct 12, 2024
1 parent e5f6ac5 commit cbdb167
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def get_xp_required(self):
"""
return self.xp_required

def get_level_progress(self):
"""
Get the level progress as a percentage.
"""
return (self.xp / self.xp_required) * 100


@app.route("/")
def index():
Expand Down
10 changes: 8 additions & 2 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ <h1>Flask User Level XP System</h1>
<ul>
{{ user.username }}:<br />
Level {{ user.level }}<br />
{{ user.xp }} / {{ user.xp_required }} XP<br />
<progress value="{{ user.xp }}" max="{{ user.xp_required }}"></progress>
{{ user.xp | round }} / {{ user.get_xp_required() | round }} XP<br />
<progress
value="{{ user.xp | round }}"
max="{{ user.get_xp_required() | round }}"
>
{{ user.get_level_progress() | round(2) }}%
</progress>
<form
action="{{ url_for('add_xp', user_id=user.id, amount=1) }}"
method="post"
>
<input type="hidden" name="amount" value="1" />
<button type="submit">Add XP</button>
</form>
</ul>
Expand Down

0 comments on commit cbdb167

Please sign in to comment.