Esempio n. 1
0
def setDefaultLayoutForNewPage(obj, event):
    """When a new page is created, set its layout based on the default in
    the FTI
    """
    
    layoutAware = ILayoutAware(obj, None)
    if layoutAware is None:
        return
    
    # Initialise object
    layoutAware.content = ILayoutAware['content'].missing_value
    layoutAware.pageSiteLayout = ILayoutAware['pageSiteLayout'].missing_value
    layoutAware.sectionSiteLayout = ILayoutAware['sectionSiteLayout'].missing_value
    
    portal_type = obj.portal_type
    template = getDefaultPageLayout(portal_type)
    
    if template is None:
        raise ValueError("Cannot find layout template for %s" % portal_type)
    
    templatePath = urlparse.urljoin(obj.absolute_url_path(), template)
    
    try:
        layoutAware.content = resolveResource(templatePath)
    except:
        LOGGER.exception("Could not resolve default page layout %s" % portal_type)
Esempio n. 2
0
 def save(self):
     adapted = ILayoutAware(self.context)
     data = self.request.form.get('data')
     if not data:
         return
     data = json.loads(data)
     adapted.pageSiteLayout = data['page_layout']
     adapted.sectionSiteLayout = data['section_layout']
     return {'success': True}
    def test_page_site_layout_is_not_acquired(self):
        self.registry[DEFAULT_SITE_LAYOUT_REGISTRY_KEY] = \
            b'/++sitelayout++testlayout1/site.html'

        a1 = ILayoutAware(self.portal['f1'])
        a2 = ILayoutAware(self.portal['f1']['d1'])

        self.assertEqual(a1.site_layout(), a2.site_layout())

        a1.pageSiteLayout = '/++sitelayout++testlayout2/mylayout.html'

        self.assertNotEqual(a1.site_layout(), a2.site_layout())
Esempio n. 4
0
 def save(self):
     adapted = ILayoutAware(self.context)
     data = self.request.form.get('data')
     if not data:
         return
     data = json.loads(data)
     adapted.pageSiteLayout = data['page_layout']
     adapted.sectionSiteLayout = data['section_layout']
     parent = aq_parent(self.context)
     if ISiteRoot.providedBy(parent):
         # check if default page...
         if getDefaultPage(parent) == self.context.id:
             # also set site wide global layout setting...
             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'] = data['section_layout']
     return {'success': True}
Esempio n. 5
0
def on_content_created(obj, event):
    if obj.portal_type == 'Dashboard':
        return
    metadata = IPublication(obj, None)
    if metadata is not None:
        if metadata.effective is None:
            metadata.effective = localized_now(obj)
    _touch_contributors(obj)

    if obj.portal_type == 'Collection':
        # enable syndication on type by default
        settings = FeedSettings(obj)
        settings.enabled = True

    adapted = ILayoutAware(obj, None)
    if adapted:
        if not adapted.content and not adapted.contentLayout:
            registry = getUtility(IRegistry)
            try:
                default_layout = registry['%s.%s' %
                                          (DEFAULT_CONTENT_LAYOUT_REGISTRY_KEY,
                                           obj.portal_type.replace(' ', '-'))]
                adapted.contentLayout = default_layout
            except (KeyError, AttributeError):
                pass
            try:
                default_layout = registry['%s.%s' %
                                          (DEFAULT_SITE_LAYOUT_REGISTRY_KEY,
                                           obj.portal_type.replace(' ', '-'))]
                adapted.pageSiteLayout = default_layout
            except (KeyError, AttributeError):
                pass

    try:
        tasks.scan_links.delay('/'.join(obj.getPhysicalPath()))
    except CannotGetPortalError:
        pass

    obj.reindexObject()
Esempio n. 6
0
def tiles(site, req, tiles_data=_tiles_data):

    alsoProvides(req, ICastleLayer)

    # Sitewide slot tiles
    for meta_id, tiles in tiles_data.items():
        meta_tile = MetaTile(site, req)
        alsoProvides(meta_tile, IGlobalTile)
        meta_tile.id = 'meta-' + meta_id
        meta_tile.__name__ = 'castle.cms.meta'
        meta_data_manager = ITileDataManager(meta_tile)
        meta_data = meta_data_manager.get()
        meta_tiles = []

        for tile_data in tiles:
            meta_tiles.append(tile_data['meta'])
            tile = getMultiAdapter((site, req), name=tile_data['meta']['type'])
            alsoProvides(tile, IPersistentTile)
            tile.id = tile_data['meta']['id']
            tile.__name__ = tile_data['meta']['type']
            data_manager = ITileDataManager(tile)
            data_manager.set(tile_data['data'])

        meta_data['tiles'] = meta_tiles
        meta_data_manager.set(meta_data)

    frontpage = site['front-page']
    adapted = ILayoutAware(frontpage, None)
    if adapted:
        adapted.pageSiteLayout = 'frontpage.html'

    # Tiles only for the front-page
    frontpage_tiles = getTileData()

    for tile in frontpage_tiles:
        fp_tile = getMultiAdapter((frontpage, req), name=tile['meta']['type'])

        meta = tile['meta']
        fp_tile.id = meta['id']
        alsoProvides(fp_tile, IPersistentTile)
        data_manager = ITileDataManager(fp_tile)
        data_manager.set(tile['data'])

        if 'slot' in tile:
            meta_tile = MetaTile(frontpage, req)
            alsoProvides(meta_tile, IGlobalTile)
            meta_tile.id = 'meta-' + tile['slot']
            meta_tile.__name__ = 'castle.cms.meta'
            meta_data_manager = ITileDataManager(meta_tile)
            meta_data = meta_data_manager.get()

            existing_tiles = meta_data.get('tiles') or []
            new_tile_id = tile['meta']['id']

            if new_tile_id in [x['id'] for x in existing_tiles]:
                # check if the tile we're trying to install is already there.
                continue

            existing_tiles.append(meta)
            meta_data['tiles'] = existing_tiles
            meta_data['mode'] = 'show'

            meta_data_manager.set(meta_data)

    frontpageLayout = ILayoutAware(frontpage, None)
    if frontpageLayout:
        frontpageLayout.contentLayout = '/++contentlayout++castle/frontpage-layout.html'  # noqa