Changeset 12214 for main/waeup.ikoba/trunk/src/waeup/ikoba/documents
- Timestamp:
- 13 Dec 2014, 15:46:41 (10 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba/documents
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/browser.py
r12213 r12214 46 46 47 47 from waeup.ikoba.documents.interfaces import ( 48 IDocumentsContainer, I Document)48 IDocumentsContainer, IPublicDocument, IDocumentsUtils) 49 49 50 50 grok.context(IIkobaObject) # Make IKofaObject the default context … … 62 62 """A breadcrumb for the customer container. 63 63 """ 64 grok.context(I Document)64 grok.context(IPublicDocument) 65 65 66 66 def title(self): … … 90 90 label = _('Manage document section') 91 91 92 taboneactions = [_('Save'),_('Cancel')] 93 tabtwoactions = [_('Add document'), _('Remove selected'),_('Cancel')] 92 @action(_('Add document'), validator=NullValidator, style='primary') 93 def addSubunit(self, **data): 94 self.redirect(self.url(self.context, 'adddoc')) 95 return 94 96 95 @jsaction(_('Remove selected '))97 @jsaction(_('Remove selected documents')) 96 98 def delDocuments(self, **data): 97 99 delSubobjects(self, redirect='manage', tab='2') 98 100 return 99 101 100 @action(_('Save'), style='primary')101 def save(self, **data):102 return msave(self, **data)103 104 102 @action(_('Cancel'), validator=NullValidator) 105 103 def cancel(self, **data): 106 104 self.redirect(self.url(self.context)) 107 return108 109 @action(_('Add document'), validator=NullValidator)110 def addSubunit(self, **data):111 self.redirect(self.url(self.context, 'adddocument'))112 105 return 113 106 … … 118 111 grok.context(IDocumentsContainer) 119 112 grok.require('waeup.manageDocuments') 120 grok.name('adddoc ument')121 form_fields = grok.AutoFields(IDocument).omit('document_id')113 grok.name('adddoc') 114 grok.template('documentaddform') 122 115 label = _('Add document') 123 116 pnav = 2 124 117 118 @property 119 def selectable_doctypes(self): 120 doctypes = getUtility(IDocumentsUtils).SELECTABLE_DOCTYPES_DICT 121 return sorted(doctypes.items()) 122 125 123 @action(_('Create document'), style='primary') 126 def addDocument(self, **data): 127 document = createObject(u'waeup.PublicDocument') 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) 128 130 self.applyData(document, **data) 129 try: 130 self.context.addDocument(document) 131 except KeyError: 132 self.flash(_('The Id chosen already exists.'), 133 type='danger') 134 return 135 self.flash( 136 _("Document ${a} added.", mapping = {'a':document.document_id})) 131 self.context.addDocument(document) 132 doctype = getUtility(IDocumentsUtils).SELECTABLE_DOCTYPES_DICT[doctype] 133 self.flash(_('${a} added.', mapping = {'a': doctype})) 137 134 ob_class = self.__implemented__.__name__.replace('waeup.ikoba.','') 138 135 self.context.__parent__.logger.info( 139 '%s - added: %s ' % (ob_class, document.document_id))140 self.redirect(self.url(self.context , u'manage')+'#tab2')136 '%s - added: %s %s' % (ob_class, doctype, document.document_id)) 137 self.redirect(self.url(self.context)) 141 138 return 139 140 @action(_('Cancel'), validator=NullValidator) 141 def cancel(self, **data): 142 self.redirect(self.url(self.context)) 142 143 143 144 … … 145 146 """ Page to display document data 146 147 """ 147 grok.context(I Document)148 grok.context(IPublicDocument) 148 149 grok.name('index') 149 150 grok.require('waeup.viewDocuments') 150 151 #grok.template('basepage') 151 form_fields = grok.AutoFields(IDocument)152 152 pnav = 2 153 154 @property 155 def form_fields(self): 156 return grok.AutoFields(self.context.form_fields_interface) 153 157 154 158 @property … … 161 165 """ View to manage document data 162 166 """ 163 grok.context(I Document)167 grok.context(IPublicDocument) 164 168 grok.name('manage') 165 169 grok.require('waeup.manageDocuments') 166 form_fields = grok.AutoFields(IDocument).omit('document_id')167 170 grok.template('documentmanagepage') 168 171 pnav = 2 … … 171 174 tabtwoactions1 = [_('Remove selected local roles')] 172 175 tabtwoactions2 = [_('Add local role')] 176 177 @property 178 def form_fields(self): 179 return grok.AutoFields(self.context.form_fields_interface) 173 180 174 181 def label(self): -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/browser_templates/containermanagepage.pt
r12206 r12214 1 1 <form action="." tal:attributes="action request/URL" 2 2 i18n:domain="waeup.ikoba" method="POST" enctype="multipart/form-data"> 3 <ul class="tabs nav nav-tabs" data-tabs="tabs"> 4 <li class="active"> 5 <a href="#tab1" data-toggle="tab"> 6 <span i18n:translate="">Settings 7 </span></a> 8 </li> 9 <li> 10 <a href="#tab2" data-toggle="tab"> 11 <span i18n:translate="">Documents 12 </span> </a> 13 </li> 14 </ul> 15 <div class="tab-content"> 16 <div id="tab1" class="active tab-pane"> 17 <table class="form-table"> 18 <tbody> 19 <tal:widgets content="structure provider:widgets" /> 20 </tbody> 21 </table> 22 <div tal:condition="view/availableActions"> 23 <span tal:repeat="action view/actions" tal:omit-tag=""> 24 <input tal:condition="python:action.label in view.taboneactions" 25 tal:replace="structure action/render"/> 26 </span> 27 </div> 28 </div> 29 <div id="tab2" class="tab-pane"> 30 <h3 i18n:translate="">Documents</h3> 31 <table class="ikoba-data-table dataTableManage"> 32 <thead> 33 <tr> 34 <th> 35 </th> 36 <th i18n:translate="">Document Id 37 </th> 38 <th i18n:translate="">Title 39 </th> 40 </tr> 41 </thead> 42 <tbody> 43 <tr tal:repeat="doc context/values"> <td> 44 <input type="checkbox" name="val_id" 45 tal:attributes="value doc/document_id" /> </td> <td> 46 <a tal:attributes="href python: view.url(doc)" 47 tal:content="doc/__name__"> ID</a> </td> <td> 48 <span tal:content="doc/title">TITLE 49 </span> </td> 50 </tr> 51 </tbody> 52 </table> 53 <div tal:condition="view/availableActions"> 54 <span tal:repeat="action view/actions" tal:omit-tag=""> 55 <input tal:condition="python:action.label in view.tabtwoactions" 56 tal:replace="structure action/render"/> 57 </span> 58 </div> 59 </div> 3 <h3 i18n:translate="">Documents</h3> 4 <table class="ikoba-data-table dataTableManage"> 5 <thead> 6 <tr> 7 <th> 8 </th> 9 <th i18n:translate="">Id</th> 10 <th i18n:translate="">Title</th> 11 <th i18n:translate="">Type</th> 12 <th i18n:translate="">State</th> 13 </tr> 14 </thead> 15 <tbody> 16 <tr tal:repeat="doc context/values"> <td> 17 <input type="checkbox" name="val_id" 18 tal:attributes="value doc/document_id" /> </td> <td> 19 <a tal:attributes="href python: view.url(doc)" 20 tal:content="doc/__name__"> ID</a> </td> 21 <td tal:content="doc/title">TITLE</td> 22 <td tal:content="doc/translated_class_name">CLASSNAME</td> 23 <td tal:content="doc/translated_state">STATE</td> 24 </tr> 25 </tbody> 26 </table> 27 <div tal:condition="view/availableActions"> 28 <span tal:repeat="action view/actions" tal:omit-tag=""> 29 <input tal:replace="structure action/render"/> 30 </span> 60 31 </div> 61 32 </form> -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/browser_templates/containerpage.pt
r12206 r12214 6 6 <thead> 7 7 <tr> 8 <th i18n:translate=""> DocumentId</th>8 <th i18n:translate="">Id</th> 9 9 <th i18n:translate="">Title</th> 10 <th i18n:translate="">Type</th> 11 <th i18n:translate="">State</th> 10 12 </tr> 11 13 </thead> … … 13 15 <tr tal:repeat="value context/values"> 14 16 <td> <a tal:attributes="href python: view.url(value)"> 15 <span tal:content="value/document_id">ID</span></a></td> 17 <span tal:content="value/document_id">ID</span></a> 18 </td> 16 19 <td tal:content="value/title">TITLE</td> 20 <td tal:content="value/translated_class_name">CLASSNAME</td> 21 <td tal:content="value/translated_state">STATE</td> 17 22 </tr> 18 23 </tbody> -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/document.py
r12213 r12214 49 49 grok.baseclass() 50 50 51 form_fields_interface = None 52 51 53 local_roles = [ 52 54 'waeup.local.DocumentManager', … … 56 58 state = None 57 59 translated_state = None 60 translated_class_name = None 58 61 59 62 def __init__(self): … … 117 120 return 118 121 122 @property 123 def translated_class_name(self): 124 try: 125 DOCTYPES_DICT = getUtility(IDocumentsUtils).DOCTYPES_DICT 126 return DOCTYPES_DICT[self.class_name] 127 except KeyError: 128 return 129 119 130 120 131 class PDFDocument(PublicDocumentBase): … … 124 135 grok.provides(IPDFDocument) 125 136 137 form_fields_interface = IPDFDocument 138 126 139 PDFDocument = attrs_to_fields(PDFDocument) 127 140 … … 133 146 grok.provides(IHTMLDocument) 134 147 148 form_fields_interface = IHTMLDocument 149 135 150 HTMLDocument = attrs_to_fields(HTMLDocument) 136 137 138 class DocumentFactory(grok.GlobalUtility):139 """A factory for documents.140 """141 grok.implements(IFactory)142 grok.name(u'waeup.PublicDocument')143 title = u"Create a new public document.",144 description = u"This factory instantiates new public documents."145 146 def __call__(self, *args, **kw):147 return PublicDocument(*args, **kw)148 149 def getInterfaces(self):150 return implementedBy(PublicDocument)151 151 152 152 -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/interfaces.py
r12213 r12214 44 44 'Returns a translated, more verbose verification state of a document') 45 45 class_name = Attribute('Name of the document class') 46 translated_class_name = Attribute('Translatable class name') 46 47 formatted_transition_date = Attribute('Last transition formatted date string') 47 48 user_id = Attribute('Id of a user') -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/utils.py
r12089 r12214 22 22 from waeup.ikoba.interfaces import ( 23 23 CREATED, SUBMITTED, 24 VERIFIED, REJECTED, EXPIRED )24 VERIFIED, REJECTED, EXPIRED, PUBLISHED) 25 25 from waeup.ikoba.documents.interfaces import IDocumentsUtils 26 26 … … 31 31 32 32 33 class Documents sUtils(grok.GlobalUtility):33 class DocumentsUtils(grok.GlobalUtility): 34 34 """A collection of methods subject to customization. 35 35 """ … … 38 38 TRANSLATED_DOCUMENT_STATES = { 39 39 CREATED: _('created'), 40 SUBMITTED: _('submitted for verification'), 41 VERIFIED: _('verified'), 42 REJECTED: _('rejected'), 43 EXPIRED:_('expired') 40 PUBLISHED:_('published') 44 41 } 42 43 DOCTYPES_DICT = { 44 'PDFDocument': _('PDF Document'), 45 'HTMLDocument': _('HTML Document'), 46 } 47 48 SELECTABLE_DOCTYPES_DICT = DOCTYPES_DICT
Note: See TracChangeset for help on using the changeset viewer.