## Script (Python) "uploads_index" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $Id:uploads_index.py 486 2006-09-06 10:09:39Z joachim $ """ return Info about the Uploads """ import DateTime import logging logger = logging.getLogger('Skins.upload_index') try: from Products.zdb import set_trace except: def set_trace(): pass request = context.REQUEST wf = context.portal_workflow mtool = context.portal_membership member = mtool.getAuthenticatedMember() path_info = request.get('PATH_INFO').split('/') NO_KEY = '----' info = {} info['action'] = "%s" % context.absolute_url() info['choosen_ids'] = request.get('ids',[]) info['doc'] = context.getContent() edit = request.form.has_key('edit') ids = request.get('ids',[]) #set_trace() if edit and ids: for long_id in ids: short_id = long_id.replace('.csv','') doc = getattr(context, long_id).getContent() logger.info('%s edited object %s' % (member,long_id)) doc.edit(mapping = request.form[short_id]) msg, invalid_keys = doc['checkKeys']() new_keys = [] for key in invalid_keys: id_key = "%s|%s" % (short_id,key) if request.form.has_key(id_key): new_key = request.form.get(id_key)['valid_key'] if new_key != NO_KEY: new_keys += (key,new_key), if new_keys: doc.editHeadline(new_keys) for key in new_keys: logger.info('%s changed column heading in file %s from %s to %s' % (member,long_id,key[0],key[1])) request.RESPONSE.redirect(context.absolute_url()) wrong = [] imported = [] importable = [] for id,upload in context.objectItems(): add_to = wrong row = {} doc = upload.getContent() row['valid_keys'] = doc['getKeys']() row['valid_keys'][0] = NO_KEY row['id'] = id.replace('.csv','') row['title'] = doc.filename row['url'] = upload.absolute_url() row['imported'] = False row['invalid_keys'] = [] import_message = getattr(doc,'import_message','') if import_message: row['imported'] = True row['msg'] = import_message row['imported_at'] = doc.imported_at.strftime("%d/%m/%y %H:%M:%S") add_to = imported else: row['msg'],row['invalid_keys'] = doc['checkKeys']() if not row['msg'] and not row['invalid_keys']: add_to = importable row['filename'] = doc.filename row['import_layout'] = doc.import_layout row['upload_date'] = doc.upload_date.strftime("%d/%m/%y %H:%M:%S") row['uploaded_by'] = doc.uploaded_by add_to.append(row) wrong.sort() imported.sort() importable.sort() info['wrong'] = wrong info['imported'] = imported info['importable'] = importable validate = "upload" in request.keys() mode = "edit" res,psm,ds = context.portal_layouts.renderLayout(layout_id = 'upload', schema_id = 'upload', layout_mode = mode, context=context, mapping=validate and request, ob= {}, commit = True, ) while True: if psm == 'invalid': psm = "Please correct your input!" # return context.uploads_form(rendered = res, # psm = "Please correct your input!", # mode = mode, # ds = ds, # info = info, # ) elif psm == 'valid': filename = ds['upload_file'].filename if filename not in context.objectIds(): break psm = "Upload object exists!" return context.uploads_form(rendered = res, psm = psm, ds = ds, mode = mode, info = info, ) context.invokeFactory('Upload',filename) upload = getattr(context,filename) d = {} d['filename'] = d['id'] = filename d['upload_date'] = DateTime.DateTime() d['import_layout'] = ds.get('import_layout','') d['uploaded_by'] = str(member) d['url'] = upload.absolute_url() upload.getContent().edit(mapping=d) logger.info('%s uploaded file %s' % (member,filename)) request.RESPONSE.redirect(context.absolute_url())