forked from devs/PCv5
Modification de la zone d'admin des comptes
Retrait de la liste déroulante au profit d'une liste de checkbox. Il faudra ajouter les icones.
This commit is contained in:
parent
95efa36228
commit
7f640a13e9
|
@ -51,7 +51,7 @@ class AdminUpdateAccountForm(FlaskForm):
|
|||
|
||||
|
||||
class AdminAccountEditTrophyForm(FlaskForm):
|
||||
trophies = [BooleanField(t.name, validators=[Optional()]) for t in Trophy.query.all()]
|
||||
# Boolean inputs are generated on-the-fly from trophies list
|
||||
submit = SubmitField('Modifier')
|
||||
|
||||
|
||||
|
|
|
@ -210,7 +210,7 @@ class Member(User, db.Model):
|
|||
the right to do this!
|
||||
"""
|
||||
if type(t) == int:
|
||||
t = Trophy.get(t)
|
||||
t = Trophy.query.get(t)
|
||||
if type(t) == str:
|
||||
t = Trophy.query.filter_by(name=t).first()
|
||||
if t not in self.trophies:
|
||||
|
@ -225,6 +225,8 @@ class Member(User, db.Model):
|
|||
Add a trophy to the current user. Check whether the request sender has
|
||||
the right to do this!
|
||||
"""
|
||||
if type(t) == int:
|
||||
t = Trophy.query.get(t)
|
||||
if type(t) == str:
|
||||
t = Trophy.query.filter_by(name=name).first()
|
||||
if t in self.trophies:
|
||||
|
|
|
@ -16,11 +16,13 @@ def adm_edit_account(user_id):
|
|||
|
||||
form = AdminUpdateAccountForm(prefix="user")
|
||||
|
||||
for t in Trophy.query.all():
|
||||
setattr(AdminAccountEditTrophyForm, "t" + str(t.id), BooleanField(t.name))
|
||||
trophy_form = AdminAccountEditTrophyForm(prefix="trophy")
|
||||
class TrophyForm(AdminAccountEditTrophyForm):
|
||||
pass
|
||||
|
||||
print(trophy_form.t22)
|
||||
for t in Trophy.query.all():
|
||||
setattr(TrophyForm, f't{t.id}', BooleanField(t.name))
|
||||
setattr(TrophyForm, "user_trophies", [f't{t.id}' for t in user.trophies])
|
||||
trophy_form = TrophyForm(prefix="trophies")
|
||||
|
||||
if form.submit.data:
|
||||
if form.validate_on_submit():
|
||||
|
@ -51,12 +53,15 @@ def adm_edit_account(user_id):
|
|||
|
||||
if trophy_form.submit.data:
|
||||
if trophy_form.validate_on_submit():
|
||||
trophies = [(t.label, t.data) for t in trophy_form.trophies]
|
||||
for t, set in trophies:
|
||||
if set:
|
||||
user.add_trophy(t)
|
||||
else:
|
||||
user.del_trophy(t)
|
||||
for id, field in trophy_form.__dict__.items():
|
||||
if id[0] == "t":
|
||||
print(f"id: {id[1:]}, name: {field.label}, checked={field.data}", end=" ")
|
||||
if field.data:
|
||||
print(f"Add trophy {id[1:]}")
|
||||
user.add_trophy(int(id[1:]))
|
||||
else:
|
||||
print(f"Del trophy {id[1:]}")
|
||||
user.del_trophy(int(id[1:]))
|
||||
else:
|
||||
flash("Erreur lors de l'ajout du trophée", 'error')
|
||||
|
||||
|
@ -69,8 +74,8 @@ def adm_edit_account(user_id):
|
|||
# else:
|
||||
# flash("Erreur lors du retrait du trophée", 'error')
|
||||
|
||||
return render('admin/edit_account.html', user=user, form=form,
|
||||
trophy_form=trophy_form)
|
||||
return render('admin/edit_account.html', user=user,
|
||||
form=form, trophy_form=trophy_form)
|
||||
|
||||
|
||||
@app.route('/admin/account/<user_id>/delete', methods=['GET', 'POST'])
|
||||
|
|
|
@ -65,3 +65,15 @@
|
|||
font-size: 80%;
|
||||
color: gray;
|
||||
}
|
||||
|
||||
.trophies-panel {
|
||||
display: flex; flex-wrap: wrap;
|
||||
}
|
||||
.trophies-panel > div {
|
||||
margin: 3px 5px; padding: 3px;
|
||||
border: 1px solid #969696;
|
||||
border-radius: 3px;
|
||||
}
|
||||
.trophies-panel label {
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
|
|
@ -95,27 +95,19 @@
|
|||
{{ trophy_form.hidden_tag() }}
|
||||
<h2>Trophées</h2>
|
||||
<div class="trophies-panel">
|
||||
{% for trophy in trophy_form.trophies %}
|
||||
{{ trophy.label }}
|
||||
{{ trophy }}
|
||||
{% for id, input in trophy_form.__dict__.items() %}
|
||||
{% if id[0] == "t" %}
|
||||
<div>
|
||||
{# TODO: add trophies icons #}
|
||||
{{ input(checked=id in trophy_form.user_trophies) }}
|
||||
{{ input.label }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div>{{ trophy_form.submit(class_="bg-green") }}</div>
|
||||
</form>
|
||||
|
||||
{# <form action="{{ url_for('adm_edit_account', user_id=user.id) }}" method="post">
|
||||
{{ deltrophy_form.hidden_tag() }}
|
||||
<h2>Retirer un trophée</h2>
|
||||
<div>
|
||||
{{ deltrophy_form.trophy.label }}
|
||||
{{ deltrophy_form.trophy }}
|
||||
{% for error in deltrophy_form.trophy.errors %}
|
||||
<span class="msgerror">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div>{{ deltrophy_form.submit(class_="bg-red") }}</div>
|
||||
</form> #}
|
||||
|
||||
<h2 style="margin-top:30px;">Supprimer le compte</h2>
|
||||
<a href="{{ url_for('adm_delete_account', user_id=user.id) }}" class="button bg-red">Supprimer le compte</a>
|
||||
|
||||
|
|
Loading…
Reference in New Issue