示例#1
0
def recursive_recatalog_content(obj, event):
    # for exposure state changes.
    # we are going to be restrictive in what we do.
    obj.reindexObject()
    if IExposure.providedBy(obj) or IExposureFolder.providedBy(obj):
        for id_, subobj in obj.items():
            recursive_recatalog_content(subobj, event)
示例#2
0
def pmr1_citation_authors_sortable(context):
    if IExposure.providedBy(context):
        s = pmr1_citation_authors_exposure(context)()
    elif IExposureFile.providedBy(context):
        s = pmr1_citation_authors_exposurefile(context)()
    else:
        # well, this is either not an exposure type, or one that is
        # sitting in some place wrong - we ignore it.
        return ''
    if isinstance(s, basestring):
        return s.lower()
    return ''
示例#3
0
def moldExposure(exposure_context, request, exported):
    """\
    Mold an exposure structure at the exposure context, using the 
    structure provided by the exported dictionary.
    """

    def caststr(s):
        # as the exported structure could be a json structure, according
        # to that spec, all strings will be in unicode, however some of
        # the internal types have been defined to be of type str.  This
        # method provides a way to properly cast them, maybe extended to
        # provide the correct encoding while retaining undefined types
        # (such as null/None).

        if not isinstance(s, basestring):
            return s
        # XXX forced casting for now
        return str(s)

    for items in exported:
        if len(items) != 2:
            raise ProcessingError('Invalid entry')

        path, fields = items
        if path is None:
            # due to wizard.
            continue

        path = caststr(path)
        # We will be calling methods that modify internal states of that
        # form, so we will require fresh instances for every file.
        fgen = zope.component.getMultiAdapter(
            (exposure_context, request), name='filegen')

        if 'views' in fields:
            # since we may use this in a regenerative context, check
            # whether file had been created.
            try:
                ctxobj = fgen.resolve_file(path)
            except ValueError:
                # I guess not.
                d = {
                    'filename': path,
                }
                fgen.createAndAdd(d)
                # XXX using something that is magic in nature
                # <form>.ctxobj is created by our customized object
                # creation method for the form, and we are using 
                # this informally declared object.
                ctxobj = fgen.ctxobj

            views = []
            for view, view_fields in fields['views']:
                # generate views
                annotatorFactory = zope.component.getUtility(
                    IExposureFileAnnotator,
                    name=view,
                )
                # pass in the view_fields regardless whether it is
                # editable or not because editable notes will have
                # data ignored.
                data = view_fields and view_fields.items() or None
                try:
                    # Annotator factory can expect request to be
                    # present.  Refer to commit d5d308226767
                    annotator = annotatorFactory(ctxobj, request)
                    annotator(data)
                    views.append(view)
                except RequiredMissing:
                    # this does not cover cases where schema have
                    # changed, or the old scheme into the new scheme.
                    note = zope.component.queryAdapter(
                        ctxobj,
                        name=view
                    )
                    if note:
                        # This editable note is missing some data,
                        # probably because it never existed, bad
                        # export data, updated schema or other
                        # errors.  We ignore it for now, and purge
                        # the stillborn note from the new object.
                        del_note(ctxobj, view)
                    else:
                        # However, the automatic generated ones we
                        # will continue to raise errors.  Maybe in
                        # the future we group these together, or
                        # make some way to adapt this to something
                        # that will handle the migration case.
                        raise
                except Exception, err:
                    # XXX trap all here.
                    raise ProcessingError(str(err))

            # only ExposureFiles have this
            if IExposureFile.providedBy(ctxobj):
                # The annotator handles the appending of the view to the
                # final list of views that are to be made visible, but
                # it does not care about the order.  This corrects the
                # order based on the order we append it here.
                views = [view for view in views if view in ctxobj.views]
                ctxobj.views = views
                ctxobj.selected_view = fields['selected_view']
                ctxobj.file_type = caststr(fields['file_type'])
                ctxobj.setSubject(fields['Subject'])

            ctxobj.reindexObject()
        else:

            # XXX couldn't this just create the folder first for out
            # of order exports?
            container = fgen.resolve_folder(path)

            if fields['docview_gensource']:
                # there is a source
                # XXX I have unicode/str confusion
                gensource = unicode(fields['docview_gensource'])
                container.docview_gensource = gensource
                viewgen = zope.component.queryUtility(
                    IDocViewGen,
                    name=fields['docview_generator']
                )
                if viewgen:
                    # and the view generator is still available
                    try:
                        viewgen(container)()
                    except Exception, err:
                        # XXX trap all here.
                        raise ProcessingError(str(err))

            if IExposure.providedBy(container):
                # only copy curation over, until this becomes an
                # annotation.
                container.curation = fields['curation']
            container.setSubject(fields['Subject'])
            container.reindexObject()
