Changeset 3314 for WAeUP_SRP/base
- Timestamp:
- 10 Mar 2008, 19:12:40 (17 years ago)
- Location:
- WAeUP_SRP/base
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/Upload.py
r3292 r3314 14 14 from WAeUPImport import CourseImport,CourseResultImport 15 15 from WAeUPImport import DepartmentImport,FacultyImport,StudentImport,VerdictImport 16 from WAeUPImport import NO_KEY 17 16 18 import logging 17 19 import csv,re,os … … 21 23 p_home = Globals.package_home(globals()) 22 24 i_home = Globals.INSTANCE_HOME 23 24 25 storage_path = "%s/%s" % (i_home,'import') 25 26 … … 53 54 portal_type = meta_type 54 55 security = ClassSecurityInfo() 55 56 NO_KEY = NO_KEY 56 57 security.declareProtected(View,"Title") ###( 57 58 def Title(self): … … 69 70 msg = '' 70 71 invalid_keys = [] 72 keys = [] 71 73 if not os.path.exists(csv_path): 72 74 base,ext = os.path.splitext(csv_path) … … 79 81 msg = 'No such file %(base_path)s' % vars() 80 82 else: 81 headline = csv.reader(open(csv_path,"rb")).next() 83 reader = csv.reader(open(csv_path,"rb")) 84 headline = reader.next() 85 values = reader.next() 82 86 if "import_mode" not in headline: 83 87 msg += 'import_mode must be in heading' … … 85 89 if invalid_keys: 86 90 msg += "invalid keys in heading" 87 return msg,invalid_keys 88 91 keys = importer.getHeadlineFields(headline,values) 92 return msg,keys 93 ###) 94 89 95 security.declareProtected(View,"getFields") ###( 90 96 def getKeys(self): … … 102 108 doc = self.getContent() 103 109 return os.stat(os.path.join(storage_path,doc.filename)) 104 110 ###) 111 105 112 security.declareProtected(ModifyPortalContent,"editHeadline") ###( 106 113 def editHeadline(self,key_pairs): -
WAeUP_SRP/base/WAeUPImport.py
r3292 r3314 50 50 i_home = INSTANCE_HOME 51 51 from utils import makeDigest 52 53 NO_KEY = '----' 52 54 53 55 class WAeUPImport(UniqueObject, SimpleItem, ActionProviderBase): ###( … … 147 149 return list(diff2schema) 148 150 return [] 151 ###) 152 153 def getHeadlineFields(self,headline,values): ###( 154 """ check the headline of an csv.file """ 155 import_keys = [k.strip() for k in headline if not (k.strip().startswith('ignore') 156 or k.strip() in self.info.keys())] 157 si = set(import_keys) 158 ss = set(self.schema.keys()) 159 160 invalid_keys = si - ss 161 diff2layout = set(import_keys).difference(set(self.layout.keys())) 162 keys = [] 163 i = 0 164 for k in import_keys: 165 if k in invalid_keys: 166 keys += (k,NO_KEY,values[i]), 167 else: 168 keys += (k,k,values[i]), 169 i += 1 170 return keys 149 171 ###) 150 172 ###) -
WAeUP_SRP/base/skins/waeup_upload/uploads_form.pt
r3308 r3314 36 36 <th>Upload Date</th> 37 37 <th>Error Message</th> 38 <th>Invalid Keys</th>39 38 </tr> 40 <tr tal:repeat="row info/wrong" 41 tal:attributes="class python:test(repeat['row'].even(), 'even ajaxtd', 'odd ajaxtd')"> 42 <td align="left" valign="middle" style="width: 5px;"> 43 <input type="checkbox" name="ids:list" value="" id="" class="noborder" 44 tal:define="id string:${row/id}.csv" 45 tal:attributes="value id; 46 id python:'cb_' + id; 47 checked python:id in info['choosen_ids'];" 48 /> 49 </td> 50 <td tal:condition="nothing"> <a href="view" tal:attributes="href string:${row/url}"> <span tal:content="row/id" /></a> </td> 51 <td tal:content="string:${row/id}.csv" ></td> 52 <td> 53 <select name="import_layout:record" tal:attributes="name string:${row/id}.import_layout:record"> 54 <option tal:repeat="option python: context.portal_vocabularies.import_names.items()" 55 tal:attributes="value python: option[0]; 56 selected python: option[0] == row['import_layout']" 57 tal:content="python:option[1]" /> 58 </select> 59 </td> 60 <td tal:content="row/uploaded_by" ></td> 61 <td tal:content="row/upload_date" ></td> 62 <td tal:content="row/msg" ></td> 63 <td> 64 <div tal:repeat="key row/invalid_keys"> 65 <span tal:replace="key" /><br /> 66 <select tal:attributes="name string:${row/id}|${key}.valid_key:record"> 39 <span tal:repeat="row info/wrong" tal:omit-tag=""> 40 <tr tal:attributes="class python:test(repeat['row'].even(), 'even ajaxtd', 'odd ajaxtd')"> 41 <td align="left" valign="middle" style="width: 5px;"> 42 <input type="checkbox" name="ids:list" value="" id="" class="noborder" 43 tal:define="id string:${row/id}.csv" 44 tal:attributes="value id; 45 id python:'cb_' + id; 46 checked python:id in info['choosen_ids'];" 47 /> 48 </td> 49 <td tal:condition="nothing"> <a href="view" tal:attributes="href string:${row/url}"> <span tal:content="row/id" /></a> </td> 50 <td tal:content="string:${row/id}.csv" ></td> 51 <td> 52 <select name="import_layout:record" tal:attributes="name string:${row/id}.import_layout:record"> 53 <option tal:repeat="option python: context.portal_vocabularies.import_names.items()" 54 tal:attributes="value python: option[0]; 55 selected python: option[0] == row['import_layout']" 56 tal:content="python:option[1]" /> 57 </select> 58 </td> 59 <td tal:content="row/uploaded_by" ></td> 60 <td tal:content="row/upload_date" ></td> 61 <td tal:content="row/msg" ></td> 62 </tr> 63 <tr> 64 <th>Current</th> 65 <th>Possible</th> 66 <th>Value from 1. record</th> 67 </tr> 68 <tr tal:repeat="key row/invalid_keys"> 69 <td colspan="1"> 70 <font tal:attributes="color python: test(key[1] == '----','red','black')" tal:content="python: key[0]" /> 71 </td> 72 <td colspan="1" 73 tal:define="old_key python: key[0];new_key python: key[1];"> 74 <select tal:attributes="name string:${row/id}|${old_key}.valid_key:record"> 67 75 <option tal:repeat="new row/valid_keys" 68 tal:attributes="value new "76 tal:attributes="value new; selected python: new == new_key" 69 77 tal:content="new" /> 70 </select> 71 </div> 72 </td> 73 <td tal:condition="python:0"> 74 <a href="edit" tal:attributes="href string:${row/url}/external_edit_form" 75 target="edit" 76 onclick="javascript:window.open('','edit','width=600, height=700, directories=no, toolbar=no, location=no, menubar=no, scrollbars=yes, status=no, resizable=no, dependent=no')"> 77 [edit] 78 </a> 79 </td> 80 </tr> 81 </table> 78 </select><br /> 79 </td> 80 <td colspan="1" tal:content="python: key[2]" /> 81 </tr> 82 </span> 83 </table> 82 84 83 85 <br /> … … 149 151 (cpsmcat('description_confirm_delete'), )" 150 152 /> 153 <input type="submit" name="goto_edit" value="Edit again" 154 class="destructive" i18n:attributes="value" 155 /> 151 156 <input type="submit" name="folder_delete:method" value="button_delete" 152 157 class="destructive" i18n:attributes="value" -
WAeUP_SRP/base/skins/waeup_upload/uploads_index.py
r3313 r3314 29 29 30 30 path_info = request.get('PATH_INFO').split('/') 31 NO_KEY = '----'32 31 info = {} 33 32 info['action'] = "%s" % context.absolute_url() … … 47 46 msg, invalid_keys = doc['checkKeys']() 48 47 new_keys = [] 49 for keyin invalid_keys:50 id_key = "%s|%s" % (short_id, key)48 for old_key,previous,value in invalid_keys: 49 id_key = "%s|%s" % (short_id,old_key) 51 50 if request.form.has_key(id_key): 52 51 new_key = request.form.get(id_key)['valid_key'] 53 if new_key != NO_KEY:54 new_keys += ( key,new_key),52 if new_key != old_key and new_key != doc.NO_KEY: 53 new_keys += (old_key,new_key), 55 54 if new_keys: 56 55 doc.editHeadline(new_keys) 57 56 for key in new_keys: 58 57 logger.info('%s changed column heading in file %s from %s to %s' % (member,long_id,key[0],key[1])) 58 return request.RESPONSE.redirect(context.absolute_url()) 59 59 60 60 wrong = [] … … 66 66 doc = upload.getContent() 67 67 row['valid_keys'] = doc['getKeys']() 68 row['valid_keys'][0 ] = NO_KEY68 row['valid_keys'][0:0] = doc.NO_KEY, 69 69 row['id'] = id.replace('.csv','') 70 70 row['title'] = doc.filename … … 75 75 if import_message: 76 76 row['imported'] = True 77 row['imported_by'] = getattr('doc','imported_by','') 77 78 row['msg'] = import_message 78 79 if getattr(doc,'import_date',''): … … 83 84 else: 84 85 row['msg'],row['invalid_keys'] = doc['checkKeys']() 85 if not row['msg'] and not row['invalid_keys']:86 if not (request.has_key('goto_edit') and id in ids) and not row['msg']: 86 87 add_to = importable 87 88 row['filename'] = doc.filename 88 89 row['import_layout'] = doc.import_layout 90 row['uploaded_by'] = doc.uploaded_by 89 91 row['upload_date'] = doc.upload_date.strftime("%d/%m/%y %H:%M:%S") 90 row['uploaded_by'] = doc.uploaded_by91 92 row['imported_by'] = doc.imported_by 92 93 add_to.append(row)
Note: See TracChangeset for help on using the changeset viewer.