Correction pour les accents dans la génération des champs des formulaires
This commit is contained in:
parent
8b4a96d06e
commit
d2818f3589
|
@ -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 = "<!--#### A inserer apres field 'Un code de suivi de votre demande...' -->\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"<!--#### A inserer apres field 'Un code de suivi de votre demande...' jusqu'a la fin des </fields> -->\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 += "<field>\n"
|
||||
output_string += " <label>Pieces a joindre</label>\n"
|
||||
output_string += " <type>page</type>\n"
|
||||
output_string += " <condition>\n"
|
||||
output_string += " <type>python</type>\n"
|
||||
output_string += ' <value>form_var_objet_raw == "'+str(objet["id"])+'"</value>\n'
|
||||
output_string += " </condition><id>"+str(id)+"</id>\n"
|
||||
output_string += u"<field>\n"
|
||||
output_string += u" <label>Pièces à joindre</label>\n"
|
||||
output_string += u" <type>page</type>\n"
|
||||
output_string += u" <condition>\n"
|
||||
output_string += u" <type>python</type>\n"
|
||||
output_string += u' <value>form_var_objet_raw == "'+str(objet["id"]).decode('utf8')+u'"</value>\n'
|
||||
output_string += u" </condition><id>"+str(id).decode('utf8')+u"</id>\n"
|
||||
id += 1
|
||||
output_string += " </field><field>\n"
|
||||
output_string += ' <label>[is form_option_type_dossier "foo"] [end]'
|
||||
output_string += "\n"
|
||||
output_string += '<span id="logo_commune"></span>\n'
|
||||
output_string += "\n"
|
||||
output_string += "\n"
|
||||
output_string += '<script type="text/javascript">\n'
|
||||
output_string += "function slugify(text)\n"
|
||||
output_string += "{\n"
|
||||
output_string += " return text.toString().toLowerCase()\n"
|
||||
output_string += " .replace(/\s+/g, '-') // Replace spaces with -\n"
|
||||
output_string += " .replace(/\'/g, '-') // Replace ' with -\n"
|
||||
output_string += " .replace(/ô/g, 'o').replace(/é/g, 'e').replace(/è/g, 'e') // Remove accent\n"
|
||||
output_string += " .replace(/[^\w\-]+/g, '') // Remove all non-word chars\n"
|
||||
output_string += " .replace(/\-\-+/g, '-') // Replace multiple - with single -\n"
|
||||
output_string += " .replace(/^-+/, '') // Trim - from start of text\n"
|
||||
output_string += " .replace(/-+$/, ''); // Trim - from end of text\n"
|
||||
output_string += "}\n"
|
||||
output_string += "function setLogo()\n"
|
||||
output_string += "{\n"
|
||||
output_string += ' var selectedText ="[form_var_commune]";\n'
|
||||
output_string += " var communeChanged = slugify(selectedText);\n"
|
||||
output_string += " // Pour enlever arrondissement de Lyon\n"
|
||||
output_string += ' if( selectedText.startsWith("Lyon") ) communeChanged = "lyon"\n'
|
||||
output_string += ' $("#logo_commune").html(\'<img src="[portal_url]static/grandlyon-gnm/producers/\'+communeChanged+\'.png" />\');\n'
|
||||
output_string += "}\n"
|
||||
output_string += "setLogo();\n"
|
||||
output_string += "</script>\n"
|
||||
output_string += "\n"
|
||||
output_string += "</label>\n"
|
||||
output_string += " <type>comment</type>\n"
|
||||
output_string += " <extra_css_class>imgCommune</extra_css_class>\n"
|
||||
output_string += " <id>"+str(id)+"</id>\n"
|
||||
output_string += u" </field><field>\n"
|
||||
output_string += u' <label>[is form_option_type_dossier "foo"] [end]'
|
||||
output_string += u"\n"
|
||||
output_string += u'<span id="logo_commune"></span>\n'
|
||||
output_string += u"\n"
|
||||
output_string += u"\n"
|
||||
output_string += u'<script type="text/javascript">\n'
|
||||
output_string += u"function slugify(text)\n"
|
||||
output_string += u"{\n"
|
||||
output_string += u" return text.toString().toLowerCase()\n"
|
||||
output_string += u" .replace(/\s+/g, '-') // Replace spaces with -\n"
|
||||
output_string += u" .replace(/\'/g, '-') // Replace ' with -\n"
|
||||
output_string += u" .replace(/ô/g, 'o').replace(/é/g, 'e').replace(/è/g, 'e') // Remove accent\n"
|
||||
output_string += u" .replace(/[^\w\-]+/g, '') // Remove all non-word chars\n"
|
||||
output_string += u" .replace(/\-\-+/g, '-') // Replace multiple - with single -\n"
|
||||
output_string += u" .replace(/^-+/, '') // Trim - from start of text\n"
|
||||
output_string += u" .replace(/-+$/, ''); // Trim - from end of text\n"
|
||||
output_string += u"}\n"
|
||||
output_string += u"function setLogo()\n"
|
||||
output_string += u"{\n"
|
||||
output_string += u' var selectedText ="[form_var_commune]";\n'
|
||||
output_string += u" var communeChanged = slugify(selectedText);\n"
|
||||
output_string += u" // Pour enlever arrondissement de Lyon\n"
|
||||
output_string += u' if( selectedText.startsWith("Lyon") ) communeChanged = "lyon"\n'
|
||||
output_string += u' $("#logo_commune").html(\'<img src="[portal_url]static/grandlyon-gnm/producers/\'+communeChanged+\'.png" />\');\n'
|
||||
output_string += u"}\n"
|
||||
output_string += u"setLogo();\n"
|
||||
output_string += u"</script>\n"
|
||||
output_string += u"\n"
|
||||
output_string += u"</label>\n"
|
||||
output_string += u" <type>comment</type>\n"
|
||||
output_string += u" <extra_css_class>imgCommune</extra_css_class>\n"
|
||||
output_string += u" <id>"+str(id).decode('utf8')+u"</id>\n"
|
||||
id += 1
|
||||
output_string += " </field><field>\n"
|
||||
output_string += " <label><p><strong>2/ Votre dossier est pr&ecirc;t &agrave; &ecirc;tre d&eacute;pos&eacute;.</strong></p><p>Merci de nous faire parvenir les pi&egrave;ces ci-dessous.</p><p>&nbsp;</p></label>\n"
|
||||
output_string += " <type>comment</type>\n"
|
||||
output_string += " <id>"+str(id)+"</id>\n"
|
||||
output_string += u" </field><field>\n"
|
||||
output_string += u" <label><p><strong>2/ Votre dossier est pr&ecirc;t &agrave; &ecirc;tre d&eacute;pos&eacute;.</strong></p><p>Merci de nous faire parvenir les pi&egrave;ces ci-dessous.</p><p>&nbsp;</p></label>\n"
|
||||
output_string += u" <type>comment</type>\n"
|
||||
output_string += u" <id>"+str(id).decode('utf8')+u"</id>\n"
|
||||
id += 1
|
||||
output_string += " </field><field>\n"
|
||||
output_string += " <label>Cerfa rempli</label>\n"
|
||||
output_string += " <type>file</type>\n"
|
||||
output_string += " <required>True</required>\n"
|
||||
output_string += " <varname>objet"+str(objet["id"])+"_cerfa</varname>\n"
|
||||
output_string += " <in_listing>True</in_listing>\n"
|
||||
output_string += " <prefill>\n"
|
||||
output_string += " <type>none</type>\n"
|
||||
output_string += " </prefill><max_file_size>200M</max_file_size>\n"
|
||||
output_string += " <allow_portfolio_picking>True</allow_portfolio_picking>\n"
|
||||
output_string += " <id>"+str(id)+"</id>\n"
|
||||
output_string += u" </field><field>\n"
|
||||
output_string += u" <label>Cerfa rempli</label>\n"
|
||||
output_string += u" <type>file</type>\n"
|
||||
output_string += u" <required>True</required>\n"
|
||||
output_string += u" <varname>objet"+str(objet["id"]).decode('utf8')+u"_cerfa</varname>\n"
|
||||
output_string += u" <in_listing>True</in_listing>\n"
|
||||
output_string += u" <prefill>\n"
|
||||
output_string += u" <type>none</type>\n"
|
||||
output_string += u" </prefill><max_file_size>200M</max_file_size>\n"
|
||||
output_string += u" <allow_portfolio_picking>True</allow_portfolio_picking>\n"
|
||||
output_string += u" <id>"+str(id).decode('utf8')+u"</id>\n"
|
||||
id += 1
|
||||
output_string += " </field>\n"
|
||||
output_string += u" </field>\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 += "<field>\n"
|
||||
output_string += " <label>"+piece["Libelle"]+"</label>\n"
|
||||
output_string += " <type>file</type>\n"
|
||||
output_string += " <required>"+str(piece["Reglementaire"]).title()+"</required>\n"
|
||||
hint = ""
|
||||
if piece["Descriptif"]: hint = piece["Descriptif"]
|
||||
output_string += " <hint>"+hint+"</hint>\n"
|
||||
output_string += " <varname>objet"+str(objet["id"])+"_"+str(piece["IdPiece"])+"_"+str(piece["CodePiece"])+"</varname>\n"
|
||||
output_string += " <in_listing>False</in_listing>\n"
|
||||
output_string += " <prefill>\n"
|
||||
output_string += " <type>none</type>\n"
|
||||
output_string += " </prefill><max_file_size>50M</max_file_size>\n"
|
||||
output_string += " <allow_portfolio_picking>True</allow_portfolio_picking>\n"
|
||||
output_string += " <id>"+str(id)+"</id>\n"
|
||||
output_string += "</field>\n"
|
||||
output_string += u"<field>\n"
|
||||
output_string += u" <label>"+h.unescape(piece["Libelle"])+u"</label>\n"
|
||||
output_string += u" <type>file</type>\n"
|
||||
output_string += u" <required>"+str(piece["Reglementaire"]).title().decode('utf8')+u"</required>\n"
|
||||
hint = u""
|
||||
if piece["Descriptif"]: hint = h.unescape(piece["Descriptif"])
|
||||
output_string += u" <hint>"+hint+u"</hint>\n"
|
||||
output_string += u" <varname>objet"+str(objet["id"]).decode('utf8')+u"_"+str(piece["IdPiece"]).decode('utf8')+u"_"+str(piece["CodePiece"]).decode('utf8')+u"</varname>\n"
|
||||
output_string += u" <in_listing>False</in_listing>\n"
|
||||
output_string += u" <prefill>\n"
|
||||
output_string += u" <type>none</type>\n"
|
||||
output_string += u" </prefill><max_file_size>50M</max_file_size>\n"
|
||||
output_string += u" <allow_portfolio_picking>True</allow_portfolio_picking>\n"
|
||||
output_string += u" <id>"+str(id).decode('utf8')+u"</id>\n"
|
||||
output_string += u"</field>\n"
|
||||
id += 1
|
||||
|
||||
output_string += " </fields><options>\n"
|
||||
output_string += u" </fields>\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}
|
||||
|
|
Reference in New Issue