本文整理汇总了Python中superdesk.notification.push_notification函数的典型用法代码示例。如果您正苦于以下问题:Python push_notification函数的具体用法?Python push_notification怎么用?Python push_notification使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了push_notification函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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
示例2: publish
def publish(self, doc, updates, target_output_channels=None):
any_channel_closed, wrong_formatted_channels, queued = \
self.queue_transmission(doc=doc, target_output_channels=target_output_channels)
if updates:
desk = None
if doc.get('task', {}).get('desk'):
desk = get_resource_service('desks').find_one(req=None, _id=doc['task']['desk'])
if not doc.get('ingest_provider'):
updates['source'] = desk['source'] if desk and desk.get('source', '') \
else DEFAULT_SOURCE_VALUE_FOR_MANUAL_ARTICLES
user = get_user()
if wrong_formatted_channels and len(wrong_formatted_channels) > 0:
push_notification('item:publish:wrong:format',
item=str(doc['_id']), unique_name=doc['unique_name'],
desk=str(doc['task']['desk']),
user=str(user.get('_id', '')),
output_channels=[c['name'] for c in wrong_formatted_channels])
if not target_output_channels and not queued:
raise PublishQueueError.item_not_queued_error(Exception('Nothing is saved to publish queue'), None)
return any_channel_closed, queued
示例3: 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
示例4: on_updated
def on_updated(self, updates, original):
do_notification = updates.get('notifications', {})\
.get('on_update', original.get('notifications', {}).get('on_update', True))
notify_and_add_activity(ACTIVITY_UPDATE, 'updated Ingest Channel {{name}}',
self.datasource, item=None,
user_list=self.user_service.get_users_by_user_type('administrator')
if do_notification else None,
name=updates.get('name', original.get('name')),
provider_id=original.get('_id'))
if updates.get('is_closed', False) != original.get('is_closed', False):
status = ''
do_notification = False
if updates.get('is_closed'):
status = 'closed'
do_notification = updates.get('notifications', {}). \
get('on_close', original.get('notifications', {}).get('on_close', True))
elif not updates.get('is_closed'):
status = 'opened'
do_notification = updates.get('notifications', {}). \
get('on_open', original.get('notifications', {}).get('on_open', True))
notify_and_add_activity(ACTIVITY_EVENT, '{{status}} Ingest Channel {{name}}',
self.datasource, item=None,
user_list=self.user_service.get_users_by_user_type('administrator')
if do_notification else None,
name=updates.get('name', original.get('name')),
status=status, provider_id=original.get('_id'))
push_notification('ingest_provider:update', provider_id=str(original.get('_id')))
logger.info("Updated Ingest Channel. Data: {}".format(updates))
示例5: lock
def lock(self, item_filter, user_id, session_id, etag):
item_model = get_model(ItemModel)
item = item_model.find_one(item_filter)
if not item:
raise SuperdeskApiError.notFoundError()
can_user_lock, error_message = self.can_lock(item, user_id, session_id)
if can_user_lock:
self.app.on_item_lock(item, user_id)
updates = {LOCK_USER: user_id, LOCK_SESSION: session_id, 'lock_time': utcnow()}
item_model.update(item_filter, updates)
if item.get(TASK):
item[TASK]['user'] = user_id
else:
item[TASK] = {'user': user_id}
superdesk.get_resource_service('tasks').assign_user(item[config.ID_FIELD], item[TASK])
self.app.on_item_locked(item, user_id)
push_notification('item:lock',
item=str(item.get(config.ID_FIELD)),
item_version=str(item.get(config.VERSION)),
user=str(user_id), lock_time=updates['lock_time'],
lock_session=str(session_id))
else:
raise SuperdeskApiError.forbiddenError(message=error_message)
item = item_model.find_one(item_filter)
return item
示例6: on_created
def on_created(self, docs):
for doc in docs:
push_notification('item:comment', item=str(doc.get('item')))
mentioned_users = doc.get('mentioned_users', {}).values()
add_activity('', type='comment', item=str(doc.get('item')),
comment=doc.get('text'), comment_id=str(doc.get('_id')),
notify=mentioned_users)
示例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.')
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):
task = archived_doc.get('task', {})
push_notification(
'content:update',
duplicated=1,
item=str(new_guid),
desk=str(task.get('desk', '')),
stage=str(task.get('stage', ''))
)
return guid_of_duplicated_items
示例8: add_activity
def add_activity(activity_name, msg, resource=None, item=None, notify=None, notify_desks=None,
can_push_notification=True, **data):
"""
Adds an activity into activity log.
This will became part of current user activity log.
If there is someone set to be notified it will make it into his notifications box.
:param activity_name: Name of the activity
:type activity_name: str
:param msg: Message to be recorded in the activity log
:type msg: str
:param resource: resource name generating this activity
:type resource: str
:param item: article instance, if the activity is being recorded against an article, default None
:type item: dict
:param notify: user identifiers against whom the activity should be recorded, default None
:type notify: list
:param notify_desks: desk identifiers if someone mentions Desk Name in comments widget, default None
:type notify_desks: list
:param can_push_notification: flag indicating if a notification should be pushed via WebSocket, default True
:type can_push_notification: bool
:param data: kwargs
:type data: dict
:return: activity object
:rtype: dict
"""
activity = {
'name': activity_name,
'message': msg,
'data': data,
'resource': resource
}
user = getattr(g, 'user', None)
if user:
activity['user'] = user.get('_id')
activity['user_name'] = user.get('display_name', user.get('username'))
activity['recipients'] = []
if notify:
activity['recipients'] = [{'user_id': ObjectId(_id), 'read': False} for _id in notify]
if notify_desks:
activity['recipients'].extend([{'desk_id': ObjectId(_id), 'read': False} for _id in notify_desks])
if item:
activity['item'] = str(item.get('guid', item.get('_id')))
activity['item_slugline'] = item.get('slugline', item.get('headline')) or item.get('unique_name')
if item.get('task') and item['task'].get('desk'):
activity['desk'] = ObjectId(item['task']['desk'])
get_resource_service(ActivityResource.endpoint_name).post([activity])
if can_push_notification:
push_notification(ActivityResource.endpoint_name, _dest=activity['recipients'], activity=activity)
return activity
示例9: update
def update(self, id, updates, original):
archived_item = super().find_one(req=None, _id=id)
try:
if archived_item['type'] == 'composite':
self.__publish_package_items(archived_item, updates[config.LAST_UPDATED])
# document is saved to keep the initial changes
self.backend.update(self.datasource, id, updates, original)
original.update(updates)
if archived_item['type'] != 'composite':
# queue only text items
self.queue_transmission(original)
task = self.__send_to_publish_stage(original)
if task:
updates['task'] = task
# document is saved to change the status
updates[config.CONTENT_STATE] = 'published'
item = self.backend.update(self.datasource, id, updates, original)
original.update(updates)
user = get_user()
push_notification('item:publish', item=str(item.get('_id')), user=str(user))
original.update(super().find_one(req=None, _id=id))
except KeyError as e:
raise SuperdeskApiError.badRequestError(
message="Key is missing on article to be published: {}"
.format(str(e)))
except Exception as e:
logger.error("Something bad happened while publishing %s".format(id), e)
raise SuperdeskApiError.internalError(message="Failed to publish the item: {}"
.format(str(e)))
示例10: on_created
def on_created(self, docs):
"""
Send notification to clients that new contact(s) have been created
:param docs:
:return:
"""
push_notification('contacts:create', _id=[doc.get(config.ID_FIELD) for doc in docs])
示例11: on_deleted
def on_deleted(self, doc):
"""
Send a notification to clients that a contact has been deleted
:param doc:
:return:
"""
push_notification('contacts:deleted', _id=[doc.get(config.ID_FIELD)])
示例12: on_updated
def on_updated(self, updates, original):
updated = copy(original)
updated.update(updates)
if self._stage_changed(updates, original):
insert_into_versions(doc=updated)
new_task = updates.get("task", {})
old_task = original.get("task", {})
if new_task.get("stage") != old_task.get("stage"):
push_notification(
"task:stage",
new_stage=str(new_task.get("stage", "")),
old_stage=str(old_task.get("stage", "")),
new_desk=str(new_task.get("desk", "")),
old_desk=str(old_task.get("desk", "")),
)
else:
push_notification(self.datasource, updated=1)
if is_assigned_to_a_desk(updated):
if self.__is_content_assigned_to_new_desk(original, updates) and not self._stage_changed(updates, original):
insert_into_versions(doc=updated)
add_activity(
ACTIVITY_UPDATE,
"updated task {{ subject }} for item {{ type }}",
self.datasource,
item=updated,
subject=get_subject(updated),
type=updated["type"],
)
示例13: add_activity
def add_activity(activity_name, msg, resource=None, item=None, notify=None, **data):
"""Add an activity into activity log.
This will became part of current user activity log.
If there is someone set to be notified it will make it into his notifications box.
"""
activity = {"name": activity_name, "message": msg, "data": data, "resource": resource}
user = getattr(g, "user", None)
if user:
activity["user"] = user.get("_id")
if notify:
activity["read"] = {str(_id): 0 for _id in notify}
else:
activity["read"] = {}
if item:
activity["item"] = str(item.get("guid", item.get("_id")))
if item.get("task") and item["task"].get("desk"):
activity["desk"] = ObjectId(item["task"]["desk"])
superdesk.get_resource_service(ActivityResource.endpoint_name).post([activity])
push_notification(ActivityResource.endpoint_name, _dest=activity["read"])
示例14: 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
示例15: create
def create(self, docs, **kwargs):
"""Toggle highlight status for given highlight and item."""
service = get_resource_service('archive')
ids = []
for doc in docs:
item = service.find_one(req=None, guid=doc['marked_item'])
if not item:
ids.append(None)
continue
ids.append(item['_id'])
highlights = item.get('highlights', [])
if not highlights:
highlights = []
if doc['highlights'] not in highlights:
highlights.append(doc['highlights'])
highlight_on = True # highlight toggled on
else:
highlights = [h for h in highlights if h != doc['highlights']]
highlight_on = False # highlight toggled off
updates = {
'highlights': highlights,
'_updated': item['_updated'],
'_etag': item['_etag']
}
service.update(item['_id'], updates, item)
push_notification(
'item:highlight',
marked=int(highlight_on),
item_id=item['_id'],
highlight_id=str(doc['highlights']))
return ids