list2form.py : correction du bogue url-name
[progfou.git] / wcs / wcs-dynexport
index b21e6ea..7e2d5db 100755 (executable)
@@ -199,7 +199,7 @@ def get_wcs_form_data(domain, form):
     fields = {}
     field_names = {}
     field_names_duplicates = {}
-    for field in formdef.fields:
+    for i, field in enumerate(formdef.fields):
         if isinstance(field, TitleField) or isinstance(field, CommentField):
             continue
         if field.varname:
@@ -210,7 +210,7 @@ def get_wcs_form_data(domain, form):
             field_names_duplicates[name] = field_names_duplicates.get(name, 1) + 1
             name = '%s_%d' % (name, field_names_duplicates[name])
         field_names.update({field.id: name})
-        fields.update({field.id: {'name': field_names[field.id], 'label': field.label, 'varname': field.varname and field.varname or ''}})
+        fields.update({field.id: {'index': i, 'name': field_names[field.id], 'label': field.label, 'varname': field.varname and field.varname or ''}})
 
     data = json.dumps(fields, ensure_ascii=False).encode('utf-8')
     set_wcs_cache(domain, form, 'fields.json', data)
@@ -229,11 +229,16 @@ def get_wcs_form_data(domain, form):
                             " On ignore...", object.id)
             continue
 
+        try:
+            workflow_status = object.status.startswith('wf-') and \
+                            object.get_workflow_status().name or None
+        except:
+            workflow_status = None
+
         result = {
             'num_dossier': object.id,
             'wcs_status': object.status,
-            'wcs_workflow_status': (object.status.startswith('wf-') and \
-                                object.get_workflow_status().name or None),
+            'wcs_workflow_status': workflow_status,
             'wcs_user_email': object.user.email,
             'wcs_user_display_name': object.user.display_name,
            #'wcs_last_modified': time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(object.last_modified())),
@@ -308,6 +313,8 @@ def get_wcs_form_data(domain, form):
             dst = filename + '_' + result[f]
             src = os.path.join(pub.app_dir, 'uploads', qfiles[f])
             liste_attachements.update({dst: src})
+            # on renomme le fichier joint indiqué dans le dossier
+            result[f] = dst
 
         # génération du fichier JSON
         data = json.dumps(result, ensure_ascii=False).encode('utf-8')