コード例 #1
0
ファイル: followup_api.py プロジェクト: ignitesol/tasks
    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()
コード例 #2
0
ファイル: followup_api.py プロジェクト: usersource/anno
    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)
コード例 #3
0
ファイル: anno.py プロジェクト: usersource/anno
    def to_dashboard_response_message(self, user):
        user_message = None
        if self.creator is not None:
            user_info = self.creator.get()
            user_message = UserMessage(display_name=user_info.display_name,
                                       user_email=user_info.user_email,
                                       image_url=user_info.image_url)

        app = self.app.get() if self.app else None
        app_name = app.name if app else self.app_name
        app_version = app.version if app else self.app_version

        # set anno association with followups
        from model.follow_up import FollowUp
        followups = FollowUp.find_by_anno(self, True)
        followup_messages = [ entity.to_message(auth_user=user) for entity in followups ]

        from model.vote import Vote
        is_my_vote = Vote.is_belongs_user(self, user)

        from model.flag import Flag
        is_my_flag = Flag.is_belongs_user(self, user)

        mentions = []
        for tagged_user in self.tagged_users:
            tagged_user_info = User.get_by_id(int(tagged_user))
            is_auth_user = tagged_user_info.user_email == user.user_email
            mentions.append(AnnoMentionsResponseMessage(id=tagged_user_info.key.id(),
                                                        display_name=tagged_user_info.display_name,
                                                        user_email=tagged_user_info.user_email,
                                                        image_url=tagged_user_info.image_url,
                                                        is_auth_user=is_auth_user))

        team_notes_metadata = AnnoTeamNotesMetadataMessage(tags=parseTeamNotesForHashtags(self.team_notes),
                                                           mentions=mentions)

        engaged_users = Anno.getEngagedUsers(anno_id=self.key.id(), auth_user=user, include_auth_user=True)

        anno_message = AnnoDashboardResponseMessage(id=self.key.id(),
                                                    anno_text=self.anno_text,
                                                    device_model=self.device_model,
                                                    app_name=app_name,
                                                    app_version=app_version,
                                                    os_name=self.os_name,
                                                    os_version=self.os_version,
                                                    created=self.created,
                                                    creator=user_message,
                                                    draw_elements=self.draw_elements,
                                                    vote_count=self.vote_count,
                                                    flag_count=self.flag_count,
                                                    followup_count=self.followup_count,
                                                    followup_list=followup_messages,
                                                    is_my_vote=is_my_vote,
                                                    is_my_flag=is_my_flag,
                                                    team_notes_metadata=team_notes_metadata,
                                                    team_notes=self.team_notes,
                                                    engaged_users=engaged_users,
                                                    archived=self.archived)

        return anno_message
コード例 #4
0
ファイル: followup_api.py プロジェクト: usersource/anno
    def followup_list(self, request):
        """
        Exposes an API endpoint to retrieve a list of follow up.
        """
        user = auth_user(self.request_state.headers)
        limit = 10
        if request.limit is not None:
            limit = request.limit

        curs = None
        if request.cursor is not None:
            try:
                curs = Cursor(urlsafe=request.cursor)
            except BadValueError:
                raise endpoints.BadRequestException('Invalid cursor %s.' % request.cursor)

        query = FollowUp.query().order(-FollowUp.created)
        if curs is not None:
            followups, next_curs, more = query.fetch_page(limit, start_cursor=curs)
        else:
            followups, next_curs, more = query.fetch_page(limit)

        items = [entity.to_message() for entity in followups]
        if more:
            return FollowupListMessage(followup_list=items, cursor=next_curs.urlsafe(), has_more=more)
        else:
            return FollowupListMessage(followup_list=items, has_more=more)
コード例 #5
0
ファイル: anno_api.py プロジェクト: usersource/anno
    def anno_get(self, request):
        """
        Exposes an API endpoint to get an anno detail by the specified id.
        """
        try:
            user = auth_user(self.request_state.headers)
        except Exception:
            user = None

        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)

        # set anno basic properties
        anno_resp_message = anno.to_response_message(user, list_message=False)

        # set anno association with followups
        followups = FollowUp.find_by_anno(anno)
        followup_messages = [ entity.to_message(team_key=request.team_key) for entity in followups ]
        anno_resp_message.followup_list = followup_messages

        # set anno association with votes/flags
        # if current user exists, then fetch vote/flag.
        if user is not None:
            anno_resp_message.is_my_vote = Vote.is_belongs_user(anno, user)
            anno_resp_message.is_my_flag = Flag.is_belongs_user(anno, user)

            # update last_read of UserAnnoState
            UserAnnoState.update_last_read(user=user, anno=anno)

        return anno_resp_message
