コード例 #1
0
ファイル: upload.py プロジェクト: IFCA/lifewatch_osf
 def _api_validate_files(obj, eng):
     if getattr(request, 'is_api_request', False):
         d = Deposition(obj)
         missing_files = False
         if len(d.files) < 1:
             for draft in d.drafts_list:
                 draft_type = draft.values.get('upload_type')
                 if draft_type != 'analysis':
                     missing_files = True
                     break
         if missing_files:
             d.set_render_context(dict(
                 response=dict(
                     message="Bad request",
                     status=400,
                     errors=[dict(
                         message="Minimum one file must be provided.",
                         code=error_codes['validation_error']
                     )],
                 ),
                 status=400,
             ))
             d.update()
             eng.halt("API: No files provided")
         else:
             # Mark all drafts as completed
             for draft in d.drafts.values():
                 draft.complete()
             d.update()
コード例 #2
0
ファイル: tasks.py プロジェクト: IFCA/lifewatch_osf
    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.')
コード例 #3
0
ファイル: tasks.py プロジェクト: IFCA/lifewatch_osf
    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")