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

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

move logger.info to the right place

  • 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
37edit = request.form.has_key('edit')
38ids = request.get('ids',[])
39#set_trace()
40if edit and ids:
41    for long_id in ids:
42        short_id = long_id.replace('.csv','')
43        doc = getattr(context, long_id).getContent()
44        import_layout =  request.form.get(short_id)['import_layout']
45        logger.info('%s set import layout of object %s to %s' % (member,long_id,import_layout))
46        doc.edit(mapping = request.form[short_id])
47        msg, invalid_keys = doc['checkKeys']()
48        new_keys = []
49        for key in invalid_keys:
50            id_key = "%s|%s" % (short_id,key)
51            if request.form.has_key(id_key):
52                new_key = request.form.get(id_key)['valid_key']
53                if new_key != NO_KEY:
54                    new_keys += (key,new_key),
55        if new_keys:
56            doc.editHeadline(new_keys)
57            for key in new_keys:
58                logger.info('%s changed column heading in file %s from %s to %s' % (member,long_id,key[0],key[1]))
59
60wrong = []
61imported = []
62importable = []
63for id,upload in context.objectItems():
64    add_to = wrong
65    row = {}
66    doc = upload.getContent()
67    row['valid_keys'] = doc['getKeys']()
68    row['valid_keys'][0] = NO_KEY
69    row['id'] = id.replace('.csv','')
70    row['title'] = doc.filename
71    row['url'] = upload.absolute_url()
72    row['imported'] = False
73    row['invalid_keys'] = []
74    import_message = getattr(doc,'import_message','')
75    if import_message:
76        row['imported'] = True
77        row['msg'] = import_message
78        if getattr(doc,'imported_at',''):
79            row['imported_at'] = doc.imported_at.strftime("%d/%m/%y %H:%M:%S")
80        else:
81            row['imported_at'] = ''
82        add_to = imported
83    else:
84        row['msg'],row['invalid_keys'] = doc['checkKeys']()
85        if not row['msg'] and not row['invalid_keys']:
86            add_to = importable
87    row['filename'] = doc.filename
88    row['import_layout'] = doc.import_layout
89    row['upload_date'] =  doc.upload_date.strftime("%d/%m/%y %H:%M:%S")
90    row['uploaded_by'] = doc.uploaded_by
91    add_to.append(row)
92wrong.sort()
93imported.sort()
94importable.sort()
95info['wrong'] = wrong
96info['imported'] = imported
97info['importable'] = importable
98
99validate = "upload" in request.keys()
100mode = "create"
101res,psm,ds = context.portal_layouts.renderLayout(layout_id = 'upload',
102                             schema_id = 'upload',
103                             layout_mode = mode,
104                             context=context,
105                             mapping=validate and request,
106                             ob= {},
107                             commit = True,
108                            )
109while True:
110    if psm == 'invalid':
111        psm = "Please correct your input!"
112    # return context.uploads_form(rendered = res,
113    #                              psm = "Please correct your input!",
114    #                              mode = mode,
115    #                              ds = ds,
116    #                              info = info,
117    #                             )
118    elif psm == 'valid':
119        filename = ds['upload_file'].filename
120        if filename not in context.objectIds():
121            break
122        psm = "Upload object exists!"
123    logger.info('%s views upload section' % member)   
124    return context.uploads_form(rendered = res,
125                                        psm = psm,
126                                        ds = ds,
127                                        mode = mode,
128                                        info = info,
129                                       )
130
131context.invokeFactory('Upload',filename)
132upload = getattr(context,filename)
133d = {}
134d['filename'] = d['id'] = filename
135d['upload_date'] =  DateTime.DateTime()
136d['import_layout'] = ds.get('import_layout','')
137d['uploaded_by'] = str(member)
138d['url'] = upload.absolute_url()
139upload.getContent().edit(mapping=d)
140logger.info('%s uploaded file %s with import layout %s' % (member,filename,d['import_layout']))
141
142return request.RESPONSE.redirect(context.absolute_url())
143
144
Note: See TracBrowser for help on using the repository browser.