Browse Source

account: small trophy improvements on #10

master
Lephe 5 months ago
parent
commit
43264d9de1

+ 5
- 2
app/models/trophies.py View File

@@ -1,11 +1,13 @@
from app import db

# Trophy: Achievements granted to users for performing specific actions
class Trophy(db.Model):
__tablename__ = 'trophy'

id = db.Column(db.Integer, primary_key=True)
# Trophy type (polymorphic discriminator)
type = db.Column(db.String(20))

__mapper_args__ = {
'polymorphic_identity': __tablename__,
'polymorphic_on': type
@@ -19,13 +21,14 @@ class Trophy(db.Model):
def __init__(self, name):
self.name = name

# Title: Rare trophies that can be displayed along one's name
class Title(Trophy):
__tablename__ = 'title'
__mapper_args__ = {'polymorphic_identity': __tablename__}

id = db.Column(db.Integer, db.ForeignKey('trophy.id'), primary_key=True)
title = db.Column(db.Unicode(64))
css = db.Column(db.Text(convert_unicode=True))
css = db.Column(db.UnicodeText)

def __init__(self, name, title, css):
self.name = name

+ 2
- 1
app/routes/admin/trophies.py View File

@@ -61,11 +61,12 @@ def adm_delete_trophy(trophy_id):
del_form = DeleteTrophyForm()
if request.method == "POST":
if del_form.validate_on_submit():
# TODO: Remove relationship with users that have the trophy
db.session.delete(trophy)
db.session.commit()
flash('Trophée supprimé', 'ok')
return redirect(url_for('adm_trophies'))
else:
flash('Erreur lors de la suppression du trophée', 'error')
del_form.delete.data = False # Force to tick to delete the account
del_form.delete.data = False # Force to tick to delete the trophy
return render('admin/delete_trophy.html', trophy=trophy, del_form=del_form)

+ 2
- 2
app/templates/admin/index.html View File

@@ -8,8 +8,8 @@
<section>
<p>Pages générales du panneau d'administration :</p>
<ul>
<li><a href="{{ url_for('adm_groups') }}">Groupes et privilèges</a></li>
<li><a href="{{ url_for('adm_trophies') }}">Titres et trophées</a></li>
<li><a href="{{ url_for('adm_groups') }}">Groupes et privilèges</a></li>
<li><a href="{{ url_for('adm_trophies') }}">Titres et trophées</a></li>
</ul>
</section>
{% endblock %}

+ 4
- 4
app/templates/admin/trophies.html View File

@@ -11,7 +11,7 @@
<h2>Titres et trophées</h2>

<table style="width:90%; margin: auto;">
<tr><th>id</th><th>Icône</th><th>Nom</th><th>Titre</th>
<tr><th>ID</th><th>Icône</th><th>Nom</th><th>Titre</th>
<th>Style</th><th>Modifier</th><th>Supprimer</th></tr>

{% for trophy in trophies %}
@@ -19,7 +19,7 @@
<td><img src="{{ url_for('static', filename='images/account-circle.svg') }}" alt="{{ trophy.name }}"></td>
<td>{{ trophy.name }}</td>
<td style="{{ trophy.css }}">{{ trophy.title }}</td>
<td>{{ trophy.css }}</td>
<td><code>{{ trophy.css }}</code></td>
<td><a href="{{ url_for('adm_edit_trophy', trophy_id=trophy.id) }}">Modifier</a></td>
<td><a href="{{ url_for('adm_delete_trophy', trophy_id=trophy.id) }}">Supprimer</a></td>
</tr>
@@ -40,16 +40,16 @@
</div>
<div>
{{ form.title.label }}
{{ form.title }}
<div class=desc>{{ form.title.description }}</div>
{{ form.title }}
{% for error in form.title.errors %}
<span class="msgerror">{{ error }}</span>
{% endfor %}
</div>
<div>
{{ form.css.label }}
{{ form.css }}
<div class=desc>{{ form.css.description }}</div>
{{ form.css }}
{% for error in form.css.errors %}
<span class="msgerror">{{ error }}</span>
{% endfor %}

Loading…
Cancel
Save