예제 #1
0
파일: utility.py 프로젝트: PMR2/pmr2.bives
    def get_tool_link(self, exposure_object):
        # TODO figure out how to do user-side customization on the type
        # of files that can be added.  Although this might better be
        # done on the comparison page as that is the centralized place
        # for all forms of comparison (i.e. CellML or SBML, etc).

        if IExposureFile.providedBy(exposure_object):
            return exposure_object.absolute_url() + '/bives_pick_file'
예제 #2
0
파일: menu.py 프로젝트: PMR2/pmr2.app
 def getMenuItems(self, context, request):
     # Have to set the context to the root.
     if (IExposureFile.providedBy(context) or
             IExposureFolder.providedBy(context)):
         helper = zope.component.queryAdapter(
             context, IExposureSourceAdapter)
         exposure, workspace, path = helper.source()
         context = exposure
     return WorkflowMenu.getMenuItems(self, context, request)
예제 #3
0
파일: catalog.py 프로젝트: PMR2/cellml.pmr2
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 ''
예제 #4
0
    def generateTitle(self):
        # the fallbacks assume context is an atct type.
        if IExposureFile.providedBy(self.context):
            # since this is an exposure file, we will need to derive the
            # model/citation file as this should be the actual file that
            # contain the documentation.
            return self.findModelTitle() or self.context.Title()

        # otherwise, we just use the list of authors if citation is
        # found, for there are expectations for the listing to be the
        # same as how PMR1 did it.
        return self.findCitationAuthors() or self.context.Title()
예제 #5
0
파일: download.py 프로젝트: PMR2/pmr2.app
    def get_download_link(self, exposure_object):
        if not IExposureFile.providedBy(exposure_object):
            return

        try:
            exposure, workspace, path = getAdapter(exposure_object,
                IExposureSourceAdapter).source()
        except:
            return

        return '%s/@@%s/%s/%s' % (
            workspace.absolute_url(), 'rawfile', exposure.commit_id, path
        )
예제 #6
0
 def available(self):
     return IExposureFile.providedBy(self.context) and self.context.views
예제 #7
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()
예제 #8
0
 def available(self):
     return (IExposureFile.providedBy(self.context) 
         and self.note 
         and self.note.flags)
예제 #9
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()