Commit de9b8a60 authored by Nicolas Joyard's avatar Nicolas Joyard

Ajout visu attachments depuis l'admin

parent b80c3b38
# -*- coding: utf-8 -*-
EXTENSIONS = {
'pdf': 'application/pdf',
'jpg': 'image/jpeg',
'jpeg': 'image/jpeg',
'png': 'image/png',
}
#
# Lors de la modification de ces énumérations, penser à créer une migration DB
# pour mettre à jour les types ENUM correspondants en base de données.
......
# -*- coding: utf-8 -*-
from flask import render_template
import os
from flask import make_response, render_template
from sqlalchemy.orm import contains_eager, joinedload
from .util import redirect_back, require_admin
from ..models import db, Action, Etape, Parlementaire
from ..models.constants import ETAPE_A_ENVOYER, ETAPE_A_CONFIRMER
from ..models.constants import ETAPE_A_ENVOYER, ETAPE_A_CONFIRMER, EXTENSIONS
def setup_routes(app):
......@@ -72,3 +74,19 @@ def setup_routes(app):
db.session.commit()
return redirect_back()
@app.route('/admin/fichier/<id_action>', endpoint='admin_fichier')
@require_admin
def admin_fichier(id_action):
act = Action.query.filter_by(id=id_action).first()
if not act or not act.attachment:
return not_found()
path = os.path.join(app.config['DATA_DIR'], act.attachment)
ext = path.rsplit('.', 1)[1].lower()
with open(path, 'rb') as fichier:
response = make_response(fichier.read())
response.headers['Content-Type'] = EXTENSIONS[ext]
return response
......@@ -9,15 +9,8 @@ from sqlalchemy.orm import joinedload, contains_eager
from .util import not_found, redirect_back, require_user, slugify
from ..models import db, Action, Etape, Parlementaire
from ..models.constants import ETAPE_A_ENVOYER, ETAPE_A_CONFIRMER, ETAPE_ENVOYE
EXTENSIONS = {
'pdf': 'application/pdf',
'jpg': 'image/jpeg',
'jpeg': 'image/jpeg',
'png': 'image/png',
}
from ..models.constants import (ETAPE_A_ENVOYER, ETAPE_A_CONFIRMER,
ETAPE_ENVOYE, EXTENSIONS)
def pris_en_charge(parl):
......
......@@ -30,7 +30,11 @@
{{ action.nick }} ({{ action.email }}) depuis {{ action.ip }}
{% endif %}
</td>
<td>{{ action.attachment or '' }}</td>
<td>
{% if action.attachment %}
<a class="btn btn-default" href="{{ url_for('admin_fichier', id_action=action.id) }}" target="_blank">{{ action.attachment }}</a>
{% endif %}
</td>
<td>
<a class="btn btn-danger" href="{{ url_for('admin_delete', id=action.id) }}">Supprimer</a>
</td>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment