Ajouter des données fictives aux aperçus
Some checks are pending
CI - Tests et Syntax / lint-and-test (push) Waiting to run
Some checks are pending
CI - Tests et Syntax / lint-and-test (push) Waiting to run
This commit is contained in:
parent
c4db4a1e12
commit
b1f1e8b604
4 changed files with 48 additions and 3 deletions
|
|
@ -452,6 +452,7 @@ def template_debug_preview():
|
||||||
from jinja2 import ChoiceLoader, FileSystemLoader, TemplateNotFound, ChainableUndefined
|
from jinja2 import ChoiceLoader, FileSystemLoader, TemplateNotFound, ChainableUndefined
|
||||||
|
|
||||||
relative_path = (request.args.get('path') or '').strip()
|
relative_path = (request.args.get('path') or '').strip()
|
||||||
|
demo_mode = request.args.get('demo', '1') != '0'
|
||||||
files, _ = _template_inventory()
|
files, _ = _template_inventory()
|
||||||
item = next((candidate for candidate in files if candidate['path'] == relative_path), None)
|
item = next((candidate for candidate in files if candidate['path'] == relative_path), None)
|
||||||
if not item:
|
if not item:
|
||||||
|
|
@ -481,12 +482,44 @@ def template_debug_preview():
|
||||||
# Reproduire les variables globales Flask (current_user, config,
|
# Reproduire les variables globales Flask (current_user, config,
|
||||||
# request...) sans injecter d'objet métier réel dans la prévisualisation.
|
# request...) sans injecter d'objet métier réel dans la prévisualisation.
|
||||||
current_app.update_template_context(preview_context)
|
current_app.update_template_context(preview_context)
|
||||||
|
if demo_mode:
|
||||||
|
from types import SimpleNamespace
|
||||||
|
|
||||||
|
class DemoObject(SimpleNamespace):
|
||||||
|
def __getattr__(self, name):
|
||||||
|
return ''
|
||||||
|
|
||||||
|
demo_room = DemoObject(id=12, name='B102', code='B102', full_name='Bâtiment principal — Zone Anglais — B102')
|
||||||
|
demo_equipment = DemoObject(
|
||||||
|
id=42, name='Luminaire LED central', code='ECL-0042',
|
||||||
|
full_path='Bâtiment principal / Zone Anglais / B102 / Éclairage',
|
||||||
|
room=demo_room, status='en_service', status_label='En service',
|
||||||
|
)
|
||||||
|
preview_context.update({
|
||||||
|
'current_user': DemoObject(id=1, username='demo.admin', full_name='Administrateur démo', role='admin', role_label='Administrateur système', is_authenticated=True),
|
||||||
|
'stats': DemoObject(alerts_unread=3, interventions_pending=4, equipments=128),
|
||||||
|
'unread': 3,
|
||||||
|
'alerts': [DemoObject(id=1, title='Luminaire défaillant', message='Une intervention est à traiter.', level='warning')],
|
||||||
|
'interventions': [DemoObject(id=39, title='Remplacement du luminaire', status='en_cours', status_label='En cours', room=demo_room, equipment=demo_equipment)],
|
||||||
|
'intervention': DemoObject(id=39, title='Remplacement du luminaire', type='curatif', status='en_cours', status_label='En cours', room=demo_room, equipment=demo_equipment),
|
||||||
|
'rooms': [demo_room, DemoObject(id=13, name='B103', code='B103', full_name='Bâtiment principal — Zone Anglais — B103')],
|
||||||
|
'equipments': [demo_equipment, DemoObject(id=43, name='Prise murale fond de salle', code='ELEC-0043', room=demo_room)],
|
||||||
|
'categories': [DemoObject(id=1, name='Éclairage'), DemoObject(id=2, name='Prises')],
|
||||||
|
'buildings': [DemoObject(id=1, name='Bâtiment principal')],
|
||||||
|
'zones': [DemoObject(id=1, name='Zone Anglais')],
|
||||||
|
'messages': [DemoObject(subject='Demande de réparation', sender='Vie scolaire', body_preview='Une chaise est cassée en B102.')],
|
||||||
|
'mails': [DemoObject(subject='Maintenance urgente', sender='service@exemple.fr', received_at='21/08/2026 08:15')],
|
||||||
|
'tasks': [DemoObject(id=7, name='Contrôle mensuel des luminaires', periodicity='Mensuelle', duration_minutes=30)],
|
||||||
|
'lots': [DemoObject(id=3, name='Éclairage intérieur', category=DemoObject(name='Éclairage'))],
|
||||||
|
'companies': [DemoObject(id=2, name='Entreprise Démo Maintenance')],
|
||||||
|
})
|
||||||
rendered = template.render(**preview_context)
|
rendered = template.render(**preview_context)
|
||||||
except (TemplateNotFound, Exception) as exc:
|
except (TemplateNotFound, Exception) as exc:
|
||||||
render_error = f'{type(exc).__name__}: {exc}'
|
render_error = f'{type(exc).__name__}: {exc}'
|
||||||
|
|
||||||
return render_template('admin/template_preview.html', template=item,
|
return render_template('admin/template_preview.html', template=item,
|
||||||
source=source, rendered=rendered, render_error=render_error)
|
source=source, rendered=rendered, render_error=render_error,
|
||||||
|
demo_mode=demo_mode)
|
||||||
|
|
||||||
|
|
||||||
@admin_bp.route('/debug/templates/mark', methods=['POST'])
|
@admin_bp.route('/debug/templates/mark', methods=['POST'])
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@
|
||||||
{% else %}<span class="badge bg-warning text-dark">Masqué probablement</span>{% endif %}
|
{% else %}<span class="badge bg-warning text-dark">Masqué probablement</span>{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td><code title="{{ template.hash }}">{{ template.hash[:10] }}</code></td>
|
<td><code title="{{ template.hash }}">{{ template.hash[:10] }}</code></td>
|
||||||
<td><a class="btn btn-outline-primary btn-sm" href="{{ url_for('admin.template_debug_preview', path=template.path) }}" target="_blank" rel="noopener"><i class="bi bi-eye"></i> Prévisualiser</a></td>
|
<td><a class="btn btn-outline-primary btn-sm" href="{{ url_for('admin.template_debug_preview', path=template.path, demo=1) }}" target="_blank" rel="noopener"><i class="bi bi-eye"></i> Prévisualiser</a></td>
|
||||||
<td>
|
<td>
|
||||||
<form method="post" action="{{ url_for('admin.template_debug_mark') }}" class="d-flex gap-1">
|
<form method="post" action="{{ url_for('admin.template_debug_mark') }}" class="d-flex gap-1">
|
||||||
<input type="hidden" name="path" value="{{ template.path }}">
|
<input type="hidden" name="path" value="{{ template.path }}">
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,17 @@
|
||||||
<a href="{{ url_for('admin.template_debug', filter='all') }}" class="btn btn-outline-secondary btn-sm"><i class="bi bi-arrow-left"></i> Retour à l’audit</a>
|
<a href="{{ url_for('admin.template_debug', filter='all') }}" class="btn btn-outline-secondary btn-sm"><i class="bi bi-arrow-left"></i> Retour à l’audit</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="alert {% if demo_mode %}alert-success{% else %}alert-secondary{% endif %} py-2 d-flex flex-wrap gap-2 justify-content-between align-items-center">
|
||||||
|
<span><i class="bi bi-{% if demo_mode %}magic{% else %}braces{% endif %}"></i>
|
||||||
|
{% if demo_mode %}<strong>Données fictives actives.</strong> Le rendu utilise un contexte GMAO de démonstration, sans écriture en base.{% else %}<strong>Contexte vide.</strong> Les variables métier absentes sont tolérées.{% endif %}
|
||||||
|
</span>
|
||||||
|
{% if demo_mode %}
|
||||||
|
<a class="btn btn-sm btn-outline-secondary" href="{{ url_for('admin.template_debug_preview', path=template.path, demo=0) }}">Tester sans données</a>
|
||||||
|
{% else %}
|
||||||
|
<a class="btn btn-sm btn-outline-success" href="{{ url_for('admin.template_debug_preview', path=template.path, demo=1) }}">Charger les données fictives</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
{% if render_error %}
|
{% if render_error %}
|
||||||
<div class="alert alert-warning">
|
<div class="alert alert-warning">
|
||||||
<strong><i class="bi bi-exclamation-triangle"></i> Rendu incomplet</strong>
|
<strong><i class="bi bi-exclamation-triangle"></i> Rendu incomplet</strong>
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,11 @@ def test_template_audit_can_mark_and_restore_without_deleting(authenticated_clie
|
||||||
assert 'Identiques' in response.get_data(as_text=True)
|
assert 'Identiques' in response.get_data(as_text=True)
|
||||||
assert 'Divergents' in response.get_data(as_text=True)
|
assert 'Divergents' in response.get_data(as_text=True)
|
||||||
|
|
||||||
response = authenticated_client.get('/admin/debug/templates/preview?path=templates%2Fadmin%2Ftemplate_debug.html')
|
response = authenticated_client.get('/admin/debug/templates/preview?path=templates%2Fadmin%2Ftemplate_debug.html&demo=1')
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert 'Prévisualisation du template' in response.get_data(as_text=True)
|
assert 'Prévisualisation du template' in response.get_data(as_text=True)
|
||||||
assert 'sandbox' in response.get_data(as_text=True)
|
assert 'sandbox' in response.get_data(as_text=True)
|
||||||
|
assert 'Données fictives actives' in response.get_data(as_text=True)
|
||||||
|
|
||||||
response = authenticated_client.post('/admin/debug/templates/mark', data={
|
response = authenticated_client.post('/admin/debug/templates/mark', data={
|
||||||
'path': template_path,
|
'path': template_path,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue