當前位置: 首頁>>代碼示例>>Python>>正文


Python Anno.get_by_id方法代碼示例

本文整理匯總了Python中model.anno.Anno.get_by_id方法的典型用法代碼示例。如果您正苦於以下問題:Python Anno.get_by_id方法的具體用法?Python Anno.get_by_id怎麽用?Python Anno.get_by_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在model.anno.Anno的用法示例。


在下文中一共展示了Anno.get_by_id方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: anno_my_stuff

# 需要導入模塊: from model.anno import Anno [as 別名]
# 或者: from model.anno.Anno import get_by_id [as 別名]
    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)
開發者ID:topcircler,項目名稱:anno,代碼行數:29,代碼來源:anno_api.py

示例2: flag_delete

# 需要導入模塊: from model.anno import Anno [as 別名]
# 或者: from model.anno.Anno import get_by_id [as 別名]
    def flag_delete(self, request):
        """
        Exposes an API endpoint to delete an existing flag.
        """
        user = auth_user(self.request_state.headers)
        anno = None
        if request.id is None and request.anno_id is None:
            raise endpoints.BadRequestException('id or anno_id field is required.')
        if request.id is not None:
            flag = Flag.get_by_id(request.id)
            if flag is None:
                raise endpoints.NotFoundException('No flag entity with the id "%s" exists.' % request.id)

            anno = flag.anno_key.get()
            flag.key.delete()
            anno.flag_count -= 1
            anno.put()
        elif request.anno_id is not None:
            anno = Anno.get_by_id(request.anno_id)
            for key in Flag.query(Flag.anno_key == anno.key, Flag.creator == user.key).iter(keys_only=True):
                key.delete()
                anno.flag_count -= 1
                anno.put()
        put_search_document(anno.generate_search_document(), SearchIndexName.ANNO)
        return message_types.VoidMessage()
開發者ID:usersource,項目名稱:anno,代碼行數:27,代碼來源:flag_api.py

示例3: vote_insert

# 需要導入模塊: from model.anno import Anno [as 別名]
# 或者: from model.anno.Anno import get_by_id [as 別名]
    def vote_insert(self, request):
        """
        Exposes an API endpoint to insert a vote 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)

        vote = Vote()
        vote.anno_key = anno.key
        vote.creator = user.key
        if request.created is not None:
            vote.created = request.created
        vote.put()

        anno.vote_count += 1
        anno.last_update_time = datetime.datetime.now()
        anno.last_activity = 'vote'
        anno.last_update_type = 'create'
        anno.put()

        # update user anno state
        UserAnnoState.insert(user=user, anno=anno, type=AnnoActionType.UPVOTED)

        # update vote in search document
        put_search_document(anno.generate_search_document(), SearchIndexName.ANNO)

        return vote.to_message()
開發者ID:usersource,項目名稱:anno,代碼行數:32,代碼來源:vote_api.py

示例4: anno_get

# 需要導入模塊: from model.anno import Anno [as 別名]
# 或者: from model.anno.Anno import get_by_id [as 別名]
    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
開發者ID:usersource,項目名稱:anno,代碼行數:37,代碼來源:anno_api.py

示例5: followup_insert

# 需要導入模塊: from model.anno import Anno [as 別名]
# 或者: from model.anno.Anno import get_by_id [as 別名]
    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()
開發者ID:ignitesol,項目名稱:tasks,代碼行數:28,代碼來源:followup_api.py

示例6: anno_merge

# 需要導入模塊: from model.anno import Anno [as 別名]
# 或者: from model.anno.Anno import get_by_id [as 別名]
    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)
開發者ID:usersource,項目名稱:anno,代碼行數:33,代碼來源:anno_api.py

示例7: flag_insert

# 需要導入模塊: from model.anno import Anno [as 別名]
# 或者: from model.anno.Anno import get_by_id [as 別名]
    def flag_insert(self, request):
        """
        Exposes an API endpoint to insert a flag 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.')

        flag = Flag()
        flag.anno_key = anno.key
        flag.creator = user.key
        if request.created is not None:
            flag.created = request.created
        flag.put()

        anno.flag_count += 1
        anno.last_update_time = datetime.datetime.now()
        anno.last_activity = 'flag'
        anno.last_update_type = 'create'
        anno.put()

        # update user anno state
        UserAnnoState.insert(user=user, anno=anno, type=AnnoActionType.FLAGGED)

        # update flag in search document
        put_search_document(anno.generate_search_document(), SearchIndexName.ANNO)

        return flag.to_message()
開發者ID:usersource,項目名稱:anno,代碼行數:32,代碼來源:flag_api.py

示例8: delete_by_anno

# 需要導入模塊: from model.anno import Anno [as 別名]
# 或者: from model.anno.Anno import get_by_id [as 別名]
    def delete_by_anno(cls, anno_id=None, anno_key=None):
        if anno_key is None:
            anno = Anno.get_by_id(anno_id) if anno_id else None
            anno_key = anno.key if anno else None

        if anno_key:
            userannostates = cls.query(cls.anno == anno_key).fetch()
            userannostate_key_list = [ userannostate.key for userannostate in userannostates ]
            ndb.delete_multi(userannostate_key_list)
開發者ID:usersource,項目名稱:anno,代碼行數:11,代碼來源:userannostate.py

示例9: delete_by_anno

