예제 #1
0
def getform(request, sub_id, domain):
    """
    Returns a metadata form tailored to the given domain.
    """

    domain = domain.lower()
    if domain in metadata_classes():
        meta = metadata_classes()[domain]()
    else:
        from b2share_model.model import SubmissionMetadata
        meta = SubmissionMetadata()

    if not is_current_user_allowed_to_deposit(meta):
        return render_template('b2share-addmeta-table-denied.html')

    MetaForm = model_form(meta.__class__, base_class=FormWithKey,
                          exclude=['submission', 'submission_type'],
                          field_args=meta.field_args,
                          converter=HTML5ModelConverter())
    meta_form = MetaForm(request.form, meta)

    return render_template(
        'b2share-addmeta-table.html',
        sub_id=sub_id,
        metadata=meta,
        form=meta_form,
        getattr=getattr)
예제 #2
0
def getform(request, sub_id, domain):
    """
    Returns a metadata form tailored to the given domain.
    """

    domain = domain.lower()
    if domain in metadata_classes():
        meta = metadata_classes()[domain]()
    else:
        from b2share_model.model import SubmissionMetadata
        meta = SubmissionMetadata()

    if not is_current_user_allowed_to_deposit(meta):
        return render_template('b2share-addmeta-table-denied.html')

    MetaForm = model_form(meta.__class__,
                          base_class=FormWithKey,
                          exclude=['submission', 'submission_type'],
                          field_args=meta.field_args,
                          converter=HTML5ModelConverter())
    meta_form = MetaForm(request.form, meta)

    return render_template('b2share-addmeta-table.html',
                           sub_id=sub_id,
                           metadata=meta,
                           form=meta_form,
                           getattr=getattr)
예제 #3
0
def addmeta(request, sub_id):
    """
    Checks the submitted metadata form for validity.
    Returns a new page with success message if valid, otherwise it returns a
    form with the errors marked.
    """
    if sub_id is None:
        #just return to deposit
        return redirect(url_for('.deposit'))

    CFG_B2SHARE_UPLOAD_FOLDER = current_app.config.get(
        "CFG_B2SHARE_UPLOAD_FOLDER")
    updir = os.path.join(CFG_B2SHARE_UPLOAD_FOLDER, sub_id)
    if (not os.path.isdir(updir)) or (not os.listdir(updir)):
        return render_template('500.html', message="Uploads not found"), 500

    domain = request.form['domain'].lower()
    if domain in metadata_classes():
        meta = metadata_classes()[domain]()
    else:
        from b2share_model.model import SubmissionMetadata
        meta = SubmissionMetadata()

    if not is_current_user_allowed_to_deposit(meta):
        return jsonify(
            valid=False,
            html=render_template('b2share-addmeta-table-denied.html'))

    MetaForm = model_form(meta.__class__,
                          base_class=FormWithKey,
                          exclude=['submission', 'submission_type'],
                          field_args=meta.field_args,
                          converter=HTML5ModelConverter())

    meta_form = MetaForm(request.form, meta)

    if meta_form.validate_on_submit():
        recid, marc = b2share_marc_handler.create_marc(request.form, sub_id,
                                                       current_user['email'],
                                                       meta)
        tmp_file = write_marc_to_temp_file(marc)
        # all usual tasks have priority 0; we want the bibuploads to run first
        from invenio.legacy.bibsched.bibtask import task_low_level_submission
        task_low_level_submission('bibupload', 'webdeposit', '--priority', '1',
                                  '-r', tmp_file)
        return jsonify(valid=True,
                       newurl=url_for("record.metadata", recid=recid),
                       html=render_template('record_waitforit.html',
                                            recid=recid,
                                            marc=marc))

    return jsonify(valid=False,
                   html=render_template('b2share-addmeta-table.html',
                                        sub_id=sub_id,
                                        metadata=meta,
                                        form=meta_form,
                                        getattr=getattr))
예제 #4
0
파일: edit.py 프로젝트: thomasmtl/b2share
def _get_meta_form_data(domain, form):
    if domain not in metadata_classes():
        raise Exception("%s is not a domain" %(domain,))

    metaclass = metadata_classes()[domain]
    meta = metaclass()
    MetaForm = model_form(meta.__class__, base_class=FormWithKey,
                          exclude=['submission', 'submission_type'],
                          field_args=meta.field_args,
                          converter=HTML5ModelConverter())
    meta_form = MetaForm(form, meta, csrf_enabled=False)
    return (metaclass, meta, meta_form)
