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

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

Add more browser components for document editing. Editing is allowed only under certain conditions.

  • work in progress -
  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1## $Id: documents.py 12018 2014-11-21 08:07:15Z 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 import queryUtility, getUtility
23from zope.component.interfaces import IFactory
24from zope.interface import implementedBy
25from waeup.ikoba.interfaces import MessageFactory as _
26from waeup.ikoba.customers.interfaces import (
27    ICustomerDocumentsContainer, ICustomerNavigation, ICustomerDocument,
28    ICustomersUtils)
29from waeup.ikoba.documents import DocumentsContainer, Document
30from waeup.ikoba.documents.interfaces import IDocumentsUtils
31from waeup.ikoba.utils.helpers import attrs_to_fields
32
33class CustomerDocumentsContainer(DocumentsContainer):
34    """This is a container for customer documents.
35    """
36    grok.implements(ICustomerDocumentsContainer, ICustomerNavigation)
37    grok.provides(ICustomerDocumentsContainer)
38
39    def __init__(self):
40        super(CustomerDocumentsContainer, self).__init__()
41        return
42
43    @property
44    def customer(self):
45        return self.__parent__
46
47    def writeLogMessage(self, view, message):
48        return self.__parent__.writeLogMessage(view, message)
49
50CustomerDocumentsContainer = attrs_to_fields(CustomerDocumentsContainer)
51
52class CustomerDocument(Document):
53    """This is an document.
54    """
55    grok.implements(ICustomerDocument, ICustomerNavigation)
56    grok.provides(ICustomerDocument)
57
58    def __init__(self):
59        super(CustomerDocument, self).__init__()
60        return
61
62    @property
63    def customer(self):
64        try:
65            return self.__parent__.__parent__
66        except AttributeError:
67            return None
68
69    def writeLogMessage(self, view, message):
70        return self.__parent__.__parent__.writeLogMessage(view, message)
71
72    @property
73    def is_editable(self):
74        try:
75            # Customer must be approved
76            cond1 = self.customer.state in getUtility(
77                ICustomersUtils).DOCMANAGE_STATES
78            # Document must be in state created
79            cond2 = self.state in getUtility(
80                IDocumentsUtils).DOCMANAGE_STATES
81            if not (cond1 and cond2):
82                return False
83        except AttributeError:
84            pass
85        return True
86
87CustomerDocument = attrs_to_fields(CustomerDocument)
88
89
90# Customer documents must be importable. So we might need a factory.
91class CustomerDocumentFactory(grok.GlobalUtility):
92    """A factory for customer documents.
93    """
94    grok.implements(IFactory)
95    grok.name(u'waeup.CustomerDocument')
96    title = u"Create a new document.",
97    description = u"This factory instantiates new document instances."
98
99    def __call__(self, *args, **kw):
100        return CustomerDocument(*args, **kw)
101
102    def getInterfaces(self):
103        return implementedBy(CustomerDocument)
Note: See TracBrowser for help on using the repository browser.