# 需要導入模塊: from model.anno import Anno [as 別名]
# 或者: from model.anno.Anno import get_by_id [as 別名]
    def delete_by_anno(cls, anno_id=None, anno_key=None):
        if anno_key is None:
            anno = Anno.get_by_id(anno_id) if anno_id else None
            anno_key = anno.key if anno else None

        if anno_key:
            followups = cls.query(cls.anno_key == anno_key).fetch()
            followup_key_list = [ followup.key for followup in followups ]
            ndb.delete_multi(followup_key_list)
開發者ID:usersource,項目名稱:anno,代碼行數:11,代碼來源:follow_up.py

示例10: delete_by_anno

# 需要導入模塊: from model.anno import Anno [as 別名]
# 或者: from model.anno.Anno import get_by_id [as 別名]
    def delete_by_anno(cls, anno_id=None, anno_key=None):
        if anno_key is None:
            anno = Anno.get_by_id(anno_id) if anno_id else None
            anno_key = anno.key if anno else None

        if anno_key:
            flags = cls.query(cls.anno_key == anno_key).fetch()
            flag_key_list = [ flag.key for flag in flags ]
            ndb.delete_multi(flag_key_list)
開發者ID:usersource,項目名稱:anno,代碼行數:11,代碼來源:flag.py

示例11: delete_by_anno

# 需要導入模塊: from model.anno import Anno [as 別名]
# 或者: from model.anno.Anno import get_by_id [as 別名]
    def delete_by_anno(cls, anno_id=None, anno_key=None):
        if anno_key is None:
            anno = Anno.get_by_id(anno_id) if anno_id else None
            anno_key = anno.key if anno else None

        if anno_key:
            votes = cls.query(cls.anno_key == anno_key).fetch()
            vote_key_list = [ vote.key for vote in votes ]
            ndb.delete_multi(vote_key_list)
開發者ID:usersource,項目名稱:anno,代碼行數:11,代碼來源:vote.py

示例12: anno_get

# 需要導入模塊: from model.anno import Anno [as 別名]
# 或者: from model.anno.Anno import get_by_id [as 別名]
 def anno_get(self, request):
     """
     Exposes an API endpoint to get an anno detail by the specified id.
     """
     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)
     return anno.to_response_message()
開發者ID:ignitesol,項目名稱:tasks,代碼行數:12,代碼來源:anno_api.py

示例13: update_notify

# 需要導入模塊: from model.anno import Anno [as 別名]
# 或者: from model.anno.Anno import get_by_id [as 別名]
    def update_notify(self, request):
        user = auth_user(self.request_state.headers)
        anno = Anno.get_by_id(request.anno_id)
        entity = UserAnnoState.get(user=user, anno=anno)

        if entity:
            entity.notify = request.notify
            entity.put()

        return message_types.VoidMessage()
開發者ID:usersource,項目名稱:anno,代碼行數:12,代碼來源:userannostate_api.py

示例14: anno_delete

# 需要導入模塊: from model.anno import Anno [as 別名]
# 或者: from model.anno.Anno import get_by_id [as 別名]
 def anno_delete(self, request):
     """
     Exposes an API endpoint to delete an existing anno.
     """
     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.key.delete()
     return message_types.VoidMessage()
開發者ID:ignitesol,項目名稱:tasks,代碼行數:13,代碼來源:anno_api.py

示例15: get

# 需要導入模塊: from model.anno import Anno [as 別名]
# 或者: from model.anno.Anno import get_by_id [as 別名]
    def get(self):
        """
        handle request for screenshot.

        sample: https://usersource-anno.appspot.com/screenshot?anno_id=5644572721938432
        """
        anno_id = self.request.get('anno_id')
        if anno_id is None or anno_id == '':
            self.response.set_status(400)
            self.response.out.write(u'anno_id parameter is required.')
        else:
            # is this an if-modified request
            if_modified_since =  self.request.headers.get('If-Modified-Since')
            if_none_match =  self.request.headers.get('If-None-Match')

            # Reply with a 304
            # we could guess that if the Anno image was never modified
            # we do not even have to read the database and return a 304
            # if (if_modified_since is not None and if_modified_since == anno.created.isoformat()) or \
            #     (if_none_match is not None and if_none_match == anno.created.isoformat()):

            # We trust the request blindly to save to DB read time
            if if_modified_since or if_none_match:
                self.response.status = 304
                return

            anno = Anno.get_by_id(long(anno_id))
            if anno is None:
                self.response.set_status(400)
                self.response.out.write('No anno entity with the id "%s" exists.' % anno_id)
            elif anno.image is None:
                self.response.set_status(404)
                self.response.out.write("This anno doesn't contain screenshot")
            else:

                # Header identifier
                head = list(anno.image[:32])

                # Cache control and ETag support
                self.response.headers['Cache-Control'] = 'max-age=%d, public'%self.MAX_AGE
                self.response.headers['Last-Modified'] = anno.created.isoformat()
                self.response.headers['ETag'] = anno.created.isoformat()

                if self.HEADER_PNG == head[:len(self.HEADER_PNG)]:
                    # PNG Header
                    self.response.headers['Content-Type'] = 'image/png'
                elif self.HEADER_JPG == head[:len(self.HEADER_JPG)]:
                    # JPEG Header
                    self.response.headers['Content-Type'] = 'image/jpeg'
                else:
                    # Defaulting to BMP for now
                    self.response.headers['Content-Type'] = 'image/bmp'

                self.response.out.write(anno.image)
開發者ID:usersource,項目名稱:anno,代碼行數:56,代碼來源:image_handler.py


注:本文中的model.anno.Anno.get_by_id方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。