Ignore:
Timestamp:
4 Dec 2011, 08:36:14 (13 years ago)
Author:
Henrik Bettermann
Message:

Add Applicant Importer (tests will follow).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/batching.py

    r7192 r7262  
    2222from waeup.sirp.interfaces import IBatchProcessor
    2323from waeup.sirp.utils.batching import BatchProcessor
    24 from waeup.sirp.applicants.interfaces import IApplicantsContainer
     24from waeup.sirp.applicants.interfaces import (
     25    IApplicantsContainer, IApplicant)
    2526
    2627class ApplicantsContainerImporter(BatchProcessor):
     
    6465        del parent[row['code']]
    6566        return
     67
     68class ApplicantProcessor(BatchProcessor):
     69    """A batch processor for IApplicant objects.
     70    """
     71    grok.implements(IBatchProcessor)
     72    grok.provides(IBatchProcessor)
     73    grok.context(Interface)
     74    util_name = 'applicantimporter'
     75    grok.name(util_name)
     76    name = u'Applicant Importer'
     77    iface = IApplicant
     78    location_fields = []
     79    factory_name = 'waeup.Applicant'
     80    location_fields = ['container_code', 'application_number']
     81
     82    mode = None
     83
     84    @property
     85    def req(self):
     86        result = dict(
     87            create = ['container_code'] + self.required_fields,
     88            update = self.location_fields,
     89            remove = self.location_fields,
     90        )
     91        return result
     92
     93    def parentsExist(self, row, site):
     94        if not 'applicants' in site.keys():
     95            return False
     96        return row['container_code'] in site['applicants'].keys()
     97
     98    def entryExists(self, row, site):
     99        if not self.parentsExist(row, site):
     100            return None
     101        parent = self.getParent(row, site)
     102        if 'application_number' in row.keys() and row['application_number']:
     103            if row['application_number'] in parent.keys():
     104                return parent[row['application_number']]
     105        return None
     106
     107    def getParent(self, row, site):
     108        return site['applicants'][row['container_code']]
     109
     110    def getEntry(self, row, site):
     111        return self.entryExists(row, site)
     112
     113    def addEntry(self, obj, row, site):
     114        parent = self.getParent(row, site)
     115        parent.addApplicant(obj)
     116        return
     117
     118    def delEntry(self, row, site):
     119        applicant = self.entryExists(row, site)
     120        if applicant:
     121            parent = self.getParent(row, site)
     122            del parent[row['application_number']]
     123        pass
Note: See TracChangeset for help on using the changeset viewer.