def test_reset(self):
     # default
     view = self.portal.restrictedTraverse('teamraumtheme-controlpanel')
     view()
     customstyles_util = CustomStylesUtility(self.portal)
     customstyles_util.save_styles({'css.font_size': '14px'})
     self.assertEqual(
         self.style_annotations['customstyles']['css.font_size'], '14px')
     # reset
     self.portal.REQUEST.form.update({'form.reset': '1'})
     view()
     self.assertEqual(
         self.style_annotations['customstyles']['css.font_size'], '12px')
Exemple #2
0
 def test_reset(self):
     # default
     view = self.portal.restrictedTraverse('teamraumtheme-controlpanel')
     view()
     customstyles_util = CustomStylesUtility(self.portal)
     customstyles_util.save_styles({'css.font_size': '14px'})
     self.assertEqual(
         self.style_annotations['customstyles']['css.font_size'], '14px')
     # reset
     self.portal.REQUEST.form.update({'form.reset': '1'})
     view()
     self.assertEqual(
         self.style_annotations['customstyles']['css.font_size'], '12px')
    def get_logo(self, disposition='inline', headers=True):
        portal = getToolByName(self.context, 'portal_url').getPortalObject()
        customstyles_util = CustomStylesUtility(portal)
        customstyles = customstyles_util.annotations.get(
            'customstyles', OOBTree(DEFAULT_STYLES))

        REQUEST = self.request
        RESPONSE = REQUEST.RESPONSE
        blob = LOGO_KEY in customstyles and customstyles[LOGO_RIGHT_KEY] or None
        if not blob:
            return ''
        length = blob.get_size()
        if headers:
            RESPONSE.setHeader('Last-Modified',
                               rfc1123_date(self.context._p_mtime))
            RESPONSE.setHeader('Content-Type', blob.getContentType())
            RESPONSE.setHeader('Accept-Ranges', 'bytes')

            if handleIfModifiedSince(self.context, REQUEST, RESPONSE):
                return ''
            RESPONSE.setHeader('Content-Length', length)
            filename = blob.getFilename()
            if filename is not None:
                filename = IUserPreferredFileNameNormalizer(REQUEST).normalize(
                    unicode(filename, self.context.getCharset()))
                header_value = contentDispositionHeader(
                    disposition=disposition, filename=filename)
                RESPONSE.setHeader("Content-disposition", header_value)

        range = handleRequestRange(self.context, length, REQUEST, RESPONSE)

        return blob.getIterator(**range)
 def logo_url(self):
     customstyles_util = CustomStylesUtility(self.portal)
     if LOGO_KEY in customstyles_util.annotations['customstyles']:
         if customstyles_util.annotations['customstyles'][LOGO_KEY]:
             return "%s/customlogo" % self.portal.absolute_url()
     return "%s/++theme++plonetheme.teamraum/images/logo_teamraum.png" % \
         self.portal.absolute_url()
    def test_safe_logo_without_a_right_logo(self, browser):
        self.login(self.manager, browser)

        browser.open(self.portal, view='@@teamraumtheme-controlpanel')
        browser.fill({'Logo': ('Raw file data', 'logo.png', 'image/png')})
        browser.click_on('save')

        self.assertEqual(['Changes saved'], statusmessages.info_messages())

        custom_styles = CustomStylesUtility(self.portal)
        logo = custom_styles.annotations['customstyles'].get(LOGO_KEY)
        self.assertEqual('Raw file data', logo.data)
