def index(collection=None): """ Index page with uploader and list of existing depositions """ u = None upload_url = url_for('deposit.upload') dropbox_upload_url = url_for('deposit.dropbox_upload') if 'c' in request.values: u = UserCollection.query.get(request.values.get('c')) if u: upload_url = url_for('deposit.upload', c=u.id) dropbox_upload_url = url_for('deposit.dropbox_upload', c=u.id) return render_template( "openaire_index.html", title=_('Upload'), myresearch=get_exisiting_publications_for_uid(current_user.get_id()), pub=None, usercollection=u, upload_url=upload_url, dropbox_upload_url=dropbox_upload_url, )
def edit(self, req, form): argd = wash_urlargd( form, { "projectid": (int, -1), #'delete': (str, ''), "id": (str, ""), "a": (str, "edit"), #'linkproject': (int, -1), #'unlinkproject': (int, -1), # style': (str, None), #'upload': (str, ''), #'dropbox': (str, '') }, ) _ = gettext_set_language(argd["ln"]) # Check if user is authorized to deposit publications user_info = collect_user_info(req) auth_code, auth_message = acc_authorize_action(user_info, "submit", doctype="OpenAIRE") if auth_code: if user_info["guest"] == "1": return redirect_to_url( req, "%s/youraccount/login%s" % ( CFG_SITE_SECURE_URL, make_canonical_urlargd( {"referer": "%s%s" % (CFG_SITE_URL, req.unparsed_uri), "ln": argd["ln"]}, {} ), ), ) else: return page( req=req, body=_("You are not authorized to use OpenAIRE deposition."), title=_("Authorization failure"), navmenuid="submit", ) # Validate action action = argd["a"] if action not in ["edit", "save", "submit", "delete"]: abort(404) uid = user_info["uid"] if not argd["id"]: return redirect("/deposit/") try: pub = OpenAIREPublication(uid, publicationid=argd["id"]) title = pub.metadata.get("title", "Untitled") except ValueError: abort(404) # # Action handling # if action == "delete": pub.delete() flash("Upload '%s' was deleted." % title, "info") return redirect("/deposit/") elif action == "edit": ctx = {"pub": pub, "title": title, "recid": pub.metadata.get("__recid__", None)} ctx["rendered_form"] = openaire_deposit_templates.tmpl_form( pub.metadata["__publicationid__"], -1, "", # projects_information "", # publication_information "", # fulltext_information form=None, metadata_status="empty", warnings=None, errors=None, ln="en", ) # if action == "edit": # elif action == "delete": # pass # if projectid >= 0: # ## There is a project on which we are working good! # publications = get_all_publications_for_project( # uid, projectid, ln=argd['ln'], style=style) # if argd['publicationid'] in publications: # if argd['addproject'] in all_project_ids: # publications[argd['publicationid'] # ].link_project(argd['linkproject']) # if argd['delproject'] in all_project_ids: # publications[argd['publicationid'] # ].unlink_project(argd['unlinkproject']) # if argd['delete'] and argd['delete'] in publications: # ## there was a request to delete a publication # publications[argd['delete']].delete() # del publications[argd['delete']] # forms = "" # submitted_publications = "" # for index, (publicationid, publication) in enumerate(publications.iteritems()): # if req.method.upper() == 'POST': # publication.merge_form(form, ln=argd['ln']) # if publication.status == 'edited': # publication.check_metadata() # publication.check_projects() # if 'submit_%s' % publicationid in form and not "".join(publication.errors.values()).strip(): # ## i.e. if the button submit for the corresponding publication has been pressed... # publication.upload_record() # if publication.status in ('initialized', 'edited'): # forms += publication.get_publication_form(projectid) # else: # submitted_publications += publication.get_publication_preview() # body += openaire_deposit_templates.tmpl_add_publication_data_and_submit(projectid, forms, submitted_publications, project_information=upload_to_project_information, ln=argd['ln']) # body += openaire_deposit_templates.tmpl_upload_publications(projectid=upload_to_projectid, project_information=upload_to_project_information, session=get_session(req).sid.encode('utf8'), style=style, ln=argd['ln']) # else: ctx.update({"myresearch": get_exisiting_publications_for_uid(uid)}) return render_template( "openaire_edit.html", req=req, breadcrumbs=[(_("Home"), ""), (_("Upload"), "deposit"), (title, "")], **ctx ).encode("utf8")
forms, submitted_publications, project_information=upload_to_project_information, ln=argd["ln"], ) body += openaire_deposit_templates.tmpl_upload_publications( projectid=upload_to_projectid, project_information=upload_to_project_information, session=get_session(req).sid.encode("utf8"), style=style, ln=argd["ln"], ) else: ctx.update( { "myresearch": get_exisiting_publications_for_uid(uid), "upload_to_projectid": upload_to_projectid, "upload_to_project_information": upload_to_project_information, } ) return render_template( "openaire_index.html", body=body, title=_("Upload"), req=req, project_information=get_project_acronym(projectid), breadcrumbs=[(_("Home"), ""), (_("Upload"), "deposit")], **ctx ).encode("utf8")
def edit(self, req, form): argd = wash_urlargd( form, { 'projectid': (int, -1), #'delete': (str, ''), 'id': (str, ''), 'a': (str, 'edit'), #'linkproject': (int, -1), #'unlinkproject': (int, -1), #style': (str, None), #'upload': (str, ''), #'dropbox': (str, '') }) _ = gettext_set_language(argd['ln']) # Check if user is authorized to deposit publications user_info = collect_user_info(req) auth_code, auth_message = acc_authorize_action(user_info, 'submit', doctype='OpenAIRE') if auth_code: if user_info['guest'] == '1': return redirect_to_url( req, "%s/youraccount/login%s" % (CFG_SITE_SECURE_URL, make_canonical_urlargd( { 'referer': "%s%s" % (CFG_SITE_URL, req.unparsed_uri), "ln": argd['ln'] }, {}))) else: return page( req=req, body=_( "You are not authorized to use OpenAIRE deposition."), title=_("Authorization failure"), navmenuid="submit") # Validate action action = argd['a'] if action not in ['edit', 'save', 'submit', 'delete']: abort(404) uid = user_info['uid'] if not argd['id']: return redirect("/deposit/") try: pub = OpenAIREPublication(uid, publicationid=argd['id']) title = pub.metadata.get('title', 'Untitled') except ValueError: abort(404) # # Action handling # if action == 'delete': pub.delete() flash("Upload '%s' was deleted." % title, 'info') return redirect('/deposit/') elif action == 'edit': ctx = { 'pub': pub, 'title': title, 'recid': pub.metadata.get('__recid__', None), } ctx['rendered_form'] = openaire_deposit_templates.tmpl_form( pub.metadata['__publicationid__'], -1, "", # projects_information "", # publication_information "", # fulltext_information form=None, metadata_status='empty', warnings=None, errors=None, ln='en', ) #if action == "edit": #elif action == "delete": # pass # if projectid >= 0: # ## There is a project on which we are working good! # publications = get_all_publications_for_project( # uid, projectid, ln=argd['ln'], style=style) # if argd['publicationid'] in publications: # if argd['addproject'] in all_project_ids: # publications[argd['publicationid'] # ].link_project(argd['linkproject']) # if argd['delproject'] in all_project_ids: # publications[argd['publicationid'] # ].unlink_project(argd['unlinkproject']) # if argd['delete'] and argd['delete'] in publications: # ## there was a request to delete a publication # publications[argd['delete']].delete() # del publications[argd['delete']] # forms = "" # submitted_publications = "" # for index, (publicationid, publication) in enumerate(publications.iteritems()): # if req.method.upper() == 'POST': # publication.merge_form(form, ln=argd['ln']) # if publication.status == 'edited': # publication.check_metadata() # publication.check_projects() # if 'submit_%s' % publicationid in form and not "".join(publication.errors.values()).strip(): # ## i.e. if the button submit for the corresponding publication has been pressed... # publication.upload_record() # if publication.status in ('initialized', 'edited'): # forms += publication.get_publication_form(projectid) # else: # submitted_publications += publication.get_publication_preview() # body += openaire_deposit_templates.tmpl_add_publication_data_and_submit(projectid, forms, submitted_publications, project_information=upload_to_project_information, ln=argd['ln']) # body += openaire_deposit_templates.tmpl_upload_publications(projectid=upload_to_projectid, project_information=upload_to_project_information, session=get_session(req).sid.encode('utf8'), style=style, ln=argd['ln']) # else: ctx.update({ 'myresearch': get_exisiting_publications_for_uid(uid), }) return render_template("openaire_edit.html", req=req, breadcrumbs=[ (_('Home'), ''), (_('Upload'), 'deposit'), (title, ''), ], **ctx).encode('utf8')
body += openaire_deposit_templates.tmpl_add_publication_data_and_submit( projectid, forms, submitted_publications, project_information=upload_to_project_information, ln=argd['ln']) body += openaire_deposit_templates.tmpl_upload_publications( projectid=upload_to_projectid, project_information=upload_to_project_information, session=get_session(req).sid.encode('utf8'), style=style, ln=argd['ln']) else: ctx.update({ 'myresearch': get_exisiting_publications_for_uid(uid), 'upload_to_projectid': upload_to_projectid, 'upload_to_project_information': upload_to_project_information, }) return render_template( "openaire_index.html", body=body, title=_('Upload'), req=req, project_information=get_project_acronym(projectid), breadcrumbs=[ (_('Home'), ''), (_('Upload'), 'deposit'),
def edit(pub_id=u'', action=u'edit'): """ Edit an upload """ uid = current_user.get_id() if action not in ['edit', 'save', 'delete', 'reserve-doi']: abort(404) try: pub = OpenAIREPublication(uid, publicationid=pub_id) title = pub.metadata.get('title', 'Untitled') or 'Untitled' editable = is_editable(pub) except ValueError: abort(404) # All POST requests change the publication, and are not allowed if the # publication is not editable anymore. if request.method == 'POST': if not editable: flash("You cannot edit an already submitted upload. Please contact %s if you would like to make changes!" % CFG_SITE_SUPPORT_EMAIL) return redirect(url_for('.edit', pub_id=pub.publicationid)) # # Action handling # ctx = {} if action == 'reserve-doi': # # Reserve DOI action (AjAX) # if request.method == 'POST': doi = pub.create_doi() return json.dumps({'doi': doi}) else: abort(405) elif action == 'delete': # # Delete action # if not editable: flash("You cannot delete an already submitted upload. Please contact %s if you would like to have it removed!" % CFG_SITE_SUPPORT_EMAIL) return redirect(url_for('.edit', pub_id=pub.publicationid)) pub.delete() flash("Upload '%s' was deleted." % title, 'success') return redirect(url_for('.index')) elif action == 'edit': # # Edit action # upload_url = url_for('deposit.upload', pub_id=pub.publicationid) dropbox_upload_url = url_for('deposit.dropbox_upload', pub_id=pub.publicationid) ctx = { 'pub': pub, 'recid': pub.metadata.get('__recid__', None), 'title': title, 'is_editable': editable, 'upload_url': upload_url, 'dropbox_upload_url': dropbox_upload_url, } if request.method == 'POST': form = DepositionForm(request.values, crsf_enabled=False) mapper = DepositionFormMapper(pub) pub = mapper.map(form) form._pub = pub if form.validate(): pub.save() pub.upload_record() flash("Upload was successfully submitted - it may take up 5 minutes before it has been fully integrated into %s." % CFG_SITE_NAME, category='success') return redirect(url_for('.index')) else: pub.save() ctx['form'] = form ctx['form_message'] = "The form was saved, but there were errors. Please see below." elif editable: mapper = PublicationMapper() form = DepositionForm(mapper.map(pub), crsf_enabled=False) ctx['form'] = form else: ctx['record_hd'] = format_record(recID=pub.recid, xml_record=pub.marcxml, ln=g.ln, of='hd') ctx['record_hdinfo'] = format_record(recID=pub.recid, xml_record=pub.marcxml, ln=g.ln, of='HDINFO') elif action == 'save': # # Save action (AjAX) # if request.method == 'POST': form = DepositionForm(request.values, crsf_enabled=False) mapper = DepositionFormMapper(pub) pub = mapper.map(form) form._pub = pub if form.validate(): pub.save() return json.dumps({'status': 'success', 'form': 'Successfully saved.'}) else: pub.save() errors = dict([(x, '') for x in form._fields.keys()]) errors.update(form.errors) return json.dumps({ 'status': 'warning', 'form': 'The form was saved, but there were errors. Please see below.', 'fields': errors, }) else: abort(405) return render_template( "openaire_edit.html", myresearch=get_exisiting_publications_for_uid(current_user.get_id()), **ctx )
def edit(pub_id=u'', action=u'edit'): """ Edit an upload """ uid = current_user.get_id() if action not in ['edit', 'save', 'delete', 'reserve-doi']: abort(404) try: pub = OpenAIREPublication(uid, publicationid=pub_id) title = pub.metadata.get('title', 'Untitled') or 'Untitled' editable = is_editable(pub) except ValueError: abort(404) # All POST requests change the publication, and are not allowed if the # publication is not editable anymore. if request.method == 'POST': if not editable: flash( "You cannot edit an already submitted upload. Please contact %s if you would like to make changes!" % CFG_SITE_SUPPORT_EMAIL) return redirect(url_for('.edit', pub_id=pub.publicationid)) # # Action handling # ctx = {} if action == 'reserve-doi': # # Reserve DOI action (AjAX) # if request.method == 'POST': doi = pub.create_doi() return json.dumps({'doi': doi}) else: abort(405) elif action == 'delete': # # Delete action # if not editable: flash( "You cannot delete an already submitted upload. Please contact %s if you would like to have it removed!" % CFG_SITE_SUPPORT_EMAIL) return redirect(url_for('.edit', pub_id=pub.publicationid)) pub.delete() flash("Upload '%s' was deleted." % title, 'success') return redirect(url_for('.index')) elif action == 'edit': # # Edit action # upload_url = url_for('deposit.upload', pub_id=pub.publicationid) dropbox_upload_url = url_for('deposit.dropbox_upload', pub_id=pub.publicationid) ctx = { 'pub': pub, 'recid': pub.metadata.get('__recid__', None), 'title': title, 'is_editable': editable, 'upload_url': upload_url, 'dropbox_upload_url': dropbox_upload_url, } if request.method == 'POST': form = DepositionForm(request.values, crsf_enabled=False) mapper = DepositionFormMapper(pub) pub = mapper.map(form) form._pub = pub if form.validate(): pub.save() pub.upload_record() flash( "Upload was successfully submitted - it may take up 5 minutes before it has been fully integrated into %s." % CFG_SITE_NAME, category='success') return redirect(url_for('.index')) else: pub.save() ctx['form'] = form ctx['form_message'] = "The form was saved, but there were errors. Please see below." elif editable: mapper = PublicationMapper() form = DepositionForm(mapper.map(pub), crsf_enabled=False) ctx['form'] = form else: ctx['record_hd'] = format_record(recID=pub.recid, xml_record=pub.marcxml, ln=g.ln, of='hd') ctx['record_hdinfo'] = format_record(recID=pub.recid, xml_record=pub.marcxml, ln=g.ln, of='HDINFO') elif action == 'save': # # Save action (AjAX) # if request.method == 'POST': form = DepositionForm(request.values, crsf_enabled=False) mapper = DepositionFormMapper(pub) pub = mapper.map(form) form._pub = pub if form.validate(): pub.save() return json.dumps({ 'status': 'success', 'form': 'Successfully saved.' }) else: pub.save() errors = dict([(x, '') for x in form._fields.keys()]) errors.update(form.errors) return json.dumps({ 'status': 'warning', 'form': 'The form was saved, but there were errors. Please see below.', 'fields': errors, }) else: abort(405) return render_template("openaire_edit.html", myresearch=get_exisiting_publications_for_uid( current_user.get_id()), **ctx)