source: main/waeup.kofa/trunk/src/waeup/kofa/hostels/batching.py @ 13344

Last change on this file since 13344 was 13159, checked in by Henrik Bettermann, 9 years ago

Enable import of list-of-choices fields.

  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1## $Id: batching.py 13159 2015-07-10 11:33:03Z 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 components for hostels.
19
20"""
21import grok
22from zope.interface import Interface
23from waeup.kofa.interfaces import IBatchProcessor, IGNORE_MARKER
24from waeup.kofa.utils.batching import BatchProcessor
25from waeup.kofa.hostels.interfaces import IHostel
26from waeup.kofa.interfaces import MessageFactory as _
27
28class HostelProcessor(BatchProcessor):
29    """The Hostel Procesor imports hostels, i.e. the container objects of
30    beds. It does not import beds. There is nothing special about this
31    processor.
32    """
33    grok.implements(IBatchProcessor)
34    grok.provides(IBatchProcessor)
35    grok.context(Interface)
36    util_name = 'hostelprocessor'
37    grok.name(util_name)
38
39    name = _('Hostel Processor')
40    iface = IHostel
41
42    location_fields = ['hostel_id',]
43    factory_name = 'waeup.Hostel'
44
45    mode = None
46
47    def parentsExist(self, row, site):
48        return 'hostels' in site.keys()
49
50    def entryExists(self, row, site):
51        return row['hostel_id'] in site['hostels'].keys()
52
53    def getParent(self, row, site):
54        return site['hostels']
55
56    def getEntry(self, row, site):
57        if not self.entryExists(row, site):
58            return None
59        parent = self.getParent(row, site)
60        return parent.get(row['hostel_id'])
61
62    def addEntry(self, obj, row, site):
63        parent = self.getParent(row, site)
64        parent.addHostel(obj)
65        return
66
67    def updateEntry(self, obj, row, site, filename):
68        """Update obj to the values given in row.
69        """
70        items_changed = super(HostelProcessor, self).updateEntry(
71            obj, row, site, filename)
72        # Log actions...
73        location_field = self.location_fields[0]
74        grok.getSite()['hostels'].logger.info(
75            '%s - %s - %s - updated: %s'
76            % (self.name, filename, row[location_field], items_changed))
77        return
Note: See TracBrowser for help on using the repository browser.