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

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

beautify upload form

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