Example #1
0
    def get_depositions(cls, user=None, type=None):
        """Get depositions."""
        params = [
            Workflow.module_name == 'webdeposit',
        ]

        if user:
            params.append(BibWorkflowObject.id_user == user.get_id())
        else:
            params.append(BibWorkflowObject.id_user != 0)

        if type:
            params.append(Workflow.name == type.get_identifier())

        objects = BibWorkflowObject.query.join("workflow").options(
            db.contains_eager('workflow')).filter(*params).order_by(
                BibWorkflowObject.modified.desc()).all()

        def _create_obj(o):
            try:
                obj = cls(o)
            except InvalidDepositionType as err:
                current_app.logger.exception(err)
                return None
            if type is None or obj.type == type:
                return obj
            return None

        return filter(lambda x: x is not None, map(_create_obj, objects))
Example #2
0
    def get_depositions(cls, user=None, type=None):
        params = [
            Workflow.module_name == 'webdeposit',
        ]

        if user:
            params.append(BibWorkflowObject.id_user == user.get_id())
        else:
            params.append(BibWorkflowObject.id_user != 0)

        if type:
            params.append(Workflow.name == type.get_identifier())

        objects = BibWorkflowObject.query.join("workflow").options(
            db.contains_eager('workflow')).filter(*params).order_by(
            BibWorkflowObject.modified.desc()).all()

        def _create_obj(o):
            try:
                obj = cls(o)
            except InvalidDepositionType as err:
                current_app.logger.exception(err)
                return None
            if type is None or obj.type == type:
                return obj
            return None

        return filter(lambda x: x is not None, map(_create_obj, objects))
Example #3
0
    def get_depositions(cls, user=None, type=None):
        """Get list of depositions (as iterator)."""
        params = [
            Workflow.module_name == 'webdeposit',
        ]

        if user:
            params.append(BibWorkflowObject.id_user == user.get_id())
        else:
            params.append(BibWorkflowObject.id_user != 0)

        if type:
            params.append(Workflow.name == type.get_identifier())

        objects = BibWorkflowObject.query.join("workflow").options(
            db.contains_eager('workflow')).filter(*params).order_by(
                BibWorkflowObject.modified.desc())

        def _create_obj(o):
            try:
                obj = cls(o)
            except InvalidDepositionType as err:
                current_app.logger.exception(err)
                return None
            if type is None or obj.type == type:
                return obj
            return None

        def mapper_filter(objs):
            for o in objs:
                o = _create_obj(o)
                if o is not None:
                    yield o

        return mapper_filter(objects)
Example #4
0
    def get_query(self):
        params = [
            Workflow.module_name == 'webdeposit',
            BibWorkflowObject.id_user != 0
        ]

        return BibWorkflowObject.query.join("workflow").options(
            db.contains_eager('workflow')).filter(*params)
Example #5
0
def _get_depositions(user=None, type=None):
    """Get list of depositions (as iterator).

    This is redefined Deposition.get_depositions classmethod without order-by
    for better performance.
    """
    from invenio.modules.workflows.models import BibWorkflowObject, Workflow
    from invenio.modules.deposit.models import InvalidDepositionType
    from flask import current_app
    from invenio.ext.sqlalchemy import db
    from invenio.modules.deposit.models import Deposition
    params = [
        Workflow.module_name == 'webdeposit',
    ]

    if user:
        params.append(BibWorkflowObject.id_user == user.get_id())
    else:
        params.append(BibWorkflowObject.id_user != 0)

    if type:
        params.append(Workflow.name == type.get_identifier())

    objects = BibWorkflowObject.query.join("workflow").options(
        db.contains_eager('workflow')).filter(*params)

    def _create_obj(o):
        try:
            obj = Deposition(o)
        except InvalidDepositionType as err:
            current_app.logger.exception(err)
            return None
        if type is None or obj.type == type:
            return obj
        return None

    def mapper_filter(objs):
        for o in objs:
            o = _create_obj(o)
            if o is not None:
                yield o

    return mapper_filter(objects)
def _get_depositions(user=None, type=None):
    """Get list of depositions (as iterator).

    This is redefined Deposition.get_depositions classmethod without order-by
    for better performance.
    """
    from invenio.modules.workflows.models import BibWorkflowObject, Workflow
    from invenio.modules.deposit.models import InvalidDepositionType
    from flask import current_app
    from invenio.ext.sqlalchemy import db
    from invenio.modules.deposit.models import Deposition
    params = [
        Workflow.module_name == 'webdeposit',
    ]

    if user:
        params.append(BibWorkflowObject.id_user == user.get_id())
    else:
        params.append(BibWorkflowObject.id_user != 0)

    if type:
        params.append(Workflow.name == type.get_identifier())

    objects = BibWorkflowObject.query.join("workflow").options(
        db.contains_eager('workflow')).filter(*params)

    def _create_obj(o):
        try:
            obj = Deposition(o)
        except InvalidDepositionType as err:
            current_app.logger.exception(err)
            return None
        if type is None or obj.type == type:
            return obj
        return None

    def mapper_filter(objs):
        for o in objs:
            o = _create_obj(o)
            if o is not None:
                yield o

    return mapper_filter(objects)