source: main/waeup.ikoba/trunk/src/waeup/ikoba/customers/documents.py @ 12005

Last change on this file since 12005 was 11997, checked in by Henrik Bettermann, 10 years ago

propset svn:keywords "Id"

  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1## $Id: documents.py 11997 2014-11-19 17:02:48Z henrik $
2##
3## Copyright (C) 2014 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"""
19Customer document components.
20"""
21import grok
22from zope.component.interfaces import IFactory
23from zope.interface import implementedBy
24from waeup.ikoba.interfaces import MessageFactory as _
25from waeup.ikoba.customers.interfaces import (
26    ICustomerDocumentsContainer, ICustomerNavigation, ICustomerDocument)
27from waeup.ikoba.documents import DocumentsContainer, Document
28from waeup.ikoba.utils.helpers import attrs_to_fields
29
30class CustomerDocumentsContainer(DocumentsContainer):
31    """This is a container for customer documents.
32    """
33    grok.implements(ICustomerDocumentsContainer, ICustomerNavigation)
34    grok.provides(ICustomerDocumentsContainer)
35
36    def __init__(self):
37        super(CustomerDocumentsContainer, self).__init__()
38        return
39
40    @property
41    def customer(self):
42        return self.__parent__
43
44    def writeLogMessage(self, view, message):
45        return self.__parent__.writeLogMessage(view, message)
46
47CustomerDocumentsContainer = attrs_to_fields(CustomerDocumentsContainer)
48
49class CustomerDocument(Document):
50    """This is an document.
51    """
52    grok.implements(ICustomerDocument, ICustomerNavigation)
53    grok.provides(ICustomerDocument)
54
55    def __init__(self):
56        super(CustomerDocument, self).__init__()
57        return
58
59    @property
60    def customer(self):
61        try:
62            return self.__parent__.__parent__
63        except AttributeError:
64            return None
65
66    def writeLogMessage(self, view, message):
67        return self.__parent__.__parent__.writeLogMessage(view, message)
68
69CustomerDocument = attrs_to_fields(CustomerDocument)
70
71
72# Customer documents must be importable. So we might need a factory.
73class CustomerDocumentFactory(grok.GlobalUtility):
74    """A factory for customer documents.
75    """
76    grok.implements(IFactory)
77    grok.name(u'waeup.CustomerDocument')
78    title = u"Create a new document.",
79    description = u"This factory instantiates new document instances."
80
81    def __call__(self, *args, **kw):
82        return CustomerDocument()
83
84    def getInterfaces(self):
85        return implementedBy(CustomerDocument)
Note: See TracBrowser for help on using the repository browser.