1 | ## $Id: batching.py 7192 2011-11-25 07:15:50Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | """Batch processing for applicants. |
---|
19 | """ |
---|
20 | import grok |
---|
21 | from zope.interface import Interface |
---|
22 | from waeup.sirp.interfaces import IBatchProcessor |
---|
23 | from waeup.sirp.utils.batching import BatchProcessor |
---|
24 | from waeup.sirp.applicants.interfaces import IApplicantsContainer |
---|
25 | |
---|
26 | class ApplicantsContainerImporter(BatchProcessor): |
---|
27 | """An importer for applicants containers. |
---|
28 | """ |
---|
29 | grok.implements(IBatchProcessor) |
---|
30 | grok.provides(IBatchProcessor) |
---|
31 | grok.context(Interface) |
---|
32 | util_name = 'applicants container importer' |
---|
33 | grok.name(util_name) |
---|
34 | |
---|
35 | name = u'Applicants Container Importer' |
---|
36 | mode = u'create' |
---|
37 | iface = IApplicantsContainer |
---|
38 | |
---|
39 | location_fields = ['code',] |
---|
40 | factory_name = 'waeup.ApplicantsContainer' |
---|
41 | |
---|
42 | def parentsExist(self, row, site): |
---|
43 | return 'applicants' in site.keys() |
---|
44 | |
---|
45 | def entryExists(self, row, site): |
---|
46 | return row['code'] in site['applicants'].keys() |
---|
47 | |
---|
48 | def getParent(self, row, site): |
---|
49 | return site['applicants'] |
---|
50 | |
---|
51 | def getEntry(self, row, site): |
---|
52 | if not self.entryExists(row, site): |
---|
53 | return None |
---|
54 | parent = self.getParent(row, site) |
---|
55 | return parent.get(row['code']) |
---|
56 | |
---|
57 | def addEntry(self, obj, row, site): |
---|
58 | parent = self.getParent(row, site) |
---|
59 | parent[row['code']] = obj |
---|
60 | return |
---|
61 | |
---|
62 | def delEntry(self, row, site): |
---|
63 | parent = self.getParent(row, site) |
---|
64 | del parent[row['code']] |
---|
65 | return |
---|