mise au point creation rdf

This commit is contained in:
2019-03-25 14:20:10 +01:00
parent 22a0fd03fd
commit e408fcc9b0
11 changed files with 126 additions and 142 deletions

View File

@@ -48,9 +48,8 @@ class GlobalLayout(object):
return is_admin
def isWebPage(self):
# get view name
view_name = self.request.matched_route.name
if view_name == 'rdf_rapport':
# test view name
if self.request.matched_route.name == 'rdf_rapport':
# oui, page PDF
return False
else:

View File

@@ -136,12 +136,16 @@ def get_devis_lig_by_no(request,nodossier):
results = request.dbsession.execute(query, {'societe': societe, 'no_id': no_id}).fetchall()
return results
def get_docs_attaches(request, nodossier):
def get_docs_attaches(request, nodossier, norapport, filename):
societe = nodossier[0:2]
nochantier = int(nodossier[3:])
query = "SELECT * FROM dossier_attaches WHERE nomrep = 'DOCS_ATTACHES' AND societe = :societe AND nochantier = :nochantier ORDER BY cree_le;"
results = request.dbsession.execute(query, {'societe': societe, 'nochantier': nochantier}).fetchall()
if filename == '':
query = "SELECT * FROM dossier_attaches WHERE nomrep = 'DOCS_ATTACHES' AND societe = :societe AND nochantier = :nochantier ORDER BY cree_le;"
else:
query = """SELECT * FROM dossier_attaches WHERE nomrep = 'DOCS_ATTACHES' AND societe = :societe AND nochantier = :nochantier
AND nodossier = :norapport AND nomfichier = :filename ORDER BY cree_le;"""
results = request.dbsession.execute(query, {'societe': societe, 'nochantier': nochantier, 'norapport': norapport, 'filename': filename}).fetchall()
return results
@@ -172,8 +176,12 @@ def insert_dossier_attaches(request, nodossier, norapport, filename, filesize, u
societe = nodossier[0:2]
nochantier = int(nodossier[3:])
# fichier existe ?
item = get_docs_attaches(request, nodossier, norapport, filename)
if item:
return
# enregistrer dans la table dossier_attaches
query = """REPLACE INTO dossier_attaches (nomrep, societe, nochantier, nodossier, nomfichier, taillefichier, cree_le, usermaj)
query = """INSERT INTO dossier_attaches (nomrep, societe, nochantier, nodossier, nomfichier, taillefichier, cree_le, usermaj)
VALUES('DOCS_ATTACHES',:societe,:nochantier,:norapport,:filename,:filesize,NOW(),:user);"""
execute_query(request, query, {'societe': societe, 'nochantier': nochantier, 'norapport': norapport, 'filename': filename, 'filesize': filesize, 'user': user})

View File

@@ -181,5 +181,4 @@
width: 350px;
height: 150px;
padding: 20px;
border: 1px solid black;
}

View File

@@ -170,11 +170,11 @@
<div class="panel panel-default" tal:condition="nodossier.startswith('PL')">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#panel-documents">
<a data-toggle="collapse" data-parent="#accordion" href="#panel-rdf">
<span class="glyphicon glyphicon-plus"></span>&nbsp;RECHERCHE DE FUITE</a>
</h4>
</div>
<div id="panel-documents" class="panel-collapse collapse">
<div id="panel-rdf" class="panel-collapse collapse">
<div class="panel-body">
<p>
<a class="btn btn-success" role="button" href="${request.route_url('rdf_edit', nodossier=nodossier, date_inter='new')}">

View File

@@ -16,7 +16,7 @@
<th>Client</th>
<th>No sinistre</th>
<th>Auteur</th>
<th>Numéro</th>
<th>Rapport</th>
</tr>
</thead>
</table>

View File

@@ -252,14 +252,18 @@
<br />
<h4 class="text-center text-primary">PHOTOS</h4>
<br />
<div tal:repeat="detail photos">
<img src="${docs_url}${detail.nomrep}/${detail.societe}/${nochantier}/${norapport}/${detail.nomfichier}" align="center" />
</div>
<p tal:repeat="detail photos">
<img src="${docs_url}${detail.nomrep}/${detail.societe}/${nochantier}/${norapport}/${detail.nomfichier}"
width="800" align="center" />
</p>
<br />
<h4 class="text-center text-primary">CONCLUSIONS</h4>
<div class="form-group">
<br />&nbsp;&nbsp;&nbsp;${rapport.conclusions}
</div>
<br />
<br/>
<br/>
</div> <!-- row -->
<table class="table table-condensed ">
@@ -267,7 +271,7 @@
<td width="40%">
<p>
<label>Date du rapport :</label>
<br />${rapport.modif_le.strftime('%d-%m-%Y')}
<br />${date_rapport}
<br />
<br />
<label>Etabli par :</label>
@@ -285,8 +289,7 @@
</tr>
</table>
<br />
<br/>
<br/>
<script type="text/javascript">
$(document).ready(function() {
//afficher signature

View File

@@ -253,25 +253,27 @@
<span class="glyphicon glyphicon-cloud-upload"></span>&nbsp;Ajouter une photo</a>
</p>
<br />
<div class="fotorama" data-nav="thumbs">
<div tal:repeat="detail photos">
<img src="${docs_url}${detail.nomrep}/${detail.societe}/${nochantier}/${norapport}/${detail.nomfichier}"
data-caption="${detail.nomfichier}" align="center" />
</div>
</div>
<p tal:repeat="detail photos">
<img src="${docs_url}${detail.nomrep}/${detail.societe}/${nochantier}/${norapport}/${detail.nomfichier}"
width="800" align="center" />
</p>
<br />
<h4 class="text-center text-primary">CONCLUSIONS</h4>
<div class="form-group">
<br />&nbsp;&nbsp;&nbsp;${rapport.conclusions}
</div>
<div class="col-sm-6">
<p>
Date du rapport : ${rapport.modif_le.strftime('%d-%m-%Y')}<br />
Etabli par ${rapport.auteur_nom}
</p>
<div class="col-sm-5">
<p>
<label>Date du rapport :</label>
<br />${date_rapport}
<br />
<br />
<label>Etabli par :</label>
<br />${rapport.auteur_nom}
</p>
</div>
<div class="col-sm-6">
<div class="col-sm-7">
<label>Signature du client :</label>
<div tal:condition="not rapport.signature_svg">
<div id="signature"></div>

View File

@@ -29,21 +29,16 @@
</div> <!-- row -->
<h3>Photos déjà téléchargées</h3>
<div class="fotorama" data-nav="thumbs">
<div tal:repeat="detail photos">
<p tal:repeat="detail photos">
<img src="${docs_url}${detail.nomrep}/${detail.societe}/${nochantier}/${norapport}/${detail.nomfichier}"
data-caption="${detail.nomfichier}" align="center" />
</div>
</div>
width="800" align="center" />
</p>
<script type="text/javascript">
$('#uploadButton').on('click', function(){
$('i.gly-spin').removeClass('gly-spin');
$('i').addClass('gly-spin');
});
$(function () {
$('.fotorama').fotorama();
});
</script>
</div>

View File

@@ -42,9 +42,6 @@
<script src="${request.static_url('mondumas:static/dist/formvalidation/js/language/fr_FR.js')}" type="text/javascript"></script>
<!-- JSignature plugin -->
<script src="${request.static_url('mondumas:static/dist/jSignature/libs/jSignature.min.js')}"></script>
<!-- fotorama.css & fotorama.js. -->
<link href="http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.4/fotorama.css" rel="stylesheet"> <!-- 3 KB -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.4/fotorama.js"></script> <!-- 16 KB -->
<!-- Less -->
<script src="//cdnjs.cloudflare.com/ajax/libs/less.js/2.5.3/less.min.js" type="text/javascript"></script>

View File

@@ -1,22 +0,0 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:tal="http://xml.zope.org/namespaces/tal"
lang="fr">
<head>
<title>${page_title}</title>
</head>
<body>
<img src="http://www.caes.cnrs.fr/logo.jpg" class="caes-logo" alt="CAES du CNRS" title="CAES du CNRS" />
<div metal:define-slot="content" />
<div id="footer">
<div class="well">
Siège : <a href="http://www.caes.cnrs.fr">CAES du CNRS</a> - 2, Allée Georges Méliès - 94306 Vincennes CEDEX - France
</div>
</div>
</body>
</html>

View File

@@ -100,7 +100,7 @@ def dossier_view(request):
# lire toutes les dossiers similaires
similaires = get_similaires_byChantier(request, dossier.societe, dossier.C_NOM, dossier.C_ADR, dossier.C_CP, dossier.C_VILLE)
# lire tous les documents attachés
docs_attaches = get_docs_attaches(request, nodossier)
docs_attaches = get_docs_attaches(request, nodossier, 0, '')
if nodossier.startswith('PL'):
# lire rapport de rdf
rapports = get_rapport_by_no(request, nodossier, '')
@@ -271,7 +271,7 @@ def upload_doc(request):
return HTTPFound(location=request.route_url("dossier_lookup"))
# lire tous les documents attachés
docs_attaches = get_docs_attaches(request, nodossier)
docs_attaches = get_docs_attaches(request, nodossier, 0, '')
if 'form.submitted' in request.params:
# récupère le fichier lui-même
@@ -290,37 +290,34 @@ def upload_doc(request):
filename = '%s-DD%s-%s' % (societe, nochantier, request.POST['filename'].filename)
# créer le répertoire du chantier s'il n'existe pas encore
path = '%s/%s/%s' % (request.registry.settings['mondumas.devfac_dir'],societe,nochantier)
try:
os.mkdir(path)
except OSError:
pass # ignorer erreor si déjà créé
finally:
file_path = os.path.join(path, filename)
# We first write to a temporary file to prevent incomplete files
temp_file_path = file_path + '~'
os.makedirs(path, exist_ok=True)
# Finally write the data to a temporary file
input_file.seek(0)
with open(temp_file_path, 'wb') as output_file:
shutil.copyfileobj(input_file, output_file)
file_path = os.path.join(path, filename)
# We first write to a temporary file to prevent incomplete files
temp_file_path = file_path + '~'
# controler la taille du fichier < 2 Mo
filesize = round(os.path.getsize(temp_file_path) / 1024)
if filesize > 2048 :
# Finally write the data to a temporary file
input_file.seek(0)
with open(temp_file_path, 'wb') as output_file:
shutil.copyfileobj(input_file, output_file)
# controler la taille du fichier < 2 Mo
filesize = round(os.path.getsize(temp_file_path) / 1024)
if filesize > 2048 :
os.remove(temp_file_path)
request.session.flash("La taille de ce fichier dépasse la limite autorisée. Téléchargement impossible.", 'warning')
else:
# Now that we know the file has been fully saved to disk move it into place.
try:
os.rename(temp_file_path, file_path)
except OSError:
os.remove(temp_file_path)
request.session.flash("La taille de ce fichier dépasse la limite autorisée. Téléchargement impossible.", 'warning')
request.session.flash('%s : Ce fichier existe déjà dans le rapport.' % input_name, 'danger')
else:
# Now that we know the file has been fully saved to disk move it into place.
try:
os.rename(temp_file_path, file_path)
except OSError:
os.remove(temp_file_path)
request.session.flash('%s : Ce fichier existe déjà dans le rapport.' % input_name, 'danger')
else:
insert_dossier_attaches(request, nodossier, 0, filename, '%s Ko' % str(filesize), logged_in)
request.session.flash('%s : Ce fichier est téléchargé avec succès.' % input_name, 'success')
# lire tous les documents attachés
docs_attaches = get_docs_attaches(request, nodossier)
insert_dossier_attaches(request, nodossier, 0, filename, '%s Ko' % str(filesize), logged_in)
request.session.flash('%s : Ce fichier est téléchargé avec succès.' % input_name, 'success')
# lire tous les documents attachés
docs_attaches = get_docs_attaches(request, nodossier, 0, '')
return {
'page_title': u"Télécharger un document",
@@ -367,37 +364,34 @@ def upload_img(request):
# créer le répertoire du chantier s'il n'existe pas encore
path = '%s/%s/%s/%s' % (request.registry.settings['mondumas.devfac_dir'], societe, nochantier, norapport)
try:
os.makedirs(path)
except OSError:
pass # ignorer erreor si déjà créé
finally:
file_path = os.path.join('%s/%s' % (path, filename))
# We first write to a temporary file to prevent incomplete files
temp_file_path = file_path + '~'
os.makedirs(path, exist_ok=True)
# Finally write the data to a temporary file
input_file.seek(0)
with open(temp_file_path, 'wb') as output_file:
shutil.copyfileobj(input_file, output_file)
file_path = os.path.join('%s/%s' % (path, filename))
# We first write to a temporary file to prevent incomplete files
temp_file_path = file_path + '~'
# controler la taille du fichier < 2 Mo
filesize = round(os.path.getsize(temp_file_path) / 1024)
if filesize > 2048 :
# Finally write the data to a temporary file
input_file.seek(0)
with open(temp_file_path, 'wb') as output_file:
shutil.copyfileobj(input_file, output_file)
# controler la taille du fichier < 2 Mo
filesize = round(os.path.getsize(temp_file_path) / 1024)
if filesize > 2048 :
os.remove(temp_file_path)
request.session.flash("La taille de ce fichier dépasse la limite autorisée. Téléchargement impossible.", 'warning')
else:
# Now that we know the file has been fully saved to disk move it into place.
try:
os.rename(temp_file_path, file_path)
except OSError:
os.remove(temp_file_path)
request.session.flash("La taille de ce fichier dépasse la limite autorisée. Téléchargement impossible.", 'warning')
request.session.flash('%s : Ce fichier existe déjà dans le rapport.' % input_name, 'danger')
else:
# Now that we know the file has been fully saved to disk move it into place.
try:
os.rename(temp_file_path, file_path)
except OSError:
os.remove(temp_file_path)
request.session.flash('%s : Ce fichier existe déjà dans le rapport.' % input_name, 'danger')
else:
insert_dossier_attaches(request, 'PL-%s' % nochantier, norapport, filename, '%s Ko' % str(filesize), logged_in)
request.session.flash('%s : Ce fichier est téléchargé avec succès.' % input_name, 'success')
# lire tous les photos attachées
photos = get_photos(request, nochantier, norapport)
insert_dossier_attaches(request, 'PL-%s' % nochantier, norapport, filename, '%s Ko' % str(filesize), logged_in)
request.session.flash('%s : Ce fichier est téléchargé avec succès.' % input_name, 'success')
# lire tous les photos attachées
photos = get_photos(request, nochantier, norapport)
return {
'page_title': u"Télécharger une photo",
@@ -421,9 +415,8 @@ def rdf_edit(request):
if not rapport:
# creer un nouveau rapport
insert_rapport(request, nodossier, logged_in)
else:
# lire le rapport
rapport = get_rapport_by_no(request, nodossier, date_inter)
# lire le rapport
rapport = get_rapport_by_no(request, nodossier, date_inter)
url = request.route_url('rdf_edit', nodossier=nodossier, date_inter=date_inter)
caracteristiques = ["Maison individuelle", "Immeuble collectif", "Copropriété", "Commerce", "Bureaux"]
@@ -524,7 +517,7 @@ def rdf_list(request):
else:
date_rapport = ''
d = (item.nochantier, item.date_inter.strftime('%d-%m-%Y'), '', '%s %s' % (item.C_QUALITE, item.C_NOM), item.NOMCLI, item.NOSIN,
d = (item.nochantier, item.date_inter.strftime('%d-%m-%Y'), date_rapport, '%s %s' % (item.C_QUALITE, item.C_NOM), item.NOMCLI, item.NOSIN,
item.auteur_code, item.no_id)
liste.append(d)
@@ -542,17 +535,15 @@ def rdf_view(request):
# lire le rapport
rapport = get_rapport_by_no_id(request, norapport)
nodossier = 'PL-' + str(rapport.nochantier)
if rapport.date_rapport:
date_rapport = rapport.date_rapport.strftime('%d-%m-%Y')
else:
date_rapport = ''
# lire tous les photos attachées
photos = get_photos(request, rapport.nochantier, norapport)
if 'form.generate' in request.params:
# génère la page rapport
result = rdf_rapport(request)
result['main_template'] = get_renderer('../templates/layouts/pdf.pt').implementation()
htmlcontent = render('../templates/dossier/rdf_rapport.pt', result, request)
htmlcontent = htmlcontent.encode('iso8859-15')
options = {
'page-size': 'A4',
'margin-top': '0.75in',
@@ -561,6 +552,9 @@ def rdf_view(request):
'margin-left': '0.75in',
}
# créer le répertoire du rapport s'il n'existe pas encore
path = '%s/%s/%s/%s' % (request.registry.settings['mondumas.devfac_dir'], 'PL', rapport.nochantier, norapport)
os.makedirs(path, exist_ok=True)
# générer le rapport en PDF
filename = "PL-DD%s-rapport RDF no %s.PDF" % (str(rapport.nochantier), norapport)
dest = "mondumas/static/DEVFAC/DOCS_ATTACHES/PL/%s/%s" % (str(rapport.nochantier), filename)
@@ -568,12 +562,15 @@ def rdf_view(request):
config = pdfkit.configuration(wkhtmltopdf="C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe")
try:
pdfkit.from_url(origin, dest, configuration=config, options=options)
# pdfkit.from_string(htmlcontent, dest, configuration=config)
except:
request.session.flash(u"Une erreur est survenue pendant la génération du PDF.", 'danger')
return HTTPFound(location=request.route_url('rdf_view', no_id=norapport))
else:
insert_dossier_attaches(request, nodossier, 0, filename, '160 Ko', logged_in)
# si generation pdf, maj de la date du rapport
new_values = {}
new_values['date_rapport'] = date.today()
update_rapport(request, nodossier, rapport.date_inter.strftime('%Y-%m-%d'), new_values)
request.session.flash(u"Le rapport a été génré avec succès.", 'success')
return HTTPFound(location=request.route_url('dossier_view', nodossier=nodossier))
@@ -586,6 +583,7 @@ def rdf_view(request):
'nodossier': nodossier,
'nochantier': rapport.nochantier,
'norapport': norapport,
'date_rapport': date_rapport,
'photos': photos,
'docs_url': request.static_url(request.registry.settings['mondumas.devfac_url']),
}
@@ -597,6 +595,10 @@ def rdf_rapport(request):
# lire le rapport
rapport = get_rapport_by_no_id(request, norapport)
nodossier = 'PL-' + str(rapport.nochantier)
if rapport.date_rapport:
date_rapport = rapport.date_rapport.strftime('%d-%m-%Y')
else:
date_rapport = ''
# lire tous les photos attachées
photos = get_photos(request, rapport.nochantier, norapport)
@@ -607,6 +609,7 @@ def rdf_rapport(request):
'nodossier': nodossier,
'nochantier': rapport.nochantier,
'norapport': norapport,
'date_rapport': date_rapport,
'photos': photos,
'docs_url': request.static_url(request.registry.settings['mondumas.devfac_url']),
}