source: WAeUP_SRP/base/skins/waeup_upload/uploads_index.py @ 3302

Last change on this file since 3302 was 3301, checked in by Henrik Bettermann, 17 years ago

request.RESPONSE.redirect without return doesn't make sense

minor changes in workflow

  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
1## Script (Python) "uploads_index"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=
8##title=
9##
10# $Id:uploads_index.py 486 2006-09-06 10:09:39Z joachim $
11"""
12return Info about the Uploads
13"""
14import DateTime
15import logging
16logger = logging.getLogger('Skins.upload_index')
17
18
19try:
20    from Products.zdb import set_trace
21except:
22    def set_trace():
23        pass
24request = context.REQUEST
25
26wf = context.portal_workflow
27mtool = context.portal_membership
28member = mtool.getAuthenticatedMember()
29
30path_info = request.get('PATH_INFO').split('/')
31NO_KEY = '----'
32info = {}
33info['action'] = "%s" % context.absolute_url()
34info['choosen_ids'] = request.get('ids',[])
35info['doc'] = context.getContent()
36
37logger.info('%s views upload section' % member)
38
39edit = request.form.has_key('edit')
40ids = request.get('ids',[])
41#set_trace()
42if edit and ids:
43    for long_id in ids:
44        short_id = long_id.replace('.csv','')
45        doc = getattr(context, long_id).getContent()
46        import_layout =  request.form.get(short_id)['import_layout']
47        logger.info('%s set import layout of object %s to %s' % (member,long_id,import_layout))
48        doc.edit(mapping = request.form[short_id])
49        msg, invalid_keys = doc['checkKeys']()
50        new_keys = []
51        for key in invalid_keys:
52            id_key = "%s|%s" % (short_id,key)
53            if request.form.has_key(id_key):
54                new_key = request.form.get(id_key)['valid_key']
55                if new_key != NO_KEY:
56                    new_keys += (key,new_key),
57        if new_keys:
58            doc.editHeadline(new_keys)
59            for key in new_keys:
60                logger.info('%s changed column heading in file %s from %s to %s' % (member,long_id,key[0],key[1]))
61       
62wrong = []
63imported = []
64importable = []
65for id,upload in context.objectItems():
66    add_to = wrong
67    row = {}
68    doc = upload.getContent()
69    row['valid_keys'] = doc['getKeys']()
70    row['valid_keys'][0] = NO_KEY
71    row['id'] = id.replace('.csv','')
72    row['title'] = doc.filename
73    row['url'] = upload.absolute_url()
74    row['imported'] = False
75    row['invalid_keys'] = []
76    import_message = getattr(doc,'import_message','')
77    if import_message:
78        row['imported'] = True
79        row['msg'] = import_message
80        if getattr(doc,'imported_at',''):
81            row['imported_at'] = doc.imported_at.strftime("%d/%m/%y %H:%M:%S")
82        else:
83            row['imported_at'] = ''
84        add_to = imported
85    else:
86        row['msg'],row['invalid_keys'] = doc['checkKeys']()
87        if not row['msg'] and not row['invalid_keys']:
88            add_to = importable
89    row['filename'] = doc.filename
90    row['import_layout'] = doc.import_layout
91    row['upload_date'] =  doc.upload_date.strftime("%d/%m/%y %H:%M:%S")
92    row['uploaded_by'] = doc.uploaded_by
93    add_to.append(row)
94wrong.sort()
95imported.sort()
96importable.sort()
97info['wrong'] = wrong
98info['imported'] = imported
99info['importable'] = importable
100
101validate = "upload" in request.keys()
102mode = "create"
103res,psm,ds = context.portal_layouts.renderLayout(layout_id = 'upload',
104                             schema_id = 'upload',
105                             layout_mode = mode,
106                             context=context,
107                             mapping=validate and request,
108                             ob= {},
109                             commit = True,
110                            )
111while True:
112    if psm == 'invalid':
113        psm = "Please correct your input!"
114    # return context.uploads_form(rendered = res,
115    #                              psm = "Please correct your input!",
116    #                              mode = mode,
117    #                              ds = ds,
118    #                              info = info,
119    #                             )
120    elif psm == 'valid':
121        filename = ds['upload_file'].filename
122        if filename not in context.objectIds():
123            break
124        psm = "Upload object exists!"
125    return context.uploads_form(rendered = res,
126                                        psm = psm,
127                                        ds = ds,
128                                        mode = mode,
129                                        info = info,
130                                       )
131
132context.invokeFactory('Upload',filename)
133upload = getattr(context,filename)
134d = {}
135d['filename'] = d['id'] = filename
136d['upload_date'] =  DateTime.DateTime()
137d['import_layout'] = ds.get('import_layout','')
138d['uploaded_by'] = str(member)
139d['url'] = upload.absolute_url()
140upload.getContent().edit(mapping=d)
141logger.info('%s uploaded file %s with import layout %s' % (member,filename,d['import_layout']))
142
143return request.RESPONSE.redirect(context.absolute_url())
144
Note: See TracBrowser for help on using the repository browser.