def validate_preingested_data(user_id, uuid, deposition_type=None):
    """Validates all preingested data by trying to match the json with every
    form. Then the validation function is being called for each form.
    """
    form_data = get_preingested_form_data(user_id, uuid)

    deposition = get_workflow(uuid, deposition_type)

    form_types = []
    # Get all form types from workflow
    for fun in deposition.workflow:
        if '__form_type__' in fun.__dict__:
            form_render = render_form(forms[fun.__form_type__])
            if form_render.func_code == fun.func_code:
                form_types.append(fun.__form_type__)

    errors = {}
    for form_type in form_types:
        form = forms[form_type]()
        for field in form:
            if field.name in form_data:
                field.data = form_data.pop(field.name)

        form.validate()

        errors.update(form.errors)

    return errors
Example #2
0
class Photo(object):
    workflow = [
        authorize_user(),
        render_form(PhotoForm),
        wait_for_submission(),
        export_marc_from_json(),
        create_record_from_marc()
    ]
    dep_type = "Photo"
    plural = "Photos"
    group = "Multimedia & Arts"
    enabled = True
Example #3
0
class Thesis(object):
    workflow = [
        authorize_user(),
        render_form(ThesisForm),
        wait_for_submission(),
        export_marc_from_json(),
        create_record_from_marc()
    ]
    dep_type = "Thesis"
    plural = "Theses"
    group = "Articles & Preprints"
    enabled = True
    def test_field_functions(self):
        from datetime import datetime
        from invenio.sqlalchemyutils import db
        from invenio.webdeposit_workflow import DepositionWorkflow
        from invenio.webdeposit_model import WebDepositDraft
        from invenio.webdeposit_workflow_utils import render_form
        from invenio.webdeposit_utils import draft_field_get
        from invenio.webdeposit_deposition_forms.article_form import ArticleForm
        from invenio.cache import cache

        wf = [render_form(ArticleForm)]
        user_id = 1

        workflow = DepositionWorkflow(workflow=wf,
                                      deposition_type='TestWorkflow',
                                      user_id=user_id)

        cache.delete_many("1:current_deposition_type", "1:current_uuid")
        cache.add("1:current_deposition_type", 'TestWorkflow')
        cache.add("1:current_uuid", workflow.get_uuid())

        workflow.run()  # Insert a form
        uuid = workflow.get_uuid()

        # Test for a field that's not there
        value = draft_field_get(user_id, uuid, 'field_that_doesnt_exist')
        assert value is None

        # Test for a field that hasn't been inserted in db yet
        value = draft_field_get(user_id, uuid, 'publisher')
        assert value is None

        values = {'publisher': 'Test Publishers Association'}

        db.session.query(WebDepositDraft).\
            filter(WebDepositDraft.uuid == uuid,
                   WebDepositDraft.step == 0).\
            update({"form_values": values,
                    "timestamp": datetime.now()})
Example #5
0
                                              render_form, \
                                              wait_for_submission, \
                                              export_marc_from_json, \
                                              create_record_from_marc

__all__ = ['Article']

ArticleForm = forms['ArticleForm']
PhotoForm = forms['PhotoForm']

dep_type = "Article"
plural = "Articles"
group = "Articles & Preprints"
wf = [
    authorize_user(),
    render_form(ArticleForm),
    wait_for_submission(),
    export_marc_from_json(),
    create_record_from_marc()
]

# form = get_metadata_creation_form_from_doctype(doc_type)  # # This will use BibField to create a simple form which is the concatenation of all the fields neeeded for doc_type "Article"

