Пример #1
0
    def _makeContext(self, context_id):

        from Products.GenericSetup.context import SnapshotImportContext

        self._makeSite()

        if context_id not in self.tool.snapshots.objectIds():
            self.tool.snapshots._setObject(context_id, Folder(context_id))

        ctx = SnapshotImportContext(self.tool, context_id)

        return ctx.__of__(self.tool)
Пример #2
0
    def _makeContext( self, context_id ):

        from Products.GenericSetup.context import SnapshotImportContext

        self._makeSite()

        if context_id not in self.tool.snapshots.objectIds():
            self.tool.snapshots._setObject( context_id, Folder( context_id ) )

        ctx = SnapshotImportContext( self.tool, context_id )

        return ctx.__of__( self.tool )
Пример #3
0
def add_default_widgets(context):
    """ Add default widgets to context
    """
    criteria = queryAdapter(context, ICriteria)
    if not criteria:
        return

    # Configure widgets only for canonical (LinguaPlone only)
    getCanonical = getattr(context, 'getCanonical', None)
    if getCanonical:
        canonical = getCanonical()
        if context != canonical:
            return

    # Criteria already changed, we don't want to mess them
    if list(criteria.keys()):
        return

    widgets = context.unrestrictedTraverse('@@default_widgets.xml')
    if not widgets:
        return

    xml = widgets()
    environ = SnapshotImportContext(context, 'utf-8')
    importer = queryMultiAdapter((context, environ), IBody)
    if not importer:
        return
    importer.body = xml
Пример #4
0
    def _getImportContext(self, context_id, should_purge=None, archive=None):
        """ Crack ID and generate appropriate import context.
        """
        encoding = self.getEncoding()

        if context_id is not None:
            if context_id.startswith('profile-'):
                context_id = context_id[len('profile-'):]
                info = _profile_registry.getProfileInfo(context_id)

                if info.get('product'):
                    path = os.path.join(_getProductPath(info['product']),
                                        info['path'])
                else:
                    path = info['path']
                if should_purge is None:
                    should_purge = (info.get('type') != EXTENSION)
                return DirectoryImportContext(self, path, should_purge,
                                              encoding)

            elif context_id.startswith('snapshot-'):
                context_id = context_id[len('snapshot-'):]
                if should_purge is None:
                    should_purge = True
                return SnapshotImportContext(self, context_id, should_purge,
                                             encoding)

        if archive is not None:
            return TarballImportContext(tool=self,
                                       archive_bits=archive,
                                       encoding='UTF8',
                                       should_purge=should_purge,
                                      )

        raise KeyError('Unknown context "%s"' % context_id)
Пример #5
0
def _facetize(item, xml_filename):
    """ Make an item as faceted navigation
    """

    notify(FacetedWillBeEnabledEvent(item))
    alsoProvides(item, IFacetedNavigable)
    if not IDisableSmartFacets.providedBy(item):
        alsoProvides(item, IDisableSmartFacets)
    if not IHidePloneLeftColumn.providedBy(item):
        alsoProvides(item, IHidePloneLeftColumn)
    if not IHidePloneRightColumn.providedBy(item):
        alsoProvides(item, IHidePloneRightColumn)
    notify(FacetedEnabledEvent(item))

    import os.path
    fpath = os.path.join(os.path.dirname(__file__), 'faceted', xml_filename)
    with open(fpath) as f:
        xml = f.read()

    if not xml.startswith('<?xml version="1.0"'):
        raise ValueError('Please provide a valid xml file')

    environ = SnapshotImportContext(item, 'utf-8')
    importer = queryMultiAdapter((item, environ), IBody)
    if not importer:
        raise ValueError('No adapter found')

    importer.body = xml
Пример #6
0
def subtype(obj, evt):
    """ Subtype as faceted navigable
    """
    context = obj
    portal_type = getattr(context, 'portal_type', None)
    if portal_type != 'EEARelationsContentType':
        return

    # Subtype as faceted navigable
    subtyper = queryMultiAdapter((context, context.REQUEST),
                                 name=u'faceted_search_subtyper',
                                 default=queryMultiAdapter(
                                     (context, context.REQUEST),
                                     name=u'faceted_subtyper'))

    if subtyper:
        subtyper.enable()

    # Add default widgets
    widgets = queryMultiAdapter((context, context.REQUEST),
                                name=u'default_widgets.xml')
    if not widgets:
        return

    xml = widgets()
    environ = SnapshotImportContext(context, 'utf-8')
    importer = queryMultiAdapter((context, environ), IBody)
    if not importer:
        return
    importer.body = xml
Пример #7
0
    def import_xml(self, **kwargs):
        """ Export
        """
        upload_file = kwargs.get('import_file', None)
        if getattr(upload_file, 'read', None):
            upload_file = upload_file.read()
        xml = upload_file or ''
        if not xml.startswith('<?xml version="1.0"'):
            return _('Please provide a valid xml file')

        environ = SnapshotImportContext(self.context, 'utf-8')
        importer = queryMultiAdapter((self.context, environ), IBody,
                                      name='metadata.progress.xml')
        importer.body = xml
        return None
    def _import_xml(self, **kwargs):
        """ Import
        """
        upload_file = kwargs.get('import_file', None)
        if getattr(upload_file, 'read', None):
            upload_file = upload_file.read()
        xml = upload_file or ''
        if not xml.startswith('<?xml version="1.0"'):
            return _('Please provide a valid xml file')

        environ = SnapshotImportContext(self.context, 'utf-8')
        importer = queryMultiAdapter((self.context, environ), IBody)
        if not importer:
            return 'No adapter found'

        importer.body = xml
        return _(u"Configuration imported")