[11982] | 1 | ## $Id: document.py 10842 2013-12-11 13:21:37Z 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 | """ |
---|
| 19 | These are the document tickets. |
---|
| 20 | """ |
---|
| 21 | import grok |
---|
[11990] | 22 | from time import time |
---|
[11982] | 23 | from grok import index |
---|
| 24 | from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState |
---|
| 25 | from zope.event import notify |
---|
| 26 | from zope.component import getUtility |
---|
| 27 | from zope.component.interfaces import IFactory |
---|
| 28 | from zope.interface import implementedBy |
---|
| 29 | from zope.i18n import translate |
---|
[11983] | 30 | from waeup.ikoba.interfaces import IIkobaUtils, IObjectHistory |
---|
[11982] | 31 | from waeup.ikoba.interfaces import MessageFactory as _ |
---|
| 32 | from waeup.ikoba.documents.interfaces import IDocument, IDocument |
---|
| 33 | from waeup.ikoba.utils.helpers import attrs_to_fields, get_current_principal |
---|
| 34 | from waeup.ikoba.utils.logger import Logger |
---|
| 35 | |
---|
| 36 | class Document(grok.Container, Logger): |
---|
| 37 | """This is a document. |
---|
| 38 | """ |
---|
| 39 | grok.implements(IDocument) |
---|
| 40 | grok.provides(IDocument) |
---|
| 41 | grok.baseclass() |
---|
| 42 | |
---|
| 43 | logger_name = 'waeup.ikoba.${sitename}.documents' |
---|
| 44 | logger_filename = 'documents.log' |
---|
| 45 | logger_format_str = '"%(asctime)s","%(user)s",%(message)s' |
---|
| 46 | |
---|
| 47 | def logger_info(self, comment=None): |
---|
| 48 | """Get the logger's info method. |
---|
| 49 | """ |
---|
| 50 | self.logger.info('%s' % comment) |
---|
| 51 | return |
---|
| 52 | |
---|
| 53 | def __init__(self): |
---|
| 54 | super(Document, self).__init__() |
---|
[11990] | 55 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
| 56 | self.id = "d%s" % timestamp |
---|
[11982] | 57 | return |
---|
| 58 | |
---|
[11983] | 59 | @property |
---|
| 60 | def history(self): |
---|
| 61 | history = IObjectHistory(self) |
---|
| 62 | return history |
---|
| 63 | |
---|
[11982] | 64 | Document = attrs_to_fields(Document) |
---|
| 65 | |
---|
| 66 | class DocumentFactory(grok.GlobalUtility): |
---|
| 67 | """A factory for documents. |
---|
| 68 | """ |
---|
| 69 | grok.implements(IFactory) |
---|
| 70 | grok.name(u'waeup.Document') |
---|
| 71 | title = u"Create a new document.", |
---|
| 72 | description = u"This factory instantiates new documents." |
---|
| 73 | |
---|
| 74 | def __call__(self, *args, **kw): |
---|
| 75 | return Document(*args, **kw) |
---|
| 76 | |
---|
| 77 | def getInterfaces(self): |
---|
| 78 | return implementedBy(Document) |
---|
| 79 | |
---|
| 80 | @grok.subscribe(IDocument, grok.IObjectAddedEvent) |
---|
| 81 | def handle_document_added(document, event): |
---|
| 82 | """If a document is added the transition create is fired. |
---|
| 83 | The latter produces a logging message. |
---|
| 84 | """ |
---|
| 85 | if IWorkflowState(document).getState() is None: |
---|
| 86 | IWorkflowInfo(document).fireTransition('create') |
---|
| 87 | return |
---|