Changeset 3325 for WAeUP_SRP/base


Ignore:
Timestamp:
12 Mar 2008, 14:06:44 (17 years ago)
Author:
joachim
Message:

pending and errors can be downloaded,
line_nr of wrong record added

Location:
WAeUP_SRP/base
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/base/Upload.py

    r3319 r3325  
    5656    NO_KEY = NO_KEY
    5757    IGNORE = IGNORE
     58    def getImporter(self):
     59        importer_name = ''.join([part.capitalize() for part in self.getContent().import_layout.split('_')])
     60        importer = eval("%sImport" % importer_name)(self)
     61        return importer
     62   
    5863    security.declareProtected(View,"Title") ###(
    5964    def Title(self):
     
    6772        doc = self.getContent()
    6873        csv_path = os.path.join(storage_path,doc.filename)
    69         importer_name = ''.join([part.capitalize() for part in self.getContent().import_layout.split('_')])
    70         importer = eval("%sImport" % importer_name)(self)
     74        importer = self.getImporter()
    7175        msg = ''
    7276        invalid_keys = []
     
    99103    def getKeys(self):
    100104        """return the valid keys for headline"""
    101         importer_name = ''.join([part.capitalize() for part in self.getContent().import_layout.split('_')])
    102         importer = eval("%sImport" % importer_name)(self)
     105        importer = self.getImporter()
    103106        keys = importer.schema.keys()
    104107        keys.sort()
     
    113116    ###)
    114117
     118    security.declareProtected(ModifyPortalContent,"getPending") ###(
     119    def getPending(self):
     120        """return pending-data"""
     121        importer = self.getImporter()
     122        data = open(importer.pending_path).read()
     123        return importer.pending_fn,data
     124
     125    security.declareProtected(ModifyPortalContent,"getPending") ###(
     126    def getErrors(self):
     127        """return import_errors"""
     128        import tempfile
     129        importer = self.getImporter()
     130        lines = []
     131        filename = self.getContent().filename
     132        data = open(importer.pending_path)
     133        reader = csv.reader(data)
     134        headline = reader.next()
     135        reader = csv.DictReader(data,headline)
     136        # imported_from_pos = headline.index('imported_from')
     137        # imported_line_nr_pos = headline.index('imported_line_nr')
     138        out_file = tempfile.TemporaryFile()
     139        writer = csv.DictWriter(out_file,
     140                                importer.info.keys(),
     141                                extrasaction='ignore')
     142        lines += dict([(k,k) for k in importer.info.keys()]),
     143        #import pdb;pdb.set_trace()
     144        for item in reader:
     145            if item["imported_from"] == filename:
     146                lines += item,
     147        writer.writerows(lines)
     148        out_file.seek(0)
     149        return out_file.read()
     150
    115151    security.declareProtected(ModifyPortalContent,"editHeadline") ###(
    116152    def editHeadline(self,key_pairs):
    117153        """edit headline"""
    118         importer_name = ''.join([part.capitalize() for part in self.getContent().import_layout.split('_')])
    119         importer = eval("%sImport" % importer_name)(self)
    120154        csv_path = os.path.join(storage_path,self.filename)
    121155        reader = csv.reader(open(csv_path,"rb"))
  • WAeUP_SRP/base/WAeUPImport.py

    r3320 r3325  
    103103            info = {}
    104104            info['imported_from'] = ''
    105             info['imported_by'] =  self.imported_by
     105            info['import_line_nr'] = 0
     106            info['imported_by'] = self.imported_by
    106107            info['import_date'] = self.import_date.strftime("%d/%m/%y %H:%M:%S")
    107108            info['error'] = ''
     
    128129        if os.path.exists(self.pending_path):
    129130            datafile = open(self.pending_path,"r")
    130             pending_csv_reader = csv.DictReader(datafile,self.csv_keys,)
    131             pending_csv_reader.next() # skip headline
     131            reader = csv.reader(datafile)
     132            old_headline = reader.next()
     133            #datafile.seek(0)
     134            pending_csv_reader = csv.DictReader(datafile,old_headline,)
     135            #pending_csv_reader.next() # skip headline
    132136            for item in pending_csv_reader:
    133137                digest = makeDigest(item,self.data_keys)
     
    169173        while True:
    170174            if len(values) != len(import_keys):
    171                 msg += "+ %d fields in headline but %d values +" % (len(import_keys),len(values))
     175                msg += "%d fields in headline but %d values" % (len(import_keys),len(values))
    172176                break
    173177            for k in import_keys:
    174178                if k in singels:
    175179                    keys += (k,'%s' % k,values[i],'(duplicate)'),
    176                     msg += ("+ duplicate %s +" % k)
     180                    msg += ("duplicate %s," % k)
    177181                    keys[singels.index(k)] = (k,'%s' % k,values[singels.index(k)],'(duplicate)')
    178182                elif k in invalid_keys and not k.startswith(IGNORE):
     
    186190    ###)
    187191###)
    188 
    189192
    190193class ApplicationImport(WAeUPImport):###(
  • WAeUP_SRP/base/WAeUPTool.py

    r3321 r3325  
    936936        da['jamb_sex'] = sex
    937937        da['jamb_age'] = brain.jamb_age
    938         da['app_reg_pin'] = brain.pin
     938        #da['app_ac_pin'] = brain.pin
    939939        da['jamb_lga'] = brain.jamb_lga
    940940        da['jamb_state'] = brain.jamb_state
     
    14121412        #current = importer.current
    14131413        import_date = importer.import_date
    1414         imported_by = importer.imported_by
    14151414        #
    14161415        # not_imported
     
    15651564            data_string = ", ".join("%s: %s" % (k,v) for k,v in mapping.items())
    15661565            info['error'] = error
     1566            info['import_line_nr'] = count + 1
    15671567            mapping.update(info)
    15681568            log_list = []
     
    16391639                #mapping['import_date'] = DateTime.DateTime()
    16401640                mapping['import_date'] = import_date
    1641                 mapping['imported_by'] = imported_by
     1641                mapping['imported_by'] = member
    16421642                mapping['import_message'] = msg
    16431643                upload_doc.edit(mapping = mapping)
  • WAeUP_SRP/base/skins/waeup_upload/uploads_form.pt

    r3319 r3325  
    180180          <table tal:condition="python: 1" class="contentListing" width="100%" summary="content layout" id="folder_content">     
    181181            <tr>
     182              <th>Download</th>
    182183              <th>File in Archive</th>
    183184              <th>Data Layout</th>
     
    190191            <tr tal:repeat="row info/imported"
    191192                tal:attributes="class python:test(repeat['row'].even(), 'even ajaxtd', 'odd ajaxtd')">
    192               <td tal:condition="nothing"> <a href="view" tal:attributes="href string:${row/url}"> <span tal:content="row/id" /></a>  </td>
     193              <td> <a href="view" tal:attributes="href string:${row/url}/download_pending">pending</a> <br />
     194                              <a href="view" tal:attributes="href string:${row/url}/download_errors">errors</a>  </td>
    193195              <td tal:content="string:${row/id}.done" ></td>
    194196              <td tal:content="row/import_layout"></td>
  • WAeUP_SRP/base/skins/waeup_upload/uploads_index.py

    r3316 r3325  
    8787        row['msg'] = import_message
    8888        if getattr(doc,'import_date',''):
    89             row['import_date'] = doc.import_date.strftime("%d/%m/%y %H:%M:%S")
     89            row['import_date'] = doc.import_date
    9090        else:
    9191            row['import_date'] = ''
    9292        add_to = imported
     93       
    9394    else:
    9495        row['msg'],row['fields'] = doc['checkKeys']()
Note: See TracChangeset for help on using the changeset viewer.