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 | """ |
---|
12 | return Info about the Uploads |
---|
13 | """ |
---|
14 | import DateTime |
---|
15 | try: |
---|
16 | from Products.zdb import set_trace |
---|
17 | except: |
---|
18 | def set_trace(): |
---|
19 | pass |
---|
20 | request = context.REQUEST |
---|
21 | |
---|
22 | wf = context.portal_workflow |
---|
23 | mtool = context.portal_membership |
---|
24 | member = mtool.getAuthenticatedMember() |
---|
25 | |
---|
26 | path_info = request.get('PATH_INFO').split('/') |
---|
27 | NO_KEY = '----' |
---|
28 | info = {} |
---|
29 | info['action'] = "%s" % context.absolute_url() |
---|
30 | info['choosen_ids'] = request.get('ids',[]) |
---|
31 | info['doc'] = context.getContent() |
---|
32 | |
---|
33 | items = [] |
---|
34 | edit = request.form.has_key('edit') |
---|
35 | ids = request.get('ids',[]) |
---|
36 | #set_trace() |
---|
37 | if edit and ids: |
---|
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]) |
---|
42 | msg, invalid_keys = doc['checkKeys']() |
---|
43 | new_keys = [] |
---|
44 | for key in invalid_keys: |
---|
45 | id_key = "%s|%s" % (short_id,key) |
---|
46 | if request.form.has_key(id_key): |
---|
47 | new_key = request.form.get(id_key)['valid_key'] |
---|
48 | if new_key != NO_KEY: |
---|
49 | new_keys += (key,new_key), |
---|
50 | if new_keys: |
---|
51 | doc.editHeadline(new_keys) |
---|
52 | request.RESPONSE.redirect(context.absolute_url()) |
---|
53 | |
---|
54 | for id,upload in context.objectItems(): |
---|
55 | row = {} |
---|
56 | doc = upload.getContent() |
---|
57 | row['valid_keys'] = doc['getKeys']() |
---|
58 | row['valid_keys'][0] = NO_KEY |
---|
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']() |
---|
63 | row['filename'] = doc.filename |
---|
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) |
---|
68 | items.sort() |
---|
69 | info['items'] = items |
---|
70 | |
---|
71 | validate = "upload" in request.keys() |
---|
72 | mode = "edit" |
---|
73 | res,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 | ) |
---|
81 | while 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 |
---|
94 | psm = "Upload object exists!" |
---|
95 | return context.uploads_form(rendered = res, |
---|
96 | psm = psm, |
---|
97 | ds = ds, |
---|
98 | mode = mode, |
---|
99 | info = info, |
---|
100 | ) |
---|
101 | |
---|
102 | context.invokeFactory('Upload',filename) |
---|
103 | upload = getattr(context,filename) |
---|
104 | d = {} |
---|
105 | d['filename'] = d['id'] = filename |
---|
106 | d['upload_date'] = DateTime.DateTime() |
---|
107 | d['import_layout'] = ds.get('import_layout','') |
---|
108 | d['uploaded_by'] = str(member) |
---|
109 | d['url'] = upload.absolute_url() |
---|
110 | upload.getContent().edit(mapping=d) |
---|
111 | |
---|
112 | request.RESPONSE.redirect(context.absolute_url()) |
---|
113 | |
---|