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 tag_popular(self, request): ''' Get the most used tags in the system, limited to a number ''' tags = Tag.get_popular_tags(limit=request.limit) tags = [TagMessage(text=t.text, total=t.total) for t in tags] return TagPopularMessage(tags=tags)
def tag_search(self, request): ''' Search for tags in the system based on the Text Currently the Search Index is NOT POPULATED ''' tags = Tag.search_tag(request.text) tags = [TagMessage(text=t.text, total=t.total) for t in tags] return TagPopularMessage(tags=tags)
def create_tags(text): tags = extract_tags_from_text(text.lower()) for tag, count in tags.iteritems(): Tag.add_tag_total(text=tag, total=count)