Esempio n. 1
0
    def __call__(self):
        data = super(CastleSettingsAdapter, self).__call__()

        if api.user.is_anonymous():
            return data

        folder = self.context
        if not IDexterityContainer.providedBy(folder):
            folder = aq_parent(folder)
        required_upload_fields = self.registry.get(
            'castle.required_file_upload_fields', []) or []
        data.update({
            'data-available-slots':
            json.dumps(self.get_available_slot_tiles()),
            'data-required-file-upload-fields':
            json.dumps(required_upload_fields),
            'data-google-maps-api-key':
            self.registry.get('castle.google_maps_api_key', '') or '',
            'data-folder-url':
            folder.absolute_url()
        })

        show_tour = False
        user = api.user.get_current()
        viewed = user.getProperty('tours_viewed', [])
        if ('all' not in viewed and set(viewed) != set([
                'welcome', 'dashboard', 'foldercontents', 'addcontentinitial',
                'addcontentadd', 'editpage'
        ])):
            show_tour = True

        if show_tour and not api.env.test_mode():
            data['data-show-tour'] = json.dumps({'viewed': viewed})

        folder = self.context
        if not ISiteRoot.providedBy(
                folder) and not IDexterityContainer.providedBy(folder):
            folder = aq_parent(folder)
        site_path = self.site.getPhysicalPath()
        folder_path = folder.getPhysicalPath()
        data['data-base-path'] = '/' + '/'.join(folder_path[len(site_path):])

        real_context = self.context
        if ISiteRoot.providedBy(real_context):
            # we're at site root but actually kind of want context front page
            try:
                real_context = real_context[getDefaultPage(real_context)]
            except (AttributeError, KeyError):
                pass
        if IDashboard.providedBy(real_context):
            real_context = self.site

        transform = theming.getTransform(real_context, self.request)
        if transform is not None:
            data['data-site-layout'] = transform.get_layout_name(real_context)

        data['data-site-default'] = getDefaultPage(self.site) or 'front-page'

        return data
Esempio n. 2
0
 def test_use_default_layout_in_registry(self):
     transform = theming.getTransform(self.portal, self.request)
     layout_name = transform.get_layout_name(self.portal)
     self.assertEqual(layout_name, 'index.html')
     registry = getUtility(IRegistry)
     field = registry_field.TextLine(title=u'Default layout',
                                     required=False)
     new_record = Record(field)
     registry.records['castle.cms.default_layout'] = new_record
     registry['castle.cms.default_layout'] = u'foobar.html'
     layout_name = transform.get_layout_name(self.portal)
     self.assertEqual(layout_name, 'foobar.html')
Esempio n. 3
0
    def test_apply_does_not_transform_inner_content(self):
        transform = theming.getTransform(self.portal, self.request)
        self.request.environ['X-CASTLE-LAYOUT'] = MINIMAL_LAYOUT
        result = ''.join(
            transform(self.request,
                      getHTMLSerializer([
                          '''
<div id="content">
<a href="foo/bar" />
</div>'''
                      ]),
                      context=self.portal))
        self.assertTrue('++theme++castle.theme/foo/bar' not in result)
        self.assertTrue('http://nohost/plone/foo/bar' in result)
Esempio n. 4
0
    def massage_plone_resp_content(self, ob, resp, url):
        content = resp['data']
        if 'html' in resp['headers']['content-type']:
            if resp['headers'].get('x-theme-applied') != 'true':
                # annoying case where theme isn't applied here...

                req = getRequest()

                # XXX a bit weird, we need to virtualhostmonster it for transform...
                site_path = '/'.join(self.site.getPhysicalPath())
                public_url = api.portal.get_registry_record('plone.public_url')
                vhm_base = _get_vhm_base_url(public_url, site_path)
                req.traverse(vhm_base)

                transform = theming.getTransform(ob, req)
                content = ''.join(transform(req, content, context=ob))
            content = self.transform_content(content, url)
        return content
Esempio n. 5
0
    def __call__(self):
        self.request.response.setHeader('X-Theme-Applied', 'true')
        layout = self.request.get('layout')
        transform = theming.getTransform(self.context, self.request)

        layout = transform.get_layout(self.context,
                                      layout,
                                      request=self.request)
        portal = api.portal.get()
        portal_url = portal.absolute_url()
        context_url = self.context.absolute_url()

        theme_base_url = '%s/++%s++%s/index.html' % (
            portal_url, THEME_RESOURCE_NAME, transform.name)

        content = {'main': '<p>Content from page</p>', 'left': '', 'right': ''}

        utils = getMultiAdapter((self.context, self.request),
                                name='castle-utils')

        layout = layout(portal_url=portal_url,
                        site_url=portal_url,
                        context_url=context_url,
                        request=self.request,
                        context=self.context,
                        portal=portal,
                        site=portal,
                        theme_base_url=theme_base_url,
                        content=content,
                        anonymous=api.user.is_anonymous(),
                        debug=api.env.debug_mode(),
                        utils=utils,
                        raw=True)

        dom = getHTMLSerializer([layout])
        transform.rewrite(dom, theme_base_url)

        root = dom.tree.getroot()
        for tile in root.cssselect('[data-tile*="@@castle.cms.meta/"]'):
            slot_id = tile.attrib['data-tile'].split('/@@castle.cms.meta/')[-1]

            title = None
            if '?' in slot_id:
                slot_id, _, qs = slot_id.partition('?')
                query = dict(urllib.parse_qsl(qs))
                title = query.get('title')
            else:
                title = slot_id.replace('meta-',
                                        '').capitalize().replace('-', ' ')
            tile.attrib['data-tile-id'] = slot_id
            tile.attrib['data-tile-title'] = title
            tile.attrib['class'] = 'castle-tile-container'
            tile.text = 'Edit %s slot' % title

        overlay = etree.Element('div')
        overlay.attrib['class'] = 'expose-overlay'
        root.cssselect('body')[0].append(overlay)

        javascript = etree.Element('script')
        javascript.text = self.javascript
        root.cssselect('body')[0].append(javascript)

        style = etree.Element('style')
        style.text = self.styles
        root.cssselect('body')[0].append(style)

        transform.dynamic_grid(dom.tree)
        return tostring(dom.tree)
Esempio n. 6
0
 def test_apply(self):
     transform = theming.getTransform(self.portal, self.request)
     result = transform(self.request, MINIMAL_RESULT, context=self.portal)
     self.assertTrue('<div>foobar</div>' in ''.join(result))
     self.assertTrue('data-pat-structure' in ''.join(result))
Esempio n. 7
0
 def test_get_layout_from_environ(self):
     transform = theming.getTransform(self.portal, self.request)
     self.request.environ['X-CASTLE-LAYOUT'] = MINIMAL_LAYOUT
     layout = transform.get_layout(self.portal, request=self.request)
     self.assertEqual(layout.name, 'environ')
Esempio n. 8
0
 def test_get_layout(self):
     transform = theming.getTransform(self.portal, self.request)
     layout = transform.get_layout(self.portal)
     self.assertEqual(layout.name, 'index.html')