def anno_merge(self, request): """ Exposes an API endpoint to merge(update only the specified properties) an anno. """ user = auth_user(self.request_state.headers) if request.id is None: raise endpoints.BadRequestException('id field is required.') anno = Anno.get_by_id(request.id) if anno is None: raise endpoints.NotFoundException('No anno entity with the id "%s" exists.' % request.id) anno.merge_from_message(request, user) # set last update time & activity anno.last_update_time = datetime.datetime.now() anno.last_activity = 'anno' anno.put() # update search document. put_search_document(anno.generate_search_document(), SearchIndexName.ANNO) # send notifications ActivityPushNotifications.send_push_notification(first_user=user, anno=anno, action_type=AnnoActionType.EDITED) # update last_read of UserAnnoState from model.userannostate import UserAnnoState UserAnnoState.update_last_read(user=user, anno=anno) return anno.to_response_message(user)
def anno_insert(self, request): """ Exposes an API endpoint to insert an anno for the current user. if current user doesn't exist, the user will be created first. """ user = auth_user(self.request_state.headers) # checking if same anno exists exist_anno = Anno.is_anno_exists(user, request) if exist_anno is not None: raise endpoints.BadRequestException("Duplicate anno(%s) already exists." % exist_anno.key.id()) entity = Anno.insert_anno(request, user) # find all hashtags tags = extract_tags_from_text(entity.anno_text.lower()) for tag, count in tags.iteritems(): # Write the cumulative amount per tag Tag.add_tag_total(tag, total=count) # index this document. strange exception here. put_search_document(entity.generate_search_document(), SearchIndexName.ANNO) # send push notifications ActivityPushNotifications.send_push_notification(first_user=user, anno=entity, action_type=AnnoActionType.CREATED) return entity.to_response_message(user)
def followup_insert(self, request): """ Exposes and API endpoint to insert a follow up for the current user. """ user = auth_user(self.request_state.headers) anno = Anno.get_by_id(request.anno_id) if anno is None: raise endpoints.NotFoundException('No anno entity with the id "%s" exists.' % request.id) followup = FollowUp() followup.anno_key = anno.key followup.creator = user.key followup.comment = request.comment followup.tagged_users = request.tagged_users if request.created is not None: followup.created = request.created followup.put() anno.followup_count += 1 anno.last_update_time = datetime.datetime.now() anno.last_activity = 'follwup' anno.last_update_type = 'create' anno.put() # update user anno state UserAnnoState.insert(user=user, anno=anno, type=AnnoActionType.COMMENTED) for tagged_user_id in followup.tagged_users: tagged_user = User.get_by_id(int(tagged_user_id)) if tagged_user: UserAnnoState.insert(user=tagged_user, anno=anno, type=AnnoActionType.TAGGEDUSER) # update search document put_search_document(anno.generate_search_document(), SearchIndexName.ANNO) put_search_document(followup.generate_search_document(), SearchIndexName.FOLLOWUP) # find all hashtags tags = extract_tags_from_text(followup.comment.lower()) for tag, count in tags.iteritems(): # Write the cumulative amount per tag Tag.add_tag_total(tag, total=count) # send notifications ActivityPushNotifications.send_push_notification(first_user=user, anno=anno, action_type=AnnoActionType.COMMENTED, comment=request.comment) return followup.to_message(request.team_key)
def anno_delete(self, request): """ Exposes an API endpoint to delete an existing anno. """ user = auth_user(self.request_state.headers) if request.id is None: raise endpoints.BadRequestException('id field is required.') anno = Anno.get_by_id(request.id) if anno is None: raise endpoints.NotFoundException('No anno entity with the id "%s" exists.' % request.id) # send notifications ActivityPushNotifications.send_push_notification(first_user=user, anno=anno, action_type=AnnoActionType.DELETED) Anno.delete(anno) return message_types.VoidMessage()