source: main/waeup.ikoba/trunk/src/waeup/ikoba/documents/browser.py @ 12214

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

Adjust UI components in documents and customers package.

  • Property svn:keywords set to Id
File size: 6.5 KB
Line 
1## $Id: browser.py 12214 2014-12-13 15:46:41Z 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"""UI components for documents offered for download by the company.
19"""
20
21import sys
22import grok
23import pytz
24from urllib import urlencode
25from datetime import datetime
26from zope.event import notify
27from zope.i18n import translate
28from zope.catalog.interfaces import ICatalog
29from zope.component import queryUtility, getUtility, createObject
30from zope.schema.interfaces import ConstraintNotSatisfied, RequiredMissing
31from zope.formlib.textwidgets import BytesDisplayWidget
32from zope.security import checkPermission
33from waeup.ikoba.interfaces import MessageFactory as _
34from waeup.ikoba.interfaces import (
35    IContactForm, IObjectHistory, IIkobaObject, IIkobaUtils)
36from waeup.ikoba.browser.layout import (
37    IkobaPage, IkobaEditFormPage, IkobaAddFormPage, IkobaDisplayFormPage,
38    IkobaForm, NullValidator, jsaction, action, UtilityView)
39from waeup.ikoba.widgets.datewidget import (
40    FriendlyDateWidget, FriendlyDateDisplayWidget,
41    FriendlyDatetimeDisplayWidget)
42from waeup.ikoba.browser.breadcrumbs import Breadcrumb
43from waeup.ikoba.browser.pages import (
44    delSubobjects, add_local_role, del_local_roles, msave,
45    LocalRoleAssignmentUtilityView)
46
47from waeup.ikoba.documents.interfaces import (
48    IDocumentsContainer, IPublicDocument, IDocumentsUtils)
49
50grok.context(IIkobaObject) # Make IKofaObject the default context
51grok.templatedir('browser_templates')
52
53
54class DocumentsBreadcrumb(Breadcrumb):
55    """A breadcrumb for the customers container.
56    """
57    grok.context(IDocumentsContainer)
58    title = _('Documents')
59
60
61class DocumentBreadcrumb(Breadcrumb):
62    """A breadcrumb for the customer container.
63    """
64    grok.context(IPublicDocument)
65
66    def title(self):
67        return self.context.title
68
69
70class DocumentsContainerPage(IkobaDisplayFormPage):
71    """The standard view for document containers.
72    """
73    grok.context(IDocumentsContainer)
74    grok.name('index')
75    grok.require('waeup.viewDocuments')
76    grok.template('containerpage')
77    pnav = 2
78    label = _('Documents')
79
80
81class DocumentsContainerManageFormPage(IkobaEditFormPage,
82                                      LocalRoleAssignmentUtilityView):
83    """The manage page for customer containers.
84    """
85    grok.context(IDocumentsContainer)
86    grok.name('manage')
87    grok.require('waeup.manageDocuments')
88    grok.template('containermanagepage')
89    pnav = 2
90    label = _('Manage document section')
91
92    @action(_('Add document'), validator=NullValidator, style='primary')
93    def addSubunit(self, **data):
94        self.redirect(self.url(self.context, 'adddoc'))
95        return
96
97    @jsaction(_('Remove selected documents'))
98    def delDocuments(self, **data):
99        delSubobjects(self, redirect='manage', tab='2')
100        return
101
102    @action(_('Cancel'), validator=NullValidator)
103    def cancel(self, **data):
104        self.redirect(self.url(self.context))
105        return
106
107
108class DocumentAddFormPage(IkobaAddFormPage):
109    """Add-form to add a customer.
110    """
111    grok.context(IDocumentsContainer)
112    grok.require('waeup.manageDocuments')
113    grok.name('adddoc')
114    grok.template('documentaddform')
115    label = _('Add document')
116    pnav = 2
117
118    @property
119    def selectable_doctypes(self):
120        doctypes = getUtility(IDocumentsUtils).SELECTABLE_DOCTYPES_DICT
121        return sorted(doctypes.items())
122
123    @action(_('Create document'), style='primary')
124    def createDocument(self, **data):
125        form = self.request.form
126        doctype = form.get('doctype', None)
127        # Here we can create various instances of PublicDocument derived
128        # classes depending on the doctype parameter given in form.
129        document = createObject('waeup.%s' % doctype)
130        self.applyData(document, **data)
131        self.context.addDocument(document)
132        doctype = getUtility(IDocumentsUtils).SELECTABLE_DOCTYPES_DICT[doctype]
133        self.flash(_('${a} added.', mapping = {'a': doctype}))
134        ob_class = self.__implemented__.__name__.replace('waeup.ikoba.','')
135        self.context.__parent__.logger.info(
136            '%s - added: %s %s' % (ob_class, doctype, document.document_id))
137        self.redirect(self.url(self.context))
138        return
139
140    @action(_('Cancel'), validator=NullValidator)
141    def cancel(self, **data):
142        self.redirect(self.url(self.context))
143
144
145class DocumentDisplayFormPage(IkobaDisplayFormPage):
146    """ Page to display document data
147    """
148    grok.context(IPublicDocument)
149    grok.name('index')
150    grok.require('waeup.viewDocuments')
151    #grok.template('basepage')
152    pnav = 2
153
154    @property
155    def form_fields(self):
156        return grok.AutoFields(self.context.form_fields_interface)
157
158    @property
159    def label(self):
160        return self.context.title
161
162
163class DocumentManageFormPage(IkobaEditFormPage,
164                            LocalRoleAssignmentUtilityView):
165    """ View to manage document data
166    """
167    grok.context(IPublicDocument)
168    grok.name('manage')
169    grok.require('waeup.manageDocuments')
170    grok.template('documentmanagepage')
171    pnav = 2
172
173    taboneactions = [_('Save'),_('Cancel')]
174    tabtwoactions1 = [_('Remove selected local roles')]
175    tabtwoactions2 = [_('Add local role')]
176
177    @property
178    def form_fields(self):
179        return grok.AutoFields(self.context.form_fields_interface)
180
181    def label(self):
182        return _('Manage document ') + self.context.document_id
183
184    @action(_('Save'), style='primary')
185    def save(self, **data):
186        return msave(self, **data)
187
188    @action(_('Cancel'), validator=NullValidator)
189    def cancel(self, **data):
190        self.redirect(self.url(self.context))
191        return
192
193    @action(_('Add local role'), validator=NullValidator)
194    def addLocalRole(self, **data):
195        return add_local_role(self,2,**data)
196
197    @action(_('Remove selected local roles'))
198    def delLocalRoles(self, **data):
199        return del_local_roles(self,2,**data)
Note: See TracBrowser for help on using the repository browser.