예제 #5
0
def addmeta(request, sub_id):
    """
    Checks the submitted metadata form for validity.
    Returns a new page with success message if valid, otherwise it returns a
    form with the errors marked.
    """
    if sub_id is None:
        # just return to deposit
        return redirect(url_for(".deposit"))

    CFG_B2SHARE_UPLOAD_FOLDER = current_app.config.get("CFG_B2SHARE_UPLOAD_FOLDER")
    updir = os.path.join(CFG_B2SHARE_UPLOAD_FOLDER, sub_id)
    if (not os.path.isdir(updir)) or (not os.listdir(updir)):
        return render_template("500.html", message="Uploads not found"), 500

    domain = request.form["domain"].lower()
    if domain in metadata_classes():
        meta = metadata_classes()[domain]()
    else:
        from b2share_model.model import SubmissionMetadata

        meta = SubmissionMetadata()

    MetaForm = model_form(
        meta.__class__,
        base_class=FormWithKey,
        exclude=["submission", "submission_type"],
        field_args=meta.field_args,
        converter=HTML5ModelConverter(),
    )

    meta_form = MetaForm(request.form, meta)

    if meta_form.validate_on_submit():
        recid, marc = b2share_marc_handler.create_marc(request.form, sub_id, current_user["email"], meta)
        tmp_file = write_marc_to_temp_file(marc)
        # all usual tasks have priority 0; we want the bibuploads to run first
        from invenio.legacy.bibsched.bibtask import task_low_level_submission

        task_low_level_submission("bibupload", "webdeposit", "--priority", "1", "-r", tmp_file)
        return jsonify(
            valid=True,
            newurl=url_for("record.metadata", recid=recid),
            html=render_template("record_waitforit.html", recid=recid, marc=marc),
        )

    return jsonify(
        valid=False,
        html=render_template(
            "b2share-addmeta-table.html", sub_id=sub_id, metadata=meta, form=meta_form, getattr=getattr
        ),
    )
예제 #6
0
파일: edit.py 프로젝트: cjhak/b2share
def _get_meta_form_data(domain, form):
    if domain not in metadata_classes():
        raise Exception("%s is not a domain" % (domain, ))

    metaclass = metadata_classes()[domain]
    meta = metaclass()
    MetaForm = model_form(meta.__class__,
                          base_class=FormWithKey,
                          exclude=['submission', 'submission_type'],
                          field_args=meta.field_args,
                          converter=HTML5ModelConverter())
    meta_form = MetaForm(form, meta, csrf_enabled=False)
    return (metaclass, meta, meta_form)
예제 #7
0
def deposit(request):
    """ Renders the deposit start page """
    return render_template(
        "b2share-deposit.html",
        url_prefix=url_for(".deposit"),
        domains=metadata_classes().values(),
        sub_id=uuid.uuid1().hex,
    )
예제 #8
0
def _get_record_info(recid):
    from invenio.modules.formatter import engine as bibformat_engine
    bfo = bibformat_engine.BibFormatObject(recid)
    open_access = read_basic_metadata_field_from_marc(bfo, 'open_access')

    is_private = open_access == "restricted" or open_access == False
    domain = read_basic_metadata_field_from_marc(bfo, 'domain')
    owner_email = read_basic_metadata_field_from_marc(bfo, 'uploaded_by')
    metaclass = metadata_classes().get(domain)
    admin_can_edit_published_record = getattr(metaclass, 'admin_can_edit_published_record', False)

    return (domain, owner_email, is_private, admin_can_edit_published_record)
예제 #9
0
def add_domain_fields(rec, form):
    """
    Adds a domain specific fields. These are just added as name value pairs
    to field 690.
    """

    domain = form['domain'].lower()
    if domain in metadata_classes():
        meta = metadata_classes()[domain]()
    else:
        #no domain stuff
        return

    for fs in meta.fieldsets:
        if fs.name != 'Generic':  # TODO: this is brittle; get from somewhere
            for k in (fs.optional_fields + fs.basic_fields):
                if k in form and form[k]:
                    fields = form.getlist(k)
                    for f in fields:
                        if f and not f.isspace():
                            record_add_field(rec, '690',
                                     subfields=[('a', k), ('b', f)])
예제 #10
0
파일: edit.py 프로젝트: cjhak/b2share
def _get_record_info(recid):
    from invenio.modules.formatter import engine as bibformat_engine
    bfo = bibformat_engine.BibFormatObject(recid)
    open_access = read_basic_metadata_field_from_marc(bfo, 'open_access')

    is_private = open_access == "restricted" or open_access == False
    domain = read_basic_metadata_field_from_marc(bfo, 'domain')
    owner_email = read_basic_metadata_field_from_marc(bfo, 'uploaded_by')
    metaclass = metadata_classes().get(domain)
    admin_can_edit_published_record = getattr(
        metaclass, 'admin_can_edit_published_record', False)

    return (domain, owner_email, is_private, admin_can_edit_published_record)
예제 #11
0
def getform(request, sub_id, domain):
    """
    Returns a metadata form tailored to the given domain.
    """

    domain = domain.lower()
    if domain in metadata_classes():
        meta = metadata_classes()[domain]()
    else:
        from b2share_model.model import SubmissionMetadata

        meta = SubmissionMetadata()

    MetaForm = model_form(
        meta.__class__,
        base_class=FormWithKey,
        exclude=["submission", "submission_type"],
        field_args=meta.field_args,
        converter=HTML5ModelConverter(),
    )
    meta_form = MetaForm(request.form, meta)

    return render_template("b2share-addmeta-table.html", sub_id=sub_id, metadata=meta, form=meta_form, getattr=getattr)
예제 #12
0
def deposit(request):
    """ Renders the deposit start page """
    return render_template('b2share-deposit.html',
                           url_prefix=url_for('.deposit'),
                           domains=metadata_classes().values(),
                           sub_id=uuid.uuid1().hex)