Skip to content
Snippets Groups Projects
Commit 1f786c1c authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Refactor QR Codes page

parent 06693cea
No related branches found
No related tags found
No related merge requests found
......@@ -102,17 +102,18 @@ def view_item(ics_id):
return render_template('view_item.html', item=item.to_dict(long=True))
@bp.route('/qrcodes')
@bp.route('/qrcodes/<kind>')
@login_required
def qrcodes():
codes = {}
for model in (models.Action, models.Manufacturer, models.Model, models.Location, models.Status):
items = db.session.query(model).order_by(model.name)
images = [{'name': item.name,
'data': utils.image_to_base64(item.image())}
for item in items]
codes[model.__name__] = images
return render_template('qrcodes.html', codes=codes)
def qrcodes(kind='Action'):
try:
model = getattr(models, kind)
except AttributeError:
raise utils.CSEntryError(f"Unknown model '{kind}'", status_code=422)
items = db.session.query(model).order_by(model.name)
images = [{'name': item.name,
'data': utils.image_to_base64(item.image())}
for item in items]
return render_template('qrcodes.html', kind=kind, images=images)
@bp.route('/attributes', methods=('GET', 'POST'))
......
......@@ -26,7 +26,7 @@
<a class="nav-item nav-link {{ is_active(path.startswith("/items")) }}" href="{{ url_for('main.list_items') }}">Items</a>
<a class="nav-item nav-link {{ is_active(path.startswith("/hosts")) }}" href="{{ url_for('main.list_hosts') }}">Hosts</a>
<a class="nav-item nav-link {{ is_active(path.startswith("/attributes")) }}" href="{{ url_for('main.attributes') }}">Attributes</a>
<a class="nav-item nav-link {{ is_active(path.startswith("/qrcodes")) }}" href="{{ url_for('main.qrcodes') }}">QR Codes</a>
<a class="nav-item nav-link {{ is_active(path.startswith("/qrcodes")) }}" href="{{ url_for('main.qrcodes', kind='Action') }}">QR Codes</a>
{% if current_user.is_authenticated and current_user.is_admin %}
<a class="nav-item nav-link" href="{{ url_for('admin.index') }}">Admin</a>
{% endif %}
......
......@@ -3,10 +3,16 @@
{% block title %}QR Codes - CSEntry{% endblock %}
{% block main %}
{% for name, images in codes.items() %}
<div class="row">
<h2>{{ name }} codes</h2>
</div>
<ul class="nav nav-tabs">
{% for item in ('Action', 'Manufacturer', 'Model', 'Location', 'Status') %}
<li class="nav-item">
<a class="nav-link {% if kind == item %}active{% endif %}" href="{{ url_for('main.qrcodes', kind=item) }}">{{ item }}</a>
</li>
{% endfor %}
</ul>
<br>
<div class="row">
{% for image in images %}
<div class="col-md-3">
......@@ -19,6 +25,4 @@
</div>
{% endfor %}
</div>
<hr class="separator">
{% endfor %}
{%- endblock %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment