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 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 search document put_search_document(anno.generate_search_document()) return followup.to_message()
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)