source: main/waeup.kofa/trunk/src/waeup/kofa/hostels/export.py @ 9295

Last change on this file since 9295 was 9199, checked in by Henrik Bettermann, 12 years ago

Add hostels and beds exporter (tests will follow).

  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1## $Id: export.py 9199 2012-09-18 21:07:02Z henrik $
2##
3## Copyright (C) 2012 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"""Exporters for hostels and beds.
19"""
20import grok
21from zope.securitypolicy.interfaces import IPrincipalRoleMap
22from waeup.kofa.interfaces import ICSVExporter
23from waeup.kofa.interfaces import MessageFactory as _
24from waeup.kofa.utils.batching import ExporterBase
25from waeup.kofa.utils.helpers import iface_names
26from waeup.kofa.hostels.interfaces import IBed, IHostel
27
28class HostelExporter(grok.GlobalUtility, ExporterBase):
29    """Exporter for hostels.
30    """
31    grok.implements(ICSVExporter)
32    grok.name('hostels')
33
34    #: Fieldnames considered by this exporter
35    fields = tuple(sorted(iface_names(IHostel)))
36
37    #: The title under which this exporter will be displayed
38    title = _(u'Hostels')
39
40    def export_all(self, site, filepath=None):
41        """Export hostels into filepath as CSV data.
42
43        If `filepath` is ``None``, a raw string with CSV data is returned.
44        """
45        writer, outfile = self.get_csv_writer(filepath)
46        hostels = site.get('hostels', {})
47        for hostel in hostels.values():
48            self.write_item(hostel, writer)
49        return self.close_outfile(filepath, outfile)
50
51class BedExporter(grok.GlobalUtility, ExporterBase):
52    """Exporter for courses.
53    """
54    grok.implements(ICSVExporter)
55    grok.name('beds')
56
57    #: Fieldnames considered by this exporter
58    fields = tuple(sorted(iface_names(IBed))) + (
59        'hall', 'block', 'room', 'bed', 'special_handling', 'sex', 'bt')
60
61    #: The title under which this exporter will be displayed
62    title = _(u'Beds')
63
64    def export_all(self, site, filepath=None):
65        """Export beds into filepath as CSV data.
66
67        If `filepath` is ``None``, a raw string with CSV data is returned.
68        """
69        writer, outfile = self.get_csv_writer(filepath)
70        hostels = site.get('hostels', {})
71        for hostel in hostels.values():
72            for bed in hostel.values():
73                self.write_item(bed, writer)
74        return self.close_outfile(filepath, outfile)
75
Note: See TracBrowser for help on using the repository browser.