Changeset 12408 for main/waeup.ikoba/trunk/src/waeup
- Timestamp:
- 6 Jan 2015, 09:15:21 (10 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/fileviewlets.py
r12347 r12408 90 90 label = _(u'Sample Scan') 91 91 title = _(u'Sample Scan') 92 mus = 1024 * 5092 mus = 1024 * 200 93 93 download_name = u'sample' 94 94 tab_redirect = '#tab2' … … 134 134 label = _(u'PDF File') 135 135 title = _(u'PDF File') 136 mus = 1024 * 200136 mus = 1024 * 1000 137 137 download_name = u'sample.pdf' 138 138 tab_redirect = '#tab2' -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/browser.py
r12365 r12408 33 33 from zope.formlib.textwidgets import BytesDisplayWidget 34 34 from zope.security import checkPermission 35 from waeup.ikoba.utils.helpers import html2dict 35 from waeup.ikoba.utils.helpers import html2dict, rest2dict 36 36 from waeup.ikoba.interfaces import MessageFactory as _ 37 37 from waeup.ikoba.interfaces import ( … … 49 49 50 50 from waeup.ikoba.documents.interfaces import ( 51 IDocumentsContainer, IPublicDocument, IHTMLDocument, IDocumentsUtils) 51 IDocumentsContainer, IPublicDocument, 52 IHTMLDocument, IRESTDocument, IDocumentsUtils) 52 53 53 54 grok.context(IIkobaObject) # Make IKofaObject the default context … … 217 218 218 219 220 class RESTDocumentDisplayFormPage(HTMLDocumentDisplayFormPage): 221 """ Page to display html document data 222 """ 223 grok.context(IRESTDocument) 224 225 @property 226 def form_fields(self): 227 return grok.AutoFields(self.context.form_fields_interface).omit( 228 'html_dict', 'rest_multilingual') 229 230 231 class RESTDocumentDisplayContentPage(HTMLDocumentDisplayContentPage): 232 """ Page to display the html content of document 233 """ 234 grok.context(IRESTDocument) 235 236 label = None 237 238 219 239 class DocumentManageFormPage(IkobaEditFormPage, 220 240 LocalRoleAssignmentUtilityView): … … 270 290 portal_language = getUtility(IIkobaUtils).PORTAL_LANGUAGE 271 291 self.context.html_dict = html2dict(html_multilingual, portal_language) 292 return 293 294 295 class RESTDocumentManageFormPage(DocumentManageFormPage): 296 """ View to manage restdocument data 297 """ 298 grok.context(IRESTDocument) 299 grok.template('htmldocumentmanagepage') 300 301 @action(_('Save'), style='primary') 302 def save(self, **data): 303 msave(self, **data) 304 html_multilingual = getattr(self.context, 'rest_multilingual', None) 305 portal_language = getUtility(IIkobaUtils).PORTAL_LANGUAGE 306 self.context.html_dict = rest2dict(html_multilingual, portal_language) 272 307 return 273 308 -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/document.py
r12256 r12408 38 38 from waeup.ikoba.documents.interfaces import ( 39 39 IDocument, IPublicDocument, IDocumentsUtils, 40 IPDFDocument, IHTMLDocument )40 IPDFDocument, IHTMLDocument, IRESTDocument) 41 41 42 42 class Document(grok.Container): … … 150 150 151 151 152 class RESTDocument(PublicDocumentBase): 153 """This is a document to render html-coded text. 154 """ 155 grok.implements(IRESTDocument) 156 grok.provides(IRESTDocument) 157 158 form_fields_interface = IRESTDocument 159 160 def __init__(self, *args, **kw): 161 super(RESTDocument, self).__init__(*args, **kw) 162 self.html_dict = {} 163 164 RESTDocument = attrs_to_fields(RESTDocument) 165 166 152 167 class PDFDocumentFactory(grok.GlobalUtility): 153 168 """A factory for documents. … … 178 193 def getInterfaces(self): 179 194 return implementedBy(HTMLDocument) 195 196 197 class RESTDocumentFactory(grok.GlobalUtility): 198 """A factory for REST documents. 199 """ 200 grok.implements(IFactory) 201 grok.name(u'waeup.RESTDocument') 202 title = u"Create a new REST document.", 203 description = u"This factory instantiates new REST documents." 204 205 def __call__(self, *args, **kw): 206 return RESTDocument(*args, **kw) 207 208 def getInterfaces(self): 209 return implementedBy(RESTDocument) 210 180 211 181 212 #: The file id marker for files -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/interfaces.py
r12268 r12408 92 92 """ 93 93 94 html_dict = Attribute('Content as language dictionary with values in htmlformat')94 html_dict = Attribute('Content as language dictionary with values in HTML format') 95 95 96 96 html_multilingual = schema.Text( 97 97 title = _(u'Multilingual content in HTML format'), 98 required = False, 99 ) 100 101 class IRESTDocument(IPublicDocument): 102 """A base representation of REST documents. 103 104 """ 105 106 html_dict = Attribute( 107 'Content as language dictionary with values in HTML format') 108 109 rest_multilingual = schema.Text( 110 title = _(u'Multilingual content in REST (reStructuredText) format'), 98 111 required = False, 99 112 ) -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/tests/test_browser.py
r12386 r12408 292 292 % document.document_id in logcontent) 293 293 294 def test_manage_rest_document(self): 295 # Managers can access the pages of documentsconter 296 # and can perform actions 297 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 298 self.browser.open('http://localhost/app') 299 self.assertEqual(self.browser.headers['Status'], '200 Ok') 300 self.browser.getLink("Documents").click() 301 self.assertEqual(self.browser.url, self.container_path) 302 self.browser.getLink("Manage").click() 303 self.browser.getControl("Add document").click() 304 self.browser.getControl(name="doctype").value = ['RESTDocument'] 305 self.browser.getControl(name="form.document_id").value = 'DOC3' 306 self.browser.getControl(name="form.title").value = 'My REST Document' 307 self.browser.getControl("Add document").click() 308 self.assertTrue('REST Document added.' in self.browser.contents) 309 document = self.app['documents']['DOC3'] 310 311 # Document can be edited 312 self.browser.getLink("DOC3").click() 313 self.browser.getLink("Manage").click() 314 self.browser.getControl(name="form.rest_multilingual").value = """ 315 ---------- 316 Main Title 317 ---------- 318 319 Subtitle 320 ======== 321 >>de<< 322 ---------- 323 Haupttitel 324 ---------- 325 326 Untertitel 327 ========== 328 """ 329 self.browser.getControl("Save").click() 330 self.assertTrue('Form has been saved.' in self.browser.contents) 331 self.browser.getLink("View").click() 332 self.assertEqual(self.browser.url, self.container_path + '/DOC3/index') 333 self.assertTrue( 334 '<h1 class="title">Main Title</h1>' in self.browser.contents) 335 self.assertTrue( 336 '<h2 class="subtitle" id="subtitle">Subtitle</h2>' 337 in self.browser.contents) 338 self.assertFalse( 339 '<h1 class="title">Haupttitel</h1>' in self.browser.contents) 340 self.browser.getLink("de").click() 341 self.assertFalse( 342 '<h1 class="title">Main Title</h1>' in self.browser.contents) 343 self.assertTrue( 344 '<h1 class="title">Haupttitel</h1>' in self.browser.contents) 345 # The content can be rendered 346 IWorkflowState(document).setState(PUBLISHED) 347 self.browser.open(self.container_path + '/DOC3/display') 348 self.assertTrue( 349 '<h1 class="title">Haupttitel</h1>' in self.browser.contents) 350 # The page label (object title) is not displayed 351 self.assertFalse( 352 '<h1 class="ikoba-content-label">My REST Document</h1>' 353 in self.browser.contents) -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/tests/test_document.py
r12256 r12408 30 30 from waeup.ikoba.imagestorage import DefaultStorage 31 31 from waeup.ikoba.documents.interfaces import ( 32 IDocumentsContainer, IPublicDocument, IPDFDocument, IHTMLDocument) 32 IDocumentsContainer, IPublicDocument, IPDFDocument, 33 IHTMLDocument, IRESTDocument) 33 34 from waeup.ikoba.documents.container import DocumentsContainer 34 35 from waeup.ikoba.documents.document import ( 35 PDFDocument, HTMLDocument, 36 PDFDocument, HTMLDocument, RESTDocument, 36 37 DocumentFileNameChooser, DocumentFileStoreHandler) 37 38 from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase) … … 66 67 verifyObject( 67 68 IHTMLDocument, HTMLDocument()) 69 ) 70 self.assertTrue( 71 verifyClass( 72 IRESTDocument, RESTDocument) 73 ) 74 self.assertTrue( 75 verifyObject( 76 IRESTDocument, RESTDocument()) 68 77 ) 69 78 return -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/utils.py
r12256 r12408 39 39 'PDFDocument': _('PDF Document'), 40 40 'HTMLDocument': _('HTML Document'), 41 'RESTDocument': _('REST Document'), 41 42 } 42 43 -
main/waeup.ikoba/trunk/src/waeup/ikoba/utils/helpers.py
r12361 r12408 832 832 contents=text) 833 833 return elements 834 835 def rest2dict(value=None,portal_language='en'): 836 """Transforms a localized REST text string into a dictionary. 837 838 Different languages must be separated by `>>xy<<` whereas 839 xy is the language code. Text parts without correct leading 840 language separator - usually the first part has no language 841 descriptor - are interpreted as texts in the portal's language. 842 The latter can be configured in waeup.srp.utils.utils.IkobaUtils. 843 """ 844 try: 845 parts = value.split('>>') 846 except: 847 return {} 848 elements = {} 849 lang = portal_language 850 for part in parts: 851 if part[2:4] == u'<<': 852 lang = str(part[0:2].lower()) 853 text = part[4:] 854 elements[lang] = renderElement(u'div id="rest"', 855 contents=ReST2HTML(text)) 856 else: 857 text = part 858 elements[lang] = renderElement(u'div id="rest"', 859 contents=ReST2HTML(text)) 860 return elements
Note: See TracChangeset for help on using the changeset viewer.