def delete(cls, anno): anno_id = "%d" % anno.key.id() # deleting UserAnnoState of anno from model.userannostate import UserAnnoState UserAnnoState.delete_by_anno(anno_key=anno.key) # deleting FollowUp of anno from model.follow_up import FollowUp FollowUp.delete_by_anno(anno_key=anno.key) # deleting Vote of anno from model.vote import Vote Vote.delete_by_anno(anno_key=anno.key) # deleting Flag of anno from model.flag import Flag Flag.delete_by_anno(anno_key=anno.key) anno.key.delete() index = search.Index(name=SearchIndexName.ANNO) index.delete(anno_id)
def send_push_notification(cls, first_user, anno, action_type, comment=""): """ Send push notification for anno actions :param ndb.Model first_user: "******" datastore of user who did anno action :param ndb.Model anno: "anno" datastore :param str action_type: one of the :py:class:`.AnnoActionType` :param str comment: comment made on an anno """ # get list of device ids to which push notification to be sent notf_device = cls.get_noft_devices(first_user, anno, action_type) # create push notification message for iOS and Android devices notf_msg = cls.create_notf_msg(first_user, anno, action_type, comment) # if action is "deleted" then delete all UserAnnoState related to that anno if action_type == AnnoActionType.DELETED: UserAnnoState.delete_by_anno(anno_key=anno.key) for platform, devices in notf_device.iteritems(): message, data = notf_msg[platform] if len(devices): PushTaskQueue.add(message=message, ids=devices, typ=platform.lower(), data=data)