Changeset 3316 for WAeUP_SRP


Ignore:
Timestamp:
11 Mar 2008, 14:16:31 (17 years ago)
Author:
joachim
Message:

allow ignore,
check for duplicates

Location:
WAeUP_SRP/base
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/base/Upload.py

    r3314 r3316  
    1414from WAeUPImport import CourseImport,CourseResultImport
    1515from WAeUPImport import DepartmentImport,FacultyImport,StudentImport,VerdictImport
    16 from WAeUPImport import NO_KEY
     16from WAeUPImport import NO_KEY,IGNORE
    1717 
    1818import logging
     
    5555    security = ClassSecurityInfo()
    5656    NO_KEY = NO_KEY
     57    IGNORE = IGNORE
    5758    security.declareProtected(View,"Title") ###(
    5859    def Title(self):
     
    8990            if invalid_keys:
    9091                msg += "invalid keys in heading"
    91             keys = importer.getHeadlineFields(headline,values)
     92            err,keys = importer.getHeadlineFields(headline,values)
     93            if err:
     94                msg += err
    9295        return msg,keys
    9396    ###)
     
    120123        records = [record for record in reader]
    121124        #import pdb;pdb.set_trace()
    122         for old,new in key_pairs:
    123             pos = headline.index(old)
     125        for old,new,pos in key_pairs:
    124126            del headline[pos]
    125127            headline.insert(pos,new)
  • WAeUP_SRP/base/WAeUPImport.py

    r3315 r3316  
    5252
    5353NO_KEY = '----'
    54 
     54IGNORE = 'ignore'
    5555class WAeUPImport(UniqueObject, SimpleItem, ActionProviderBase): ###(
    5656    """ WAeUPImport """
     
    143143        import_keys = [k.strip() for k in headline if not (k.strip().startswith('ignore')
    144144                                                        or k.strip() in self.info.keys())]
     145        # import_keys = [k.strip() for k in headline if not (k.strip() in self.info.keys())]
    145146        diff2schema = set(import_keys).difference(set(self.schema.keys()))
    146147        diff2layout = set(import_keys).difference(set(self.layout.keys()))
     
    153154    def getHeadlineFields(self,headline,values): ###(
    154155        """ check the headline of a 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         import_keys = [k.strip() for k in headline]                                                       
     156        # import_keys = [k.strip() for k in headline if not (k.strip().startswith('ignore')
     157        #                                                 or k.strip() in self.info.keys())]
     158        import_keys = [k.strip() for k in headline if not (k.strip() in self.info.keys())]
    158159        si = set(import_keys)
    159160        ss = set(self.schema.keys())
    160161
    161162        invalid_keys = si - ss
    162         #diff2layout = set(import_keys).difference(set(self.layout.keys()))
    163163        keys = []
    164164        i = 0
    165         for k in import_keys:
    166             if k in invalid_keys:
    167                 keys += (k,NO_KEY,values[i]),
    168             else:
    169                 keys += (k,k,values[i]),
    170             i += 1
    171         return keys
     165        duplicates = False
     166        singels = []
     167        msg = ''
     168        while True:
     169            if len(values) != len(import_keys):
     170                msg += "%d fields in headline but %d values" % (len(import_keys),len(values))
     171                break
     172            for k in import_keys:
     173                if k in singels:
     174                    keys += (k,'DUP_%s' % k,values[i],'duplicate'),
     175                    msg += ("duplicate %s," % k)
     176                    keys[singels.index(k)] = (k,'DUP_%s' % k,values[singels.index(k)],'duplicate')
     177                elif k in invalid_keys and not k.startswith(IGNORE):
     178                    keys += (k,NO_KEY,values[i],'invalid'),
     179                else:
     180                    keys += (k,k,values[i],''),
     181                i += 1
     182                singels += k,
     183            break
     184        return msg,keys
    172185    ###)
    173186###)
  • WAeUP_SRP/base/skins/waeup_upload/uploads_form.pt

    r3315 r3316  
    6666                <th>Value from 1. record</th>
    6767              </tr>
    68               <tr tal:repeat="key row/invalid_keys">
     68              <tr tal:repeat="key row/fields">
    6969                <td colspan="1">
    70                   <font tal:attributes="color python: test(key[1] == '----' and not key[0].startswith('ignore'),'red','black')" tal:content="python: key[0]" />
     70                  <font tal:attributes="color python: test(key[3],'red','black')">
     71                    <span tal:content="python: key[1]" tal:omit-tag=""/>
     72                    <span tal:condition="python: key[3]" tal:content="python: key[3]" tal:omit-tag=""/>
     73                  </font>
    7174                </td>
    7275                <td colspan="1"
    7376                    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">
     77                  <select tal:attributes="name string:${row/id}|${repeat/key/index}.valid_key:record">
    7578                    <option tal:repeat="new row/valid_keys"
    76                             tal:attributes="value new; selected python: new == new_key"
     79                            tal:attributes="value new; selected python: new_key == new"
    7780                            tal:content="new" />
    7881                  </select><br />
  • WAeUP_SRP/base/skins/waeup_upload/uploads_index.py

    r3314 r3316  
    3636edit = request.form.has_key('edit')
    3737ids = request.get('ids',[])
    38 #set_trace()
    3938if edit and ids:
    4039    for long_id in ids:
     
    4645        msg, invalid_keys = doc['checkKeys']()
    4746        new_keys = []
    48         for old_key,previous,value in invalid_keys:
    49             id_key = "%s|%s" % (short_id,old_key)
     47        i = 0
     48        for old_key,previous,value,err in invalid_keys:
     49            id_key = "%s|%s" % (short_id,i)
    5050            if request.form.has_key(id_key):
    5151                new_key = request.form.get(id_key)['valid_key']
    52                 if new_key != old_key and new_key != doc.NO_KEY:
    53                     new_keys += (old_key,new_key),
     52                if new_key != old_key:
     53                    if new_key == doc.IGNORE:
     54                        new_keys += (old_key,"%s_%s" % (doc.IGNORE,old_key),i),
     55                    elif new_key != doc.NO_KEY:
     56                        new_keys += (old_key,new_key,i),
     57            i += 1
    5458        if new_keys:
    5559            doc.editHeadline(new_keys)
    5660            for key in new_keys:
    57                 logger.info('%s changed column heading in file %s from %s to %s' % (member,long_id,key[0],key[1]))
     61                logger.info('%s changed column %s heading in file %s from %s to %s' % (member,
     62                                                                                    key[2],
     63                                                                                    long_id,
     64                                                                                    key[0],
     65                                                                                    key[1]))
    5866    return request.RESPONSE.redirect(context.absolute_url())
    5967
     
    6775    row['valid_keys'] = doc['getKeys']()
    6876    row['valid_keys'][0:0] = doc.NO_KEY,
     77    row['valid_keys'][1:1] = doc.IGNORE,
    6978    row['id'] = id.replace('.csv','')
    7079    row['title'] = doc.filename
    7180    row['url'] = upload.absolute_url()
    7281    row['imported'] = False
    73     row['invalid_keys'] = []
     82    row['fields'] = []
    7483    import_message = getattr(doc,'import_message','')
    7584    if import_message:
     
    8392        add_to = imported
    8493    else:
    85         row['msg'],row['invalid_keys'] = doc['checkKeys']()
     94        row['msg'],row['fields'] = doc['checkKeys']()
    8695        if not (request.has_key('goto_edit') and id in ids) and not row['msg']:
    8796            add_to = importable
Note: See TracChangeset for help on using the changeset viewer.