From d2818f35898bdfe4c3565c6a5f46eec921e06740 Mon Sep 17 00:00:00 2001 From: Etienne Loupias Date: Thu, 5 Apr 2018 11:42:17 +0200 Subject: [PATCH] =?UTF-8?q?Correction=20pour=20les=20accents=20dans=20la?= =?UTF-8?q?=20g=C3=A9n=C3=A9ration=20des=20champs=20des=20formulaires?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cartads/models.py | 157 ++++++++++++++++++++++++---------------------- 1 file changed, 81 insertions(+), 76 deletions(-) diff --git a/cartads/models.py b/cartads/models.py index 1ad092c..26db22e 100644 --- a/cartads/models.py +++ b/cartads/models.py @@ -1,3 +1,5 @@ +# coding: utf8 + # Copyright (C) 2016 Entr'ouvert # # This program is free software: you can redistribute it and/or modify it @@ -19,6 +21,7 @@ import datetime import uuid import zipfile import StringIO +import HTMLParser import os # TODO: inutile si on genere le zip in-memory from email import encoders @@ -285,6 +288,9 @@ class CartADS(BaseResource): @endpoint(perm='can_access') def get_objets_demande(self, request, type_dossier): + if len(type_dossier) != 2: + raise ParameterTypeError("invalid type_dossier parameter") + resp = self.get_client().service.GetObjetsDemande(self.get_token_cartads(), type_dossier) dict_resp = sudsobject_to_dict(resp) @@ -335,7 +341,8 @@ class CartADS(BaseResource): @endpoint(perm='can_access') def write_wcs_files(self, request, type_dossier): - output_string = "\n" + h = HTMLParser.HTMLParser() # h.unescape(string) decode le html qui vient du web service en unicode : http://fredericiana.com/2010/10/08/decoding-html-entities-to-text-in-python/ + output_string = u"\n" dict_resp = self.get_objets_demande(request, type_dossier) for objet in dict_resp['data']: @@ -352,67 +359,66 @@ class CartADS(BaseResource): #(par exemple : 1000*objet["id"]+10*no du champ+no de la piece si elle est envoyee 6 fois) id = 100*objet["id"] - #TODO: mettre les accents dans "Pieces a joindre" - output_string += "\n" - output_string += " \n" - output_string += " page\n" - output_string += " \n" - output_string += " python\n" - output_string += ' form_var_objet_raw == "'+str(objet["id"])+'"\n' - output_string += " "+str(id)+"\n" + output_string += u"\n" + output_string += u" \n" + output_string += u" page\n" + output_string += u" \n" + output_string += u" python\n" + output_string += u' form_var_objet_raw == "'+str(objet["id"]).decode('utf8')+u'"\n' + output_string += u" "+str(id).decode('utf8')+u"\n" id += 1 - output_string += " \n" - output_string += ' \n" - output_string += " comment\n" - output_string += " imgCommune\n" - output_string += " "+str(id)+"\n" + output_string += u" \n" + output_string += u' \n" + output_string += u" comment\n" + output_string += u" imgCommune\n" + output_string += u" "+str(id).decode('utf8')+u"\n" id += 1 - output_string += " \n" - output_string += " \n" - output_string += " comment\n" - output_string += " "+str(id)+"\n" + output_string += u" \n" + output_string += u" \n" + output_string += u" comment\n" + output_string += u" "+str(id).decode('utf8')+u"\n" id += 1 - output_string += " \n" - output_string += " \n" - output_string += " file\n" - output_string += " True\n" - output_string += " objet"+str(objet["id"])+"_cerfa\n" - output_string += " True\n" - output_string += " \n" - output_string += " none\n" - output_string += " 200M\n" - output_string += " True\n" - output_string += " "+str(id)+"\n" + output_string += u" \n" + output_string += u" \n" + output_string += u" file\n" + output_string += u" True\n" + output_string += u" objet"+str(objet["id"]).decode('utf8')+u"_cerfa\n" + output_string += u" True\n" + output_string += u" \n" + output_string += u" none\n" + output_string += u" 200M\n" + output_string += u" True\n" + output_string += u" "+str(id).decode('utf8')+u"\n" id += 1 - output_string += " \n" + output_string += u" \n" for piece in dict_resp['Piece']: @@ -420,27 +426,26 @@ class CartADS(BaseResource): #for key, value in piece.items(): #print >> open('/home/grandlyon/log/'+type_dossier+'_'+date_file.strftime('%Y%m%d%H%M%S')+'.wcs', 'a+'), key,": ", value #self.print_wcs_files(type_dossier, date_file, key+": "+str(value)) - output_string += "\n" - output_string += " \n" - output_string += " file\n" - output_string += " "+str(piece["Reglementaire"]).title()+"\n" - hint = "" - if piece["Descriptif"]: hint = piece["Descriptif"] - output_string += " "+hint+"\n" - output_string += " objet"+str(objet["id"])+"_"+str(piece["IdPiece"])+"_"+str(piece["CodePiece"])+"\n" - output_string += " False\n" - output_string += " \n" - output_string += " none\n" - output_string += " 50M\n" - output_string += " True\n" - output_string += " "+str(id)+"\n" - output_string += "\n" + output_string += u"\n" + output_string += u" \n" + output_string += u" file\n" + output_string += u" "+str(piece["Reglementaire"]).title().decode('utf8')+u"\n" + hint = u"" + if piece["Descriptif"]: hint = h.unescape(piece["Descriptif"]) + output_string += u" "+hint+u"\n" + output_string += u" objet"+str(objet["id"]).decode('utf8')+u"_"+str(piece["IdPiece"]).decode('utf8')+u"_"+str(piece["CodePiece"]).decode('utf8')+u"\n" + output_string += u" False\n" + output_string += u" \n" + output_string += u" none\n" + output_string += u" 50M\n" + output_string += u" True\n" + output_string += u" "+str(id).decode('utf8')+u"\n" + output_string += u"\n" id += 1 - output_string += " \n" + output_string += u" \n" - #TODO: a voir pb utf8 (pour l'instant tous les caracteres accentues sont supprimes par le ignore) - output_string = output_string.encode('ascii', 'ignore') + output_string = output_string.encode('ascii', errors='xmlcharrefreplace') print >> open('/home/grandlyon/log/'+type_dossier+'_'+date_file.strftime('%Y%m%d%H%M%S')+'.wcs', 'a+'), output_string return {'data': output_string}