## $Id: batching.py 7264 2011-12-04 13:34:26Z uli $ ## ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## """Batch processing for applicants. """ import grok from zope.interface import Interface from waeup.sirp.interfaces import IBatchProcessor from waeup.sirp.utils.batching import BatchProcessor from waeup.sirp.applicants.interfaces import ( IApplicantsContainer, IApplicant) class ApplicantsContainerImporter(BatchProcessor): """An importer for applicants containers. """ grok.implements(IBatchProcessor) grok.provides(IBatchProcessor) grok.context(Interface) util_name = 'applicants container importer' grok.name(util_name) name = u'Applicants Container Importer' mode = u'create' iface = IApplicantsContainer location_fields = ['code',] factory_name = 'waeup.ApplicantsContainer' def parentsExist(self, row, site): return 'applicants' in site.keys() def entryExists(self, row, site): return row['code'] in site['applicants'].keys() def getParent(self, row, site): return site['applicants'] def getEntry(self, row, site): if not self.entryExists(row, site): return None parent = self.getParent(row, site) return parent.get(row['code']) def addEntry(self, obj, row, site): parent = self.getParent(row, site) parent[row['code']] = obj return def delEntry(self, row, site): parent = self.getParent(row, site) del parent[row['code']] return class ApplicantImporter(BatchProcessor): """A batch processor for IApplicant objects. """ grok.implements(IBatchProcessor) grok.provides(IBatchProcessor) grok.context(Interface) util_name = 'applicantimporter' grok.name(util_name) name = u'Applicant Importer' iface = IApplicant location_fields = [] factory_name = 'waeup.Applicant' location_fields = ['container_code', 'application_number'] mode = None @property def req(self): result = dict( create = ['container_code'] + self.required_fields, update = self.location_fields, remove = self.location_fields, ) return result def parentsExist(self, row, site): if not 'applicants' in site.keys(): return False return row['container_code'] in site['applicants'].keys() def entryExists(self, row, site): return self.getEntry(row, site) is not None def getParent(self, row, site): return site['applicants'][row['container_code']] def getEntry(self, row, site): if not self.parentsExist(row, site): return None parent = self.getParent(row, site) return parent.get(row.get('application_number', None), None) def addEntry(self, obj, row, site): parent = self.getParent(row, site) parent.addApplicant(obj) return def delEntry(self, row, site): if self.entryExists(row, site): parent = self.getParent(row, site) del parent[row['application_number']] pass