本文整理汇总了Python中superdesk.workflow.is_workflow_state_transition_valid函数的典型用法代码示例。如果您正苦于以下问题:Python is_workflow_state_transition_valid函数的具体用法?Python is_workflow_state_transition_valid怎么用?Python is_workflow_state_transition_valid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_workflow_state_transition_valid函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create
def create(self, docs, **kwargs):
guid_of_translated_items = []
for doc in docs:
guid_of_item_to_be_translated = doc.get('guid')
archive_service = get_resource_service(ARCHIVE)
archived_doc = archive_service.find_one(req=None, _id=guid_of_item_to_be_translated)
if not archived_doc:
raise SuperdeskApiError.notFoundError('Fail to found item with guid: %s' %
guid_of_item_to_be_translated)
if not is_workflow_state_transition_valid('translate', archived_doc[ITEM_STATE]):
raise InvalidStateTransitionError()
get_resource_service('macros').execute_translation_macro(
archived_doc, archived_doc.get('language', None), doc.get('language'))
archived_doc['language'] = doc.get('language')
new_guid = archive_service.duplicate_content(archived_doc)
guid_of_translated_items.append(new_guid)
if kwargs.get('notify', True):
push_content_notification([archived_doc])
return guid_of_translated_items
开发者ID:hlmnrmr,项目名称:superdesk-core,代码行数:25,代码来源:archive_translate.py
示例2: create
def create(self, docs, **kwargs):
for doc in docs:
ingest_doc = superdesk.get_resource_service('ingest').find_one(req=None, _id=doc.get('guid'))
if not ingest_doc:
msg = 'Fail to found ingest item with guid: %s' % doc.get('guid')
raise SuperdeskError(payload=msg)
if not is_workflow_state_transition_valid('fetch_as_from_ingest', ingest_doc[config.CONTENT_STATE]):
raise InvalidStateTransitionError()
mark_ingest_as_archived(ingest_doc=ingest_doc)
archived_doc = superdesk.get_resource_service(ARCHIVE).find_one(req=None, _id=doc.get('guid'))
if not archived_doc:
create_from_ingest_doc(doc, ingest_doc)
send_to(doc, doc.get('desk'))
superdesk.get_resource_service(ARCHIVE).post([doc])
task = archive_item.delay(doc.get('guid'), ingest_doc.get('ingest_provider'), get_user())
doc['task_id'] = task.id
if task.state not in ('PROGRESS', states.SUCCESS, states.FAILURE) and not task.result:
update_status(task.id, 0, 0)
return [doc.get('guid') for doc in docs]
开发者ID:vied12,项目名称:superdesk-server,代码行数:25,代码来源:archive_ingest.py
示例3: update
def update(self, id, updates, original):
original_state = original[ITEM_STATE]
if not is_workflow_state_transition_valid(ITEM_SPIKE, original_state):
raise InvalidStateTransitionError()
user = get_user(required=True)
item = get_resource_service(ARCHIVE).find_one(req=None, _id=id)
task = item.get('task', {})
updates[EXPIRY] = self._get_spike_expiry(desk_id=task.get('desk'), stage_id=task.get('stage'))
updates[REVERT_STATE] = item.get(ITEM_STATE, None)
if original.get('rewrite_of'):
updates['rewrite_of'] = None
if original.get('rewritten_by'):
updates['rewritten_by'] = None
if original.get('broadcast'):
updates['broadcast'] = None
if original.get('rewrite_sequence'):
updates['rewrite_sequence'] = None
# remove any relation with linked items
updates[ITEM_EVENT_ID] = generate_guid(type=GUID_TAG)
# remove lock
updates.update({
'lock_user': None,
'lock_session': None,
})
if original[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE:
# remove links from items in the package
package_service = PackageService()
items = package_service.get_item_refs(original)
for item in items:
package_item = get_resource_service(ARCHIVE).find_one(req=None, _id=item[GUID_FIELD])
if package_item:
linked_in_packages = [linked for linked in package_item.get(LINKED_IN_PACKAGES, [])
if linked.get(PACKAGE) != original.get(config.ID_FIELD)]
super().system_update(package_item[config.ID_FIELD],
{LINKED_IN_PACKAGES: linked_in_packages},
package_item)
# keep the structure of old group in order to be able to unspike the package
updates[DELETED_GROUPS] = original[GROUPS]
# and remove all the items from the package
updates['groups'] = []
item = self.backend.update(self.datasource, id, updates, original)
push_notification('item:spike', item=str(id), user=str(user.get(config.ID_FIELD)))
history_updates = dict(updates)
if original.get('task'):
history_updates['task'] = original.get('task')
app.on_archive_item_updated(history_updates, original, ITEM_SPIKE)
self._removed_refs_from_package(id)
return item
开发者ID:jerome-poisson,项目名称:superdesk-core,代码行数:60,代码来源:archive_spike.py
示例4: move_content
def move_content(self, id, doc):
archive_service = get_resource_service(ARCHIVE)
archived_doc = archive_service.find_one(req=None, _id=id)
if not archived_doc:
raise SuperdeskApiError.notFoundError('Fail to found item with guid: %s' % id)
current_stage_of_item = archived_doc.get('task', {}).get('stage')
if current_stage_of_item and str(current_stage_of_item) == str(doc.get('task', {}).get('stage')):
raise SuperdeskApiError.preconditionFailedError(message='Move is not allowed within the same stage.')
if not is_workflow_state_transition_valid('submit_to_desk', archived_doc[config.CONTENT_STATE]):
raise InvalidStateTransitionError()
original = dict(archived_doc)
send_to(archived_doc, doc.get('task', {}).get('desc'), doc.get('task', {}).get('stage'))
if archived_doc[config.CONTENT_STATE] not in ['published', 'scheduled', 'killed']:
archived_doc[config.CONTENT_STATE] = 'submitted'
resolve_document_version(archived_doc, ARCHIVE, 'PATCH', original)
del archived_doc['_id']
archive_service.update(original['_id'], archived_doc, original)
insert_into_versions(id_=original['_id'])
return archived_doc
开发者ID:ahilles107,项目名称:superdesk-1,代码行数:29,代码来源:archive_move.py
示例5: move_content
def move_content(self, id, doc):
archive_service = get_resource_service(ARCHIVE)
archived_doc = archive_service.find_one(req=None, _id=id)
if not archived_doc:
raise SuperdeskApiError.notFoundError('Fail to found item with guid: %s' % id)
current_stage_of_item = archived_doc.get('task', {}).get('stage')
if current_stage_of_item and str(current_stage_of_item) == str(doc.get('task', {}).get('stage')):
raise SuperdeskApiError.preconditionFailedError(message='Move is not allowed within the same stage.')
if not is_workflow_state_transition_valid('submit_to_desk', archived_doc[ITEM_STATE]):
raise InvalidStateTransitionError()
original = dict(archived_doc)
user = get_user()
send_to(doc=archived_doc, desk_id=doc.get('task', {}).get('desc'), stage_id=doc.get('task', {}).get('stage'),
user_id=user.get(config.ID_FIELD))
if archived_doc[ITEM_STATE] not in {CONTENT_STATE.PUBLISHED, CONTENT_STATE.SCHEDULED, CONTENT_STATE.KILLED}:
archived_doc[ITEM_STATE] = CONTENT_STATE.SUBMITTED
archived_doc[ITEM_OPERATION] = ITEM_MOVE
set_sign_off(archived_doc, original=original)
resolve_document_version(archived_doc, ARCHIVE, 'PATCH', original)
del archived_doc[config.ID_FIELD]
archive_service.update(original[config.ID_FIELD], archived_doc, original)
insert_into_versions(id_=original[config.ID_FIELD])
return archived_doc
开发者ID:chalkjockey,项目名称:superdesk,代码行数:33,代码来源:archive_move.py
示例6: create
def create(self, docs, **kwargs):
guid_of_item_to_be_moved = request.view_args['guid']
guid_of_moved_items = []
for doc in docs:
archive_service = get_resource_service(ARCHIVE)
archived_doc = archive_service.find_one(req=None, _id=guid_of_item_to_be_moved)
if not archived_doc:
raise SuperdeskApiError.notFoundError('Fail to found item with guid: %s' %
guid_of_item_to_be_moved)
current_stage_of_item = archived_doc.get('task', {}).get('stage')
if current_stage_of_item and str(current_stage_of_item) == str(doc.get('stage')):
raise SuperdeskApiError.preconditionFailedError(message='Move is not allowed within the same stage.')
if not is_workflow_state_transition_valid('submit_to_desk', archived_doc[config.CONTENT_STATE]):
raise InvalidStateTransitionError()
original = dict(archived_doc)
send_to(archived_doc, doc.get('desk'), doc.get('stage'))
archived_doc[config.CONTENT_STATE] = 'submitted'
resolve_document_version(archived_doc, ARCHIVE, 'PATCH', original)
del archived_doc['_id']
archive_service.update(original['_id'], archived_doc, original)
insert_into_versions(guid=original['_id'])
guid_of_moved_items.append(archived_doc['guid'])
return guid_of_moved_items
开发者ID:yukoff,项目名称:superdesk,代码行数:34,代码来源:archive_move.py
示例7: create
def create(self, docs, **kwargs):
guid_of_item_to_be_duplicated = request.view_args['guid']
guid_of_duplicated_items = []
for doc in docs:
archive_service = get_resource_service(ARCHIVE)
archived_doc = archive_service.find_one(req=None, _id=guid_of_item_to_be_duplicated)
if not archived_doc:
raise SuperdeskApiError.notFoundError('Fail to found item with guid: %s' %
guid_of_item_to_be_duplicated)
current_desk_of_item = archived_doc.get('task', {}).get('desk')
if current_desk_of_item is None or str(current_desk_of_item) != str(doc.get('desk')):
raise SuperdeskApiError.preconditionFailedError(message='Duplicate is allowed within the same desk.')
if not is_workflow_state_transition_valid('duplicate', archived_doc[ITEM_STATE]):
raise InvalidStateTransitionError()
send_to(doc=archived_doc, desk_id=doc.get('desk'))
new_guid = archive_service.duplicate_content(archived_doc)
guid_of_duplicated_items.append(new_guid)
if kwargs.get('notify', True):
push_content_notification([archived_doc])
return guid_of_duplicated_items
开发者ID:actionless,项目名称:superdesk,代码行数:28,代码来源:archive_duplication.py
示例8: update
def update(self, id, updates, original):
original_state = original[ITEM_STATE]
if not is_workflow_state_transition_valid('spike', original_state):
raise InvalidStateTransitionError()
package_service = PackageService()
user = get_user(required=True)
item = get_resource_service(ARCHIVE).find_one(req=None, _id=id)
expiry_minutes = app.settings['SPIKE_EXPIRY_MINUTES']
# check if item is in a desk. If it's then use the desks spike_expiry
if is_assigned_to_a_desk(item):
desk = get_resource_service('desks').find_one(_id=item['task']['desk'], req=None)
expiry_minutes = desk.get('spike_expiry', expiry_minutes)
updates[EXPIRY] = get_expiry_date(expiry_minutes)
updates[REVERT_STATE] = item.get(ITEM_STATE, None)
if original.get('rewrite_of'):
updates['rewrite_of'] = None
item = self.backend.update(self.datasource, id, updates, original)
push_notification('item:spike', item=str(item.get('_id')), user=str(user))
package_service.remove_spiked_refs_from_package(id)
return item
开发者ID:verifiedpixel,项目名称:verifiedpixel,代码行数:26,代码来源:archive_spike.py
示例9: _validate
def _validate(self, doc_in_archive, doc, guid_to_duplicate):
"""Validates if the given archived_doc is still eligible to be duplicated.
Rules:
1. Is the item requested found in archive collection?
2. Is workflow transition valid?
3. Is item locked by another user?
:param doc_in_archive: object representing the doc in archive collection
:type doc_in_archive: dict
:param doc: object received as part of request
:type doc: dict
:param guid_to_duplicate: GUID of the item to duplicate
:type guid_to_duplicate: str
:raises
SuperdeskApiError.notFoundError: If doc_in_archive is None
SuperdeskApiError.forbiddenError: if item is locked
InvalidStateTransitionError: if workflow transition is invalid
"""
if not doc_in_archive:
raise SuperdeskApiError.notFoundError('Fail to found item with guid: %s' % guid_to_duplicate)
if not is_workflow_state_transition_valid('duplicate', doc_in_archive[ITEM_STATE]):
raise InvalidStateTransitionError()
lock_user = doc_in_archive.get('lock_user', None)
force_unlock = doc_in_archive.get('force_unlock', False)
user = get_user()
str_user_id = str(user.get(config.ID_FIELD)) if user else None
if lock_user and str(lock_user) != str_user_id and not force_unlock:
raise SuperdeskApiError.forbiddenError('The item was locked by another user')
开发者ID:superdesk,项目名称:superdesk-core,代码行数:32,代码来源:archive_duplication.py
示例10: create
def create(self, docs, **kwargs):
guid_of_item_to_be_copied = request.view_args['guid']
guid_of_copied_items = []
for doc in docs:
archive_service = get_resource_service(ARCHIVE)
archived_doc = archive_service.find_one(req=None, _id=guid_of_item_to_be_copied)
if not archived_doc:
raise SuperdeskApiError.notFoundError('Fail to found item with guid: %s' %
guid_of_item_to_be_copied)
current_desk_of_item = archived_doc.get('task', {}).get('desk')
if current_desk_of_item:
raise SuperdeskApiError.preconditionFailedError(message='Copy is not allowed on items in a desk.')
if not is_workflow_state_transition_valid('copy', archived_doc[ITEM_STATE]):
raise InvalidStateTransitionError()
new_guid = archive_service.duplicate_content(archived_doc)
guid_of_copied_items.append(new_guid)
if kwargs.get('notify', True):
push_notification('item:copy', copied=1)
return guid_of_copied_items
开发者ID:MiczFlor,项目名称:superdesk-core,代码行数:27,代码来源:archive_copy.py
示例11: update
def update(self, id, updates, original):
original_state = original[config.CONTENT_STATE]
if not is_workflow_state_transition_valid("spike", original_state):
raise InvalidStateTransitionError()
package_service = PackageService()
user = get_user(required=True)
item = get_resource_service(ARCHIVE).find_one(req=None, _id=id)
expiry_minutes = app.settings["SPIKE_EXPIRY_MINUTES"]
# check if item is in a desk. If it's then use the desks spike_expiry
if is_assigned_to_a_desk(item):
desk = get_resource_service("desks").find_one(_id=item["task"]["desk"], req=None)
expiry_minutes = desk.get("spike_expiry", expiry_minutes)
updates[EXPIRY] = get_expiry_date(expiry_minutes)
updates[REVERT_STATE] = item.get(app.config["CONTENT_STATE"], None)
if original.get("rewrite_of"):
updates["rewrite_of"] = None
item = self.backend.update(self.datasource, id, updates, original)
push_notification("item:spike", item=str(item.get("_id")), user=str(user))
package_service.remove_spiked_refs_from_package(id)
return item
开发者ID:oxcarh,项目名称:superdesk,代码行数:26,代码来源:archive_spike.py
示例12: raise_if_invalid_state_transition
def raise_if_invalid_state_transition(self, original):
if not is_workflow_state_transition_valid(self.publish_type, original[ITEM_STATE]):
error_message = (
"Can't {} as item state is {}"
if original[ITEM_TYPE] == CONTENT_TYPE.TEXT
else "Can't {} as either package state or one of the items state is {}"
)
raise InvalidStateTransitionError(error_message.format(self.publish_type, original[ITEM_STATE]))
开发者ID:will-in-wi,项目名称:superdesk,代码行数:8,代码来源:common.py
示例13: __update_state
def __update_state(self, updates, original):
if self.__is_content_assigned_to_new_desk(original, updates):
# check if the preconditions for the action are in place
original_state = original[config.CONTENT_STATE]
if not is_workflow_state_transition_valid('move', original_state):
raise InvalidStateTransitionError()
updates[config.CONTENT_STATE] = 'draft' if self.__is_content_moved_from_desk(updates) else 'submitted'
resolve_document_version(updates, ARCHIVE, 'PATCH', original)
开发者ID:ahilles107,项目名称:superdesk-1,代码行数:9,代码来源:tasks.py
示例14: __update_state
def __update_state(self, updates, original):
if self.__is_content_assigned_to_new_desk(original, updates):
# check if the preconditions for the action are in place
original_state = original[ITEM_STATE]
if not is_workflow_state_transition_valid('move', original_state):
raise InvalidStateTransitionError()
updates[ITEM_STATE] = CONTENT_STATE.DRAFT if self.__is_content_moved_from_desk(updates) \
else CONTENT_STATE.SUBMITTED
resolve_document_version(updates, ARCHIVE, 'PATCH', original)
开发者ID:actionless,项目名称:superdesk,代码行数:10,代码来源:tasks.py
示例15: _validate
def _validate(self, archived_doc, doc):
"""Validate that the item can be move.
:param dict archived_doc: item to be moved
:param dict doc: new location details
"""
current_stage_of_item = archived_doc.get('task', {}).get('stage')
if current_stage_of_item and str(current_stage_of_item) == str(doc.get('task', {}).get('stage')):
raise SuperdeskApiError.preconditionFailedError(message='Move is not allowed within the same stage.')
if not is_workflow_state_transition_valid('submit_to_desk', archived_doc[ITEM_STATE]):
raise InvalidStateTransitionError()
开发者ID:sjunaid,项目名称:superdesk-core,代码行数:11,代码来源:archive_move.py
示例16: fetch
def fetch(self, docs, id=None, **kwargs):
id_of_fetched_items = []
for doc in docs:
id_of_item_to_be_fetched = doc.get('_id') if id is None else id
desk_id = doc.get('desk')
stage_id = doc.get('stage')
ingest_service = get_resource_service('ingest')
ingest_doc = ingest_service.find_one(req=None, _id=id_of_item_to_be_fetched)
if not ingest_doc:
raise SuperdeskApiError.notFoundError('Fail to found ingest item with _id: %s' %
id_of_item_to_be_fetched)
if not is_workflow_state_transition_valid('fetch_from_ingest', ingest_doc[config.CONTENT_STATE]):
raise InvalidStateTransitionError()
if doc.get('macro'): # there is a macro so transform it
ingest_doc = get_resource_service('macros').execute_macro(ingest_doc, doc.get('macro'))
archived = utcnow()
ingest_service.patch(id_of_item_to_be_fetched, {'archived': archived})
dest_doc = dict(ingest_doc)
new_id = generate_guid(type=GUID_TAG)
id_of_fetched_items.append(new_id)
dest_doc['_id'] = new_id
dest_doc['guid'] = new_id
dest_doc['destination_groups'] = doc.get('destination_groups')
generate_unique_id_and_name(dest_doc)
dest_doc[config.VERSION] = 1
send_to(dest_doc, desk_id, stage_id)
dest_doc[config.CONTENT_STATE] = doc.get('state', STATE_FETCHED)
dest_doc[INGEST_ID] = dest_doc[FAMILY_ID] = ingest_doc['_id']
remove_unwanted(dest_doc)
set_original_creator(dest_doc)
self.__fetch_items_in_package(dest_doc, desk_id, stage_id,
doc.get('state', STATE_FETCHED),
doc.get('destination_groups'))
get_resource_service(ARCHIVE).post([dest_doc])
insert_into_versions(doc=dest_doc)
build_custom_hateoas(custom_hateoas, dest_doc)
doc.update(dest_doc)
if kwargs.get('notify', True):
push_notification('item:fetch', fetched=1)
return id_of_fetched_items
开发者ID:ahilles107,项目名称:superdesk-1,代码行数:53,代码来源:archive_fetch.py
示例17: fetch
def fetch(self, docs, id=None, **kwargs):
id_of_fetched_items = []
for doc in docs:
id_of_item_to_be_fetched = doc.get("_id") if id is None else id
desk_id = doc.get("desk")
stage_id = doc.get("stage")
ingest_service = get_resource_service("ingest")
ingest_doc = ingest_service.find_one(req=None, _id=id_of_item_to_be_fetched)
if not ingest_doc:
raise SuperdeskApiError.notFoundError(
"Fail to found ingest item with _id: %s" % id_of_item_to_be_fetched
)
if not is_workflow_state_transition_valid("fetch_from_ingest", ingest_doc[ITEM_STATE]):
raise InvalidStateTransitionError()
if doc.get("macro"): # there is a macro so transform it
ingest_doc = get_resource_service("macros").execute_macro(ingest_doc, doc.get("macro"))
archived = utcnow()
ingest_service.patch(id_of_item_to_be_fetched, {"archived": archived})
dest_doc = dict(ingest_doc)
new_id = generate_guid(type=GUID_TAG)
id_of_fetched_items.append(new_id)
dest_doc["_id"] = new_id
dest_doc["guid"] = new_id
generate_unique_id_and_name(dest_doc)
dest_doc[config.VERSION] = 1
send_to(doc=dest_doc, desk_id=desk_id, stage_id=stage_id)
dest_doc[ITEM_STATE] = doc.get(ITEM_STATE, CONTENT_STATE.FETCHED)
dest_doc[INGEST_ID] = dest_doc[FAMILY_ID] = ingest_doc["_id"]
dest_doc[ITEM_OPERATION] = ITEM_FETCH
remove_unwanted(dest_doc)
set_original_creator(dest_doc)
self.__fetch_items_in_package(dest_doc, desk_id, stage_id, doc.get(ITEM_STATE, CONTENT_STATE.FETCHED))
get_resource_service(ARCHIVE).post([dest_doc])
insert_into_versions(doc=dest_doc)
build_custom_hateoas(custom_hateoas, dest_doc)
doc.update(dest_doc)
if kwargs.get("notify", True):
push_notification("item:fetch", fetched=1)
return id_of_fetched_items
开发者ID:chalkjockey,项目名称:superdesk,代码行数:52,代码来源:archive_fetch.py
示例18: update_state
def update_state(self, original, updates):
original_state = original.get(config.CONTENT_STATE)
if original_state != 'ingested' and original_state != 'in_progress':
if not is_workflow_state_transition_valid('save', original_state):
raise InvalidStateTransitionError()
elif self._is_req_for_save(updates):
if original.get('task', {}).get('desk', None) is None:
# content is on workspace
if original_state != 'draft':
updates[config.CONTENT_STATE] = 'draft'
else:
# content is on a desk
updates[config.CONTENT_STATE] = 'in_progress'
开发者ID:vied12,项目名称:superdesk-server,代码行数:13,代码来源:archive.py
示例19: on_update
def on_update(self, updates, original):
if original.get('marked_for_not_publication', False):
raise SuperdeskApiError.badRequestError(
message='Cannot publish an item which is marked as Not for Publication')
if not is_workflow_state_transition_valid(self.publish_type, original[config.CONTENT_STATE]):
raise InvalidStateTransitionError()
validate_item = {'act': self.publish_type, 'type': original['type'], 'validate': updates}
validation_errors = get_resource_service('validate').post([validate_item])
if validation_errors[0]:
raise ValidationError(validation_errors)
开发者ID:oxcarh,项目名称:superdesk,代码行数:13,代码来源:archive_publish.py
示例20: on_update
def on_update(self, updates, original):
if original.get('marked_for_not_publication', False):
raise SuperdeskApiError.badRequestError(
message='Cannot publish an item which is marked as Not for Publication')
if not is_workflow_state_transition_valid(self.publish_type, original[config.CONTENT_STATE]):
raise InvalidStateTransitionError()
if original.get('item_id') and get_resource_service('published').is_published_before(original['item_id']):
raise PublishQueueError.post_publish_exists_error(Exception('Story with id:{}'.format(original['_id'])))
validate_item = {'act': self.publish_type, 'validate': updates}
validation_errors = get_resource_service('validate').post([validate_item])
if validation_errors[0]:
raise ValidationError(validation_errors)
开发者ID:Flowdeeps,项目名称:superdesk-1,代码行数:14,代码来源:archive_publish.py
注:本文中的superdesk.workflow.is_workflow_state_transition_valid函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论