Changeset 12408


Ignore:
Timestamp:
6 Jan 2015, 09:15:21 (10 years ago)
Author:
Henrik Bettermann
Message:

Add RESTDocument.

Location:
main/waeup.ikoba/trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/CHANGES.txt

    r11958 r12408  
    55===================
    66
    7 * Add components for customer management.
     7* Add products, documents and customers modules and tons of components.
    88
    99* Rename 'kofa' 'ikoba', 'university' 'company' and 'student' 'customer'.
  • main/waeup.ikoba/trunk/layout/static/css/base.css

    r12313 r12408  
    279279}
    280280
     281
     282 /* docutils stuff */
     283
     284.section h1 {
     285    font-size: 30px}
     286
     287.section h2 {
     288    font-size: 24px}
     289
     290.section h3 {
     291    font-size: 18px}
     292
     293.section h4 {
     294    font-size: 14px}
     295
     296
    281297.sorting { background: url('../img/sort_both.png') no-repeat center right; }
    282298.sorting_asc { background: url('../img/sort_asc.png') no-repeat center right; }
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/fileviewlets.py

    r12347 r12408  
    9090    label = _(u'Sample Scan')
    9191    title = _(u'Sample Scan')
    92     mus = 1024 * 50
     92    mus = 1024 * 200
    9393    download_name = u'sample'
    9494    tab_redirect = '#tab2'
     
    134134    label = _(u'PDF File')
    135135    title = _(u'PDF File')
    136     mus = 1024 * 200
     136    mus = 1024 * 1000
    137137    download_name = u'sample.pdf'
    138138    tab_redirect = '#tab2'
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/browser.py

    r12365 r12408  
    3333from zope.formlib.textwidgets import BytesDisplayWidget
    3434from zope.security import checkPermission
    35 from waeup.ikoba.utils.helpers import html2dict
     35from waeup.ikoba.utils.helpers import html2dict, rest2dict
    3636from waeup.ikoba.interfaces import MessageFactory as _
    3737from waeup.ikoba.interfaces import (
     
    4949
    5050from waeup.ikoba.documents.interfaces import (
    51     IDocumentsContainer, IPublicDocument, IHTMLDocument, IDocumentsUtils)
     51    IDocumentsContainer, IPublicDocument,
     52    IHTMLDocument, IRESTDocument, IDocumentsUtils)
    5253
    5354grok.context(IIkobaObject) # Make IKofaObject the default context
     
    217218
    218219
     220class 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
     231class RESTDocumentDisplayContentPage(HTMLDocumentDisplayContentPage):
     232    """ Page to display the html content of document
     233    """
     234    grok.context(IRESTDocument)
     235
     236    label = None
     237
     238
    219239class DocumentManageFormPage(IkobaEditFormPage,
    220240                            LocalRoleAssignmentUtilityView):
     
    270290        portal_language = getUtility(IIkobaUtils).PORTAL_LANGUAGE
    271291        self.context.html_dict = html2dict(html_multilingual, portal_language)
     292        return
     293
     294
     295class 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)
    272307        return
    273308
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/document.py

    r12256 r12408  
    3838from waeup.ikoba.documents.interfaces import (
    3939    IDocument, IPublicDocument, IDocumentsUtils,
    40     IPDFDocument, IHTMLDocument)
     40    IPDFDocument, IHTMLDocument, IRESTDocument)
    4141
    4242class Document(grok.Container):
     
    150150
    151151
     152class 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
     164RESTDocument = attrs_to_fields(RESTDocument)
     165
     166
    152167class PDFDocumentFactory(grok.GlobalUtility):
    153168    """A factory for documents.
     
    178193    def getInterfaces(self):
    179194        return implementedBy(HTMLDocument)
     195
     196
     197class 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
    180211
    181212#: The file id marker for files
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/interfaces.py

    r12268 r12408  
    9292    """
    9393
    94     html_dict = Attribute('Content as language dictionary with values in html format')
     94    html_dict = Attribute('Content as language dictionary with values in HTML format')
    9595
    9696    html_multilingual = schema.Text(
    9797        title = _(u'Multilingual content in HTML format'),
     98        required = False,
     99        )
     100
     101class 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'),
    98111        required = False,
    99112        )
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/tests/test_browser.py

    r12386 r12408  
    292292            % document.document_id in logcontent)
    293293
     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----------
     316Main Title
     317----------
     318
     319Subtitle
     320========
     321>>de<<
     322----------
     323Haupttitel
     324----------
     325
     326Untertitel
     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  
    3030from waeup.ikoba.imagestorage import DefaultStorage
    3131from waeup.ikoba.documents.interfaces import (
    32     IDocumentsContainer, IPublicDocument, IPDFDocument, IHTMLDocument)
     32    IDocumentsContainer, IPublicDocument, IPDFDocument,
     33    IHTMLDocument, IRESTDocument)
    3334from waeup.ikoba.documents.container import DocumentsContainer
    3435from waeup.ikoba.documents.document import (
    35     PDFDocument, HTMLDocument,
     36    PDFDocument, HTMLDocument, RESTDocument,
    3637    DocumentFileNameChooser, DocumentFileStoreHandler)
    3738from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase)
     
    6667            verifyObject(
    6768                IHTMLDocument, HTMLDocument())
     69            )
     70        self.assertTrue(
     71            verifyClass(
     72                IRESTDocument, RESTDocument)
     73            )
     74        self.assertTrue(
     75            verifyObject(
     76                IRESTDocument, RESTDocument())
    6877            )
    6978        return
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/utils.py

    r12256 r12408  
    3939        'PDFDocument': _('PDF Document'),
    4040        'HTMLDocument': _('HTML Document'),
     41        'RESTDocument': _('REST Document'),
    4142        }
    4243
  • main/waeup.ikoba/trunk/src/waeup/ikoba/utils/helpers.py

    r12361 r12408  
    832832                contents=text)
    833833    return elements
     834
     835def 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.