Exemple #6
0
    def teamraum_logo_behaviour(self):
        portal = getToolByName(self.context, 'portal_url').getPortalObject()
        customstyles_util = CustomStylesUtility(portal)
        customstyles = customstyles_util.annotations.get(
            'customstyles', OOBTree(DEFAULT_STYLES))
        url = "%s/++theme++plonetheme.teamraum/images/logo_teamraum.png" % \
            portal.absolute_url()

        if LOGO_RIGHT_KEY in customstyles and customstyles[LOGO_RIGHT_KEY]:
            url = "%s/customlogoright" % portal.absolute_url()
        self.logo_tag = "<img src='%s' alt='%s Logo' />" % (
            url,
            portal.Title())
    def test_import_export_json_empty_string_as_logo_right_value(
            self, browser):
        self.login(self.manager, browser)

        data = self.get_dict()
        data.pop(LOGO_RIGHT_KEY)

        browser.open(self.portal, view='@@teamraumtheme-controlpanel')
        browser.fill({'import_styles': self.file_from_dict(data)})
        browser.find('import styles').click()

        statusmessages.assert_no_error_messages()

        custom_styles = CustomStylesUtility(self.portal)
        self.assertIsNone(
            custom_styles.annotations['customstyles'].get(LOGO_RIGHT_KEY))

        browser.find('export styles').click()
        self.assertEquals(data, json.loads(browser.contents))
    def test_import_export_logo(self):
        imgdata = base64.b64encode(
            'GIF89a\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00'
            '\x00!\xf9\x04\x04\x00\x00\x00\x00,\x00\x00\x00\x00\x01\x00'
            '\x01\x00\x00\x02\x02D\x01\x00;')
        styles_json = StringIO('{"css.logo": "%s"}' % imgdata)

        self.portal.REQUEST.form = {
            'form.import': '1',
            'import_styles': styles_json
        }

        panel = self.portal.restrictedTraverse('teamraumtheme-controlpanel')
        panel()

        view = self.portal.restrictedTraverse('customlogo')
        # now there should be an image
        blob = view.get_logo(headers=False)

        self.assertEqual(blob.read(), base64.b64decode(imgdata))
        # now export the styles
        self.portal.REQUEST.form = {'form.export': '1'}

        tmp = StringIO(panel())
        tmp_data = tmp.read()
        self.assertIn('css.logo', tmp_data)

        # reset the image
        customstyles_util = CustomStylesUtility(self.portal)
        del customstyles_util.annotations['customstyles']['css.logo']
        self.assertEqual(view.get_logo(headers=False), '')

        # import the styles
        styles_json.seek(0)
        self.portal.REQUEST.form = {
            'form.import': '1',
            'import_styles': styles_json
        }
        panel = self.portal.restrictedTraverse('teamraumtheme-controlpanel')
        panel()

        blob = view.get_logo(headers=False)
        self.assertEqual(blob.read(), base64.b64decode(imgdata))
    def customfield(self, fieldid, label, cssclass="", help=""):
        """Creates a field and returns its html code.
        """
        customstyles_util = CustomStylesUtility(self.portal)
        default = ''
        field_key = '%s%s' % (CSS_PREFIX, fieldid)
        if field_key in customstyles_util.defaults:
            default = customstyles_util.defaults[field_key]
        afterfield = ''
        if cssclass == 'colorSelection':
            afterfield = """<input type="button"
         class="pickColorButton"
         style="background-color:%s"
         value=""
         />
""" % default
        translated_label = translate(
            label, domain='plonetheme.teamraum', context=self.request)
        translated_help = translate(
            help, domain='plonetheme.teamraum', context=self.request)

        return """
<div class="field">
  <label for="css_%(fieldid)s">%(label)s</label>
  <div class="formHelp">%(help)s</div>
  <input type="text"
         name="%(field_key)s"
         id="css_%(fieldid)s"
         class="%(cssclass)s"
         value="%(default)s"
         />%(afterfield)s
</div>
""" % {'fieldid': fieldid,
       'field_key': field_key,
       'label': translated_label,
       'default': default,
       'help': translated_help,
       'afterfield': afterfield,
       'cssclass': cssclass}
def import_styles_configuration(context):
    """ This importstep checks if there is a specific json
    file and imports it into the theme customstyles.
    """

    styles = context.readDataFile('customstyles.json')

    if styles is None:
        return

    data = json.loads(styles)

    site = context.getSite()

    customstyles_util = CustomStylesUtility(site)

    # reset styles if there is nothing in annotations
    if 'customstyles' not in customstyles_util.annotations:
        customstyles_util.reset_styles()

    customstyles_util.import_styles(data)
 def has_right_logo(self):
     customstyles_util = CustomStylesUtility(self.portal)
     if LOGO_RIGHT_KEY in customstyles_util.annotations['customstyles']:
         if customstyles_util.annotations['customstyles'][LOGO_RIGHT_KEY]:
             return True
     return False
 def defaults(self):
     customstyles_util = CustomStylesUtility(self.portal)
     return customstyles_util.defaults
    def __call__(self):
        customstyles_util = CustomStylesUtility(self.portal)
        # reset styles if there is nothing in annotations
        if 'customstyles' not in customstyles_util.annotations:
            customstyles_util.reset_styles()

        if self.request.form.get('form.submitted', None):
            items = self.request.form
            customstyles_util.save_styles(items)
            IStatusMessage(self.request).addStatusMessage(
                _(u'info_changes_saved',
                  default=u'Changes saved'), type='info')

        if self.request.form.get('form.export', None):
            self.context.REQUEST.RESPONSE.setHeader(
                'Content-Type',
                'text/json; charset=utf-8')
            self.context.REQUEST.RESPONSE.setHeader(
                'Content-disposition',
                'attachment; filename=customstyles.json')
            return customstyles_util.export_styles()

        if self.request.form.get('form.import', None):
            upload = self.request.form.get('import_styles', None)
            if upload:
                customstyles_util.import_styles(json.loads(upload.read()))

        if self.request.form.get('form.reset', None):
            customstyles_util.reset_styles()
            IStatusMessage(self.request).addStatusMessage(
                _(u'info_changes_resetted',
                  default=u'Changes resetted'), type='info')

        if self.request.form.get('reset_logo', None):
            customstyles_util.reset_logo()
            IStatusMessage(self.request).addStatusMessage(
                _(u'info_logo_resetted',
                  default=u'Logo resetted'), type='info')
            self.request.response.redirect('@@%s' % self.__name__)

        if self.request.form.get('reset_logo_right', None):
            customstyles_util.reset_logo_right()
            IStatusMessage(self.request).addStatusMessage(
                _(u'info_logo_resetted',
                  default=u'Logo resetted'), type='info')
            self.request.response.redirect('@@%s' % self.__name__)
        return self.index()
Exemple #14
0
 def style_annotations(self):
     customstyles_util = CustomStylesUtility(self.portal)
     return customstyles_util.annotations