[12438] | 1 | ## $Id: container.py 12438 2015-01-11 08:27:37Z henrik $ |
---|
[12437] | 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 | """ |
---|
| 19 | Containers which contain document objects. |
---|
| 20 | """ |
---|
| 21 | import grok |
---|
| 22 | from grok import index |
---|
| 23 | from waeup.kofa.interfaces import IKofaPluggable |
---|
| 24 | from waeup.kofa.documents.interfaces import IDocumentsContainer, IDocument |
---|
| 25 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
| 26 | from waeup.kofa.utils.logger import Logger |
---|
| 27 | |
---|
| 28 | class DocumentsContainer(grok.Container, Logger): |
---|
| 29 | """This is a container for all kind of documents. |
---|
| 30 | """ |
---|
| 31 | grok.implements(IDocumentsContainer) |
---|
| 32 | grok.provides(IDocumentsContainer) |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | def addDocument(self, document): |
---|
| 36 | if not IDocument.providedBy(document): |
---|
| 37 | raise TypeError( |
---|
| 38 | 'DocumentsContainers contain only IDocument instances') |
---|
| 39 | self[document.document_id] = document |
---|
| 40 | return |
---|
| 41 | |
---|
| 42 | DocumentsContainer = attrs_to_fields(DocumentsContainer) |
---|
| 43 | |
---|
| 44 | class DocumentsPlugin(grok.GlobalUtility): |
---|
| 45 | """A plugin that creates container for documents inside a company. |
---|
| 46 | """ |
---|
| 47 | grok.implements(IKofaPluggable) |
---|
| 48 | grok.name('documents') |
---|
| 49 | |
---|
| 50 | def setup(self, site, name, logger): |
---|
| 51 | if 'documents' in site.keys(): |
---|
| 52 | logger.warn('Could not create container for documents.') |
---|
| 53 | return |
---|
| 54 | site['documents'] = DocumentsContainer() |
---|
| 55 | logger.info('Container for documents created') |
---|
| 56 | return |
---|
| 57 | |
---|
| 58 | def update(self, site, name, logger): |
---|
| 59 | if not 'documents' in site.keys(): |
---|
| 60 | self.setup(site, name, logger) |
---|