本文整理汇总了Python中invenio_workflows.models.BibWorkflowObject.create_object方法的典型用法代码示例。如果您正苦于以下问题:Python BibWorkflowObject.create_object方法的具体用法?Python BibWorkflowObject.create_object怎么用?Python BibWorkflowObject.create_object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类invenio_workflows.models.BibWorkflowObject
的用法示例。
在下文中一共展示了BibWorkflowObject.create_object方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_payload_file_creation
# 需要导入模块: from invenio_workflows.models import BibWorkflowObject [as 别名]
# 或者: from invenio_workflows.models.BibWorkflowObject import create_object [as 别名]
def test_payload_file_creation(self):
"""Can add a file to a Payload."""
from invenio_workflows.models import BibWorkflowObject
from inspire.modules.workflows.models import Payload
from inspire.utils.helpers import (
get_file_by_name,
add_file_by_name,
)
obj = BibWorkflowObject.create_object()
obj.save()
obj.data = obj.get_data() # FIXME hack until workflow 2.0
payload = Payload.create(workflow_object=obj, type="payload_fixture")
payload.save()
fd, filename = tempfile.mkstemp()
os.close(fd)
newpath = add_file_by_name(payload, filename)
self.assertTrue(newpath)
self.assertTrue(get_file_by_name(payload,
os.path.basename(filename)))
BibWorkflowObject.delete(obj)
示例2: demoform
# 需要导入模块: from invenio_workflows.models import BibWorkflowObject [as 别名]
# 或者: from invenio_workflows.models.BibWorkflowObject import create_object [as 别名]
def demoform():
"""View for INSPIRE demo form."""
# from inspire.modules.forms.utils import DataExporter
form = DemoForm(data={"nickname": "John Doe"})
ctx = {
"action": url_for('.demoform'),
"name": "inspireForm",
"id": "inspireForm",
}
if form.validate_on_submit():
# If it is needed to post process the form keys, for example to match
# the names in the JSONAlchemy, one can use the DataExporter.
# The keys will then be renamed using `export_key` parameter.
# visitor = DataExporter()
# visitor.visit(form)
# visitor.data
from invenio_workflows.models import BibWorkflowObject
from flask.ext.login import current_user
myobj = BibWorkflowObject.create_object(id_user=current_user.get_id())
myobj.set_data(form.data)
# Start workflow. delayed=True will execute the workflow in the
# background using, for example, Celery.
myobj.start_workflow("demoworkflow", delayed=True)
return render_template('forms/form_demo_success.html', form=form)
return render_template('forms/form_demo.html', form=form, **ctx)
示例3: test_restart_failed_workflow
# 需要导入模块: from invenio_workflows.models import BibWorkflowObject [as 别名]
# 或者: from invenio_workflows.models.BibWorkflowObject import create_object [as 别名]
def test_restart_failed_workflow(self):
"""Test restarting workflow for given workflow id."""
from invenio_workflows.models import (BibWorkflowObject,
ObjectVersion)
from invenio_workflows.engine import WorkflowStatus
from invenio_workflows.api import start, start_by_oids
from invenio_workflows.errors import WorkflowError
initial_data = BibWorkflowObject.create_object()
initial_data.set_data(1)
initial_data.save()
self.assertRaises(
WorkflowError,
start,
workflow_name="demo_workflow_error",
data=[initial_data],
module_name="unit_tests"
)
self.assertEqual(initial_data.version, ObjectVersion.ERROR)
restarted_workflow = start_by_oids("demo_workflow",
oids=[initial_data.id],
module_name="unit_tests")
self.assertEqual(initial_data.version, ObjectVersion.WAITING)
self.assertEqual(restarted_workflow.status, WorkflowStatus.HALTED)
示例4: __init__
# 需要导入模块: from invenio_workflows.models import BibWorkflowObject [as 别名]
# 或者: from invenio_workflows.models.BibWorkflowObject import create_object [as 别名]
def __init__(self, workflow_object, type=None, user_id=None):
"""Init."""
self.workflow_object = workflow_object
if not workflow_object:
self.files = []
self.drafts = {}
self.type = self.get_type(type)
self.title = ""
self.sips = []
self.workflow_object = BibWorkflowObject.create_object(id_user=user_id)
# Ensure default data is set for all objects.
self.update()
else:
self.__setstate__(workflow_object.get_data())
self.engine = None
示例5: run_harvest
# 需要导入模块: from invenio_workflows.models import BibWorkflowObject [as 别名]
# 或者: from invenio_workflows.models.BibWorkflowObject import create_object [as 别名]
def run_harvest(workflow, **kwargs):
"""Run given harvesting workflow in Celery."""
from invenio.base.globals import cfg
from invenio_workflows.models import BibWorkflowObject
args = {
"workflow": workflow
}
args.update(**kwargs)
data = BibWorkflowObject.create_object()
extra_data = data.get_extra_data()
extra_data["args"] = args
extra_data["config"] = cfg["HARVESTER_WORKFLOWS_CONFIG"].get(workflow, {})
data.set_extra_data(extra_data)
data.set_data({})
data.save()
data.start_workflow(workflow, delayed=True)
示例6: submitupdate
# 需要导入模块: from invenio_workflows.models import BibWorkflowObject [as 别名]
# 或者: from invenio_workflows.models.BibWorkflowObject import create_object [as 别名]
def submitupdate():
"""Form action handler for INSPIRE author update form."""
from inspirehep.modules.forms.utils import DataExporter
from invenio_workflows.models import BibWorkflowObject
from flask.ext.login import current_user
form = AuthorUpdateForm(formdata=request.form)
visitor = DataExporter()
visitor.visit(form)
myobj = BibWorkflowObject.create_object(id_user=current_user.get_id())
myobj.set_data(visitor.data)
# Start workflow. delayed=True will execute the workflow in the
# background using, for example, Celery.
myobj.start_workflow("authorupdate", delayed=True)
ctx = {
"inspire_url": get_inspire_url(visitor.data)
}
return render_template('authors/forms/update_success.html', **ctx)