def get(self): """List depositions. :param type: Upload type identifier (optional) """ args = list_parser.parse_args() result = Deposition.get_depositions( user=current_user, type=args['type'] or None ) return map(lambda o: o.marshal(), result)
def _render_form(obj, eng): d = Deposition(obj) draft = d.get_or_create_draft(draft_id) if getattr(request, 'is_api_request', False): form = draft.get_form(validate_draft=True) if form.errors: error_messages = [] for field, msgs in form.errors: for m in msgs: error_messages.append( field=field, message=m, code=error_codes['validation_error'], ) d.set_render_context(dict( response=dict( message="Bad request", status=400, errors=error_messages, ), status=400, )) eng.halt("API: Draft did not validate") else: if draft.is_completed(): eng.jumpCallForward(1) else: form = draft.get_form(validate_draft=draft.validate) form.validate = True d.set_render_context(dict( template_name_or_list=form.get_template(), deposition=d, deposition_type=( None if d.type.is_default() else d.type.get_identifier() ), uuid=d.id, draft=draft, form=form, my_depositions=Deposition.get_depositions( current_user, type=d.type ), )) d.update() eng.halt('Wait for form submission.')
def render_completed(cls, d): """ Render page when deposition was successfully completed """ ctx = dict( deposition=d, deposition_type=( None if d.type.is_default() else d.type.get_identifier() ), uuid=d.id, my_depositions=Deposition.get_depositions( current_user, type=d.type ), sip=d.get_latest_sip(), format_record=format_record, ) return render_template('deposit/completed.html', **ctx)
def _load_record(obj, eng): d = Deposition(obj) sip = d.get_latest_sip(sealed=True) record = get_record(sip.metadata.get('recid'), reset_cache=True) if not is_sip_uploaded(sip, record=record): if getattr(request, 'is_api_request', False): d.set_render_context(dict( response=dict( message="Conflict", status=409, errors="Upload not yet fully integrated. Please wait" " a few moments.", ), status=409, )) else: from flask import flash flash( "Editing is only possible after your upload have been" " fully integrated. Please wait a few moments, then try" " to reload the page.", category='warning' ) d.set_render_context(dict( template_name_or_list="deposit/completed.html", deposition=d, deposition_type=( None if d.type.is_default() else d.type.get_identifier() ), uuid=d.id, sip=sip, my_depositions=Deposition.get_depositions( current_user, type=d.type ), format_record=format_record, )) d.update() eng.halt("Wait for record to be uploaded") # Check if record is already loaded, if so, skip. if d.drafts: eng.jumpCallForward(1) # Load draft draft = d.get_or_create_draft(draft_id) # Fill draft with values from recjson record_to_draft( record, draft=draft, post_process=post_process, producer=producer ) d.update() # Stop API request if getattr(request, 'is_api_request', False): d.set_render_context(dict( response=d.marshal(), status=201, )) eng.halt("API request")