示例#4
0
文件: util.py 项目: PMR2/pmr2.app
def moldExposure(exposure_context, request, exported):
    """\
    Mold an exposure structure at the exposure context, using the 
    structure provided by the exported dictionary.
    """

    def caststr(s):
        # as the exported structure could be a json structure, according
        # to that spec, all strings will be in unicode, however some of
        # the internal types have been defined to be of type str.  This
        # method provides a way to properly cast them, maybe extended to
        # provide the correct encoding while retaining undefined types
        # (such as null/None).

        if not isinstance(s, basestring):
            return s
        # XXX forced casting for now
        return str(s)

    for items in exported:
        if len(items) != 2:
            raise ProcessingError('Invalid entry')

        path, fields = items
        if path is None:
            # due to wizard.
            continue

        path = caststr(path)
        # We will be calling methods that modify internal states of that
        # form, so we will require fresh instances for every file.
        fgen = zope.component.getMultiAdapter(
            (exposure_context, request), name='filegen')

        if 'views' in fields:
            # since we may use this in a regenerative context, check
            # whether file had been created.
            try:
                ctxobj = fgen.resolve_file(path)
            except ValueError:
                # I guess not.
                d = {
                    'filename': path,
                }
                fgen.createAndAdd(d)
                # XXX using something that is magic in nature
                # <form>.ctxobj is created by our customized object
                # creation method for the form, and we are using 
                # this informally declared object.
                ctxobj = fgen.ctxobj

            views, hidden_views = _mold_views(ctxobj, request, fields)

            # only ExposureFiles have this
            if IExposureFile.providedBy(ctxobj):
                # The annotator handles the appending of the view to the
                # final list of views that are to be made visible, but
                # it does not care about the order.  This corrects the
                # order based on the order we append it here.
                views = [view for view in views if view in ctxobj.views]
                ctxobj.views = views
                ctxobj.selected_view = fields['selected_view']
                ctxobj.file_type = caststr(fields['file_type'])
                ctxobj.hidden_views = hidden_views
                ctxobj.setSubject(fields['Subject'])

            ctxobj.reindexObject()
        else:

            # XXX couldn't this just create the folder first for out
            # of order exports?
            container = fgen.resolve_folder(path)

            if fields['docview_gensource']:
                # there is a source
                # XXX I have unicode/str confusion
                gensource = unicode(fields['docview_gensource'])
                container.docview_gensource = gensource
                viewgen = zope.component.queryUtility(
                    IDocViewGen,
                    name=fields['docview_generator']
                )
                if viewgen:
                    # and the view generator is still available
                    try:
                        viewgen(container)()
                    except Exception, err:
                        # XXX trap all here.
                        qi = getToolByName(ctxobj, 'portal_quickinstaller')
                        if qi.isDevelopmentMode():
                            logger.exception('Error molding exposure')
                        raise ProcessingError(str(err))

            if IExposure.providedBy(container):
                # only copy curation over, until this becomes an
                # annotation.
                container.curation = fields['curation']
            container.setSubject(fields['Subject'])
            container.reindexObject()