当前位置: 首页>>代码示例>>Python>>正文


Python Deposition.set_render_context方法代码示例

本文整理汇总了Python中invenio.modules.deposit.models.Deposition.set_render_context方法的典型用法代码示例。如果您正苦于以下问题:Python Deposition.set_render_context方法的具体用法?Python Deposition.set_render_context怎么用?Python Deposition.set_render_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在invenio.modules.deposit.models.Deposition的用法示例。


在下文中一共展示了Deposition.set_render_context方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _render_form

# 需要导入模块: from invenio.modules.deposit.models import Deposition [as 别名]
# 或者: from invenio.modules.deposit.models.Deposition import set_render_context [as 别名]
    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.')
开发者ID:kasioumis,项目名称:invenio,代码行数:50,代码来源:tasks.py

示例2: _api_validate_files

# 需要导入模块: from invenio.modules.deposit.models import Deposition [as 别名]
# 或者: from invenio.modules.deposit.models.Deposition import set_render_context [as 别名]
 def _api_validate_files(obj, eng):
     if getattr(request, 'is_api_request', False):
         d = Deposition(obj)
         if len(d.files) < 1:
             d.set_render_context(dict(
                 message="Bad request",
                 status=400,
                 errors=[dict(
                     message="Minimum one file must be provided.",
                     code=error_codes['validation_error']
                 )],
             ))
             d.update()
             eng.halt("API: No files provided")
         else:
             # Mark all drafts as completed
             for draft in d.drafts.values():
                 draft.complete()
             d.update()
开发者ID:egabancho,项目名称:zenodo,代码行数:21,代码来源:upload.py

示例3: halt_to_render

# 需要导入模块: from invenio.modules.deposit.models import Deposition [as 别名]
# 或者: from invenio.modules.deposit.models.Deposition import set_render_context [as 别名]
def halt_to_render(obj, eng):
    """Halt the workflow - waiting to be resumed."""
    deposition = Deposition(obj)
    sip = deposition.get_latest_sip(sealed=False)
    deposition.set_render_context(dict(
        template_name_or_list="deposit/completed.html",
        deposition=deposition,
        deposition_type=(
            None if deposition.type.is_default() else
            deposition.type.get_identifier()
        ),
        uuid=deposition.id,
        sip=sip,
        my_depositions=Deposition.get_depositions(
            current_user, type=deposition.type
        ),
        format_record=format_record,
    ))
    obj.last_task = "halt_to_render"
    eng.halt("User submission complete.")
开发者ID:annetteholtkamp,项目名称:inspire-next,代码行数:22,代码来源:submission.py

示例4: _load_record

# 需要导入模块: from invenio.modules.deposit.models import Deposition [as 别名]
# 或者: from invenio.modules.deposit.models.Deposition import set_render_context [as 别名]
    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")
开发者ID:kasioumis,项目名称:invenio,代码行数:64,代码来源:tasks.py


注:本文中的invenio.modules.deposit.models.Deposition.set_render_context方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。