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)
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)
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))
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)
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 ), )
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)
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, )
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)
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)])
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)
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)
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)