コード例 #6
0
ファイル: anno_api.py プロジェクト: topcircler/anno
    def anno_my_stuff(self, request):
        """
        Exposes an API endpoint to return all my anno list.
        """
        user = auth_user(self.request_state.headers)
        anno_list = Anno.query_anno_by_author(user)
        vote_list = Vote.query_vote_by_author(user)
        for vote in vote_list:
            anno = Anno.get_by_id(vote.anno_key.id())
            if anno is not None:
                anno_list.append(anno)
        flag_list = Flag.query_flag_by_author(user)
        for flag in flag_list:
            anno = Anno.get_by_id(flag.anno_key.id())
            if anno is not None:
                anno_list.append(anno)
        followup_list = FollowUp.query_followup_by_author(user)
        for followup in followup_list:
            anno = Anno.get_by_id(followup.anno_key.id())
            if anno is not None:
                anno_list.append(anno)
        anno_set = list(set(anno_list))

        anno_message_list = []
        for anno in anno_set:
            anno_message_list.append(anno.to_response_message())
        return AnnoListMessage(anno_list=anno_message_list)
コード例 #7
0
def update_followup_indices(cursor=None):
    followup_list, cursor, more = FollowUp.query().fetch_page(BATCH_SIZE, start_cursor=cursor)

    for followup in followup_list:
#         regenerate_index(followup, SearchIndexName.FOLLOWUP)
        create_tags(followup.comment)

    if more:
        update_followup_indices(cursor=cursor)
コード例 #8
0
ファイル: followup_api.py プロジェクト: usersource/anno
 def followup_get(self, request):
     """
     Exposes an API endpoint to get a followup.
     """
     user = auth_user(self.request_state.headers)
     if request.id is None:
         raise endpoints.BadRequestException('id field is required.')
     followup = FollowUp.get_by_id(request.id)
     if followup is None:
         raise endpoints.NotFoundException('No follow up entity with the id "%s" exists.' % request.id)
     return followup.to_message()
コード例 #9
0
ファイル: anno.py プロジェクト: usersource/anno
    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)
コード例 #10
0
ファイル: followup_api.py プロジェクト: usersource/anno
 def followup_delete(self, request):
     """
     Exposes an API endpoint to delete an existing follow up.
     """
     user = auth_user(self.request_state.headers)
     if request.id is None:
         raise endpoints.BadRequestException('id field is required.')
     followup = FollowUp.get_by_id(request.id)
     if followup is None:
         raise endpoints.NotFoundException('No follow up entity with the id "%s" exists.' % request.id)
     anno = followup.anno_key.get()
     followup.key.delete()
     anno.followup_count -= 1
     anno.put()
     return message_types.VoidMessage()
コード例 #11
0
ファイル: anno_api.py プロジェクト: usersource/anno
    def anno_search(self, request):
        """
        Exposes and API endpoint to search anno list.
        """
        user = auth_user(self.request_state.headers)

        if request.order_type is None:
            raise endpoints.BadRequestException('order_type field is required.')
        if request.order_type != 'recent' and request.order_type != 'active' and request.order_type != 'popular':
            raise endpoints.BadRequestException(
                'Invalid order_type field value, valid values are "recent", "active" and "popular"')

        app_set = None
        logging.info("only_my_apps=%s" % request.only_my_apps)
        if request.only_my_apps:
            app_set = set()
            for anno in Anno.query_anno_by_author(user):
                app_set.add(anno.app_name)
            for vote in Vote.query_vote_by_author(user):
                anno = Anno.get_by_id(vote.anno_key.id())
                if anno is not None:
                    app_set.add(anno.app_name)
            for flag in Flag.query_flag_by_author(user):
                anno = Anno.get_by_id(flag.anno_key.id())
                if anno is not None:
                    app_set.add(anno.app_name)
            for followup in FollowUp.query_followup_by_author(user):
                anno = Anno.get_by_id(followup.anno_key.id())
                if anno is not None:
                    app_set.add(anno.app_name)

        if request.order_type == 'popular':
            return Anno.query_by_popular(request.limit, request.offset,
                                         request.search_string, request.app_name, app_set, user)
        elif request.order_type == 'active':
            return Anno.query_by_active(request.limit, request.offset, request.search_string, request.app_name, app_set, user)
        else:
            return Anno.query_by_recent(request.limit, request.offset, request.search_string, request.app_name, app_set, user)