Article = {
    "dep_type": dep_type,
    "workflow": wf,
    "plural": plural,
    "group": group,
    "enabled": True
}
"""
from invenio.webdeposit_load_forms import forms
from invenio.webdeposit_workflow_utils import authorize_user, \
                                              render_form, \
                                              wait_for_submission, \
                                              export_marc_from_json, \
                                              create_record_from_marc

__all__ = ['Thesis']

ThesisForm = forms['ThesisForm']

dep_type = "Thesis"
plural = "Theses"
group = "Articles & Preprints"
wf = [
    authorize_user(),
    render_form(ThesisForm),
    wait_for_submission(),
    export_marc_from_json(),
    create_record_from_marc()
]

Thesis = {
    "dep_type": dep_type,
    "workflow": wf,
    "plural": plural,
    "group": group,
    "enabled": True
}
Example #7
0
class TestWorkflow(object):
    workflow = [render_form(ArticleForm), wait_for_submission()]
    dep_type = "TestWorkflow"
    plural = "TestWorkflows"
    group = ""
    enabled = False
    def test_form_functions(self):
        from invenio.webdeposit_load_deposition_types import \
            deposition_metadata
        from invenio.webdeposit_load_forms import forms
        from invenio.webdeposit_model import WebDepositDraft
        from invenio.webdeposit_workflow import DepositionWorkflow
        from invenio.webdeposit_utils import get_current_form, get_form, \
            get_form_status, CFG_DRAFT_STATUS
        from invenio.sqlalchemyutils import db
        from invenio.webdeposit_workflow_utils import render_form, \
            wait_for_submission
        from invenio.cache import cache

        for metadata in deposition_metadata.values():
            for wf_function in metadata['workflow']:
                if 'render_form' == wf_function.func_name:
                    break

        from invenio.webuser_flask import login_user
        login_user(1)

        wf = [render_form(forms.values()[0]), wait_for_submission()]
        deposition_workflow = DepositionWorkflow(
            deposition_type='TestWorkflow', workflow=wf, user_id=1)

        uuid = deposition_workflow.get_uuid()
        cache.delete_many("1:current_deposition_type", "1:current_uuid")
        cache.add("1:current_deposition_type", 'TestWorkflow')
        cache.add("1:current_uuid", uuid)

        # Run the workflow to insert a form to the db
        deposition_workflow.run()

        # There is only one form in the db
        drafts = db.session.query(WebDepositDraft)
        assert len(drafts.all()) == 1

        # Test that guest user doesn't have access to the form
        uuid, form = get_current_form(0,
                                      deposition_type='TestWorkflow',
                                      uuid=uuid)
        assert form is None

        # Test that the current form has the right type
        uuid, form = get_current_form(1,
                                      deposition_type='TestWorkflow',
                                      uuid=deposition_workflow.get_uuid())
        assert isinstance(form, forms.values()[0])
        assert str(uuid) == str(deposition_workflow.get_uuid())

        # Test that form is returned with get_form function
        form = get_form(1, deposition_workflow.get_uuid())
        assert form is not None

        form = get_form(1, deposition_workflow.get_uuid(), step=0)
        assert form is not None

        # Second step doesn't have a form
        form = get_form(1, deposition_workflow.get_uuid(), step=1)
        assert form is None

        form_status = get_form_status(1, deposition_workflow.get_uuid())
        assert form_status == CFG_DRAFT_STATUS['unfinished']

        form_status = get_form_status(1,
                                      deposition_workflow.get_uuid(),
                                      step=2)
        assert form_status is None

        db.session.query(WebDepositDraft).\
            update({'status': CFG_DRAFT_STATUS['finished']})

        form_status = get_form_status(1, deposition_workflow.get_uuid())
        assert form_status == CFG_DRAFT_STATUS['finished']
Example #9
0
from invenio.webdeposit_load_forms import forms
from invenio.webdeposit_workflow_utils import authorize_user, \
                                              render_form, \
                                              wait_for_submission, \
                                              export_marc_from_json, \
                                              create_record_from_marc

__all__ = ['Photo']

PhotoForm = forms['PhotoForm']

dep_type = "Photo"
plural = "Photos"
group = "Multimedia & Arts"
wf = [
    authorize_user(),
    render_form(PhotoForm),
    wait_for_submission(),
    export_marc_from_json(),
    create_record_from_marc()
]

Photo = {
    "dep_type": dep_type,
    "workflow": wf,
    "plural": plural,
    "group": group,
    "enabled": True
}
Example #10
0
from invenio.webdeposit_load_forms import forms
from invenio.webdeposit_workflow_utils import authorize_user, \
                                              render_form, \
                                              wait_for_submission, \
                                              export_marc_from_json, \
                                              create_record_from_marc

__all__ = ['Preprint']

PreprintForm = forms['PreprintForm']

dep_type = "Preprint"
plural = "Preprints"
group = "Articles & Preprints"
wf = [
    authorize_user(),
    render_form(PreprintForm),
    wait_for_submission(),
    export_marc_from_json(),
    create_record_from_marc()
]

Preprint = {
    "dep_type": dep_type,
    "workflow": wf,
    "plural": plural,
    "group": group,
    "enabled": True
}
Example #11
0
from invenio.webdeposit_load_forms import forms
from invenio.webdeposit_workflow_utils import authorize_user, \
                                              render_form, \
                                              wait_for_submission, \
                                              export_marc_from_json, \
                                              create_record_from_marc

__all__ = ['Poetry']

PoemForm = forms['PoemForm']

dep_type = "Poetry"
plural = "Poems"
group = "Multimedia & Arts"
wf = [
    authorize_user(),
    render_form(PoemForm),
    wait_for_submission(),
    export_marc_from_json(),
    create_record_from_marc()
]

Poetry = {
    "dep_type": dep_type,
    "workflow": wf,
    "plural": plural,
    "group": group,
    "enabled": True
}