1 | ## $Id: batching.py 7264 2011-12-04 13:34:26Z uli $ |
---|
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 ( |
---|
25 | IApplicantsContainer, IApplicant) |
---|
26 | |
---|
27 | class ApplicantsContainerImporter(BatchProcessor): |
---|
28 | """An importer for applicants containers. |
---|
29 | """ |
---|
30 | grok.implements(IBatchProcessor) |
---|
31 | grok.provides(IBatchProcessor) |
---|
32 | grok.context(Interface) |
---|
33 | util_name = 'applicants container importer' |
---|
34 | grok.name(util_name) |
---|
35 | |
---|
36 | name = u'Applicants Container Importer' |
---|
37 | mode = u'create' |
---|
38 | iface = IApplicantsContainer |
---|
39 | |
---|
40 | location_fields = ['code',] |
---|
41 | factory_name = 'waeup.ApplicantsContainer' |
---|
42 | |
---|
43 | def parentsExist(self, row, site): |
---|
44 | return 'applicants' in site.keys() |
---|
45 | |
---|
46 | def entryExists(self, row, site): |
---|
47 | return row['code'] in site['applicants'].keys() |
---|
48 | |
---|
49 | def getParent(self, row, site): |
---|
50 | return site['applicants'] |
---|
51 | |
---|
52 | def getEntry(self, row, site): |
---|
53 | if not self.entryExists(row, site): |
---|
54 | return None |
---|
55 | parent = self.getParent(row, site) |
---|
56 | return parent.get(row['code']) |
---|
57 | |
---|
58 | def addEntry(self, obj, row, site): |
---|
59 | parent = self.getParent(row, site) |
---|
60 | parent[row['code']] = obj |
---|
61 | return |
---|
62 | |
---|
63 | def delEntry(self, row, site): |
---|
64 | parent = self.getParent(row, site) |
---|
65 | del parent[row['code']] |
---|
66 | return |
---|
67 | |
---|
68 | class ApplicantImporter(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 | return self.getEntry(row, site) is not None |
---|
100 | |
---|
101 | def getParent(self, row, site): |
---|
102 | return site['applicants'][row['container_code']] |
---|
103 | |
---|
104 | def getEntry(self, row, site): |
---|
105 | if not self.parentsExist(row, site): |
---|
106 | return None |
---|
107 | parent = self.getParent(row, site) |
---|
108 | return parent.get(row.get('application_number', None), None) |
---|
109 | |
---|
110 | def addEntry(self, obj, row, site): |
---|
111 | parent = self.getParent(row, site) |
---|
112 | parent.addApplicant(obj) |
---|
113 | return |
---|
114 | |
---|
115 | def delEntry(self, row, site): |
---|
116 | if self.entryExists(row, site): |
---|
117 | parent = self.getParent(row, site) |
---|
118 | del parent[row['application_number']] |
---|
119 | pass |
---|