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


Python Need.api_response方法代碼示例

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


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

示例1: put

# 需要導入模塊: from app.needs import Need [as 別名]
# 或者: from app.needs.Need import api_response [as 別名]
    def put(self, key):
        """
        The PUT HTTP method
        """
        obj = self.model.get_by_id(key)
        if not obj:
            return create_api_response(404, "{resource} {key} not found".format(
                resource=self.name, key=key))

        need = Need('get')
        if not obj.can(session['user'], need, obj):
            return need.api_response()

        need = Need('put')
        if not obj.can(session['user'], need, obj):
            return need.api_response()

        blank_val = object()
        changed = False
        for key, value in self.parse_args(False).iteritems():
            old_val = getattr(obj, key, blank_val)
            if old_val == blank_val:
                return create_api_response(
                    400, "{} is not a valid field.".format(key))

            setattr(obj, key, value)
            changed = True

        if changed:
            obj.put()

        return create_api_response(200, "", obj)
開發者ID:sheep0x,項目名稱:ok,代碼行數:34,代碼來源:api.py

示例2: index

# 需要導入模塊: from app.needs import Need [as 別名]
# 或者: from app.needs.Need import api_response [as 別名]
    def index(self):
        """
        Index HTTP method. Should be called from GET when no key is provided.

        Processes cursor and num_page URL arguments for pagination support.
        """
        query = self.model.query()
        need = Need('index')

        result = self.model.can(session['user'], need, query=query)
        if not result:
            return need.api_response()

        args = self.parse_args(True)
        query = filter_query(result, args, self.model)
        created_prop = getattr(self.model, 'created', None)
        if not query.orders and created_prop:
            logging.info("Adding default ordering by creation time.")
            query = query.order(-created_prop)

        page = int(request.args.get('page', 1))
        num_page = request.args.get('num_page', None)
        query_results = paginate(query, page, num_page)

        add_statistics = request.args.get('stats', False)
        if add_statistics:
            query_results['statistics'] = self.statistics()
        return create_api_response(200, "success", query_results)
開發者ID:sheep0x,項目名稱:ok,代碼行數:30,代碼來源:api.py

示例3: delete

# 需要導入模塊: from app.needs import Need [as 別名]
# 或者: from app.needs.Need import api_response [as 別名]
    def delete(self, user_id):
        """
        The DELETE HTTP method
        """
        ent = self.model.query.get(user_id)

        need = Need('delete')
        if not self.model.can_static(session['user'], need):
            return need.api_response()

        ent.key.delete()
        return create_api_response(200, "success", {})
開發者ID:sheep0x,項目名稱:ok,代碼行數:14,代碼來源:api.py

示例4: get

# 需要導入模塊: from app.needs import Need [as 別名]
# 或者: from app.needs.Need import api_response [as 別名]
    def get(self, key):
        """
        The GET HTTP method
        """
        obj = self.model.get_by_id(key)
        if not obj:
            return create_api_response(404, "{resource} {key} not found".format(
                resource=self.name, key=key))

        need = Need('get')
        if not obj.can(session['user'], need, obj):
            return need.api_response()

        return create_api_response(200, "", obj)
開發者ID:sheep0x,項目名稱:ok,代碼行數:16,代碼來源:api.py

示例5: post

# 需要導入模塊: from app.needs import Need [as 別名]
# 或者: from app.needs.Need import api_response [as 別名]
    def post(self):
        """
        The POST HTTP method
        """
        data = self.parse_args(False)

        need = Need('create')
        if not self.model.can(session['user'], need):
            return need.api_response()

        entity, error_response = self.new_entity(data)

        if not error_response:
            return create_api_response(200, "success", {
                'key': entity.key.id()
            })
        else:
            return error_response
開發者ID:sheep0x,項目名稱:ok,代碼行數:20,代碼來源:api.py

示例6: download

# 需要導入模塊: from app.needs import Need [as 別名]
# 或者: from app.needs.Need import api_response [as 別名]
    def download(self, key):
        """
        Allows you to download a submission.
        """
        obj = self.model.get_by_id(key)
        if not obj:
            return create_api_response(404, "{resource} {key} not found".format(
                resource=self.name, key=key))

        need = Need('get')
        if not obj.can(session['user'], need, obj):
            return need.api_response()

        if 'file_contents' not in obj.messages:
            return create_api_response(400,
                "Submissions has no contents to download.")

        response = make_response(create_zip(obj.messages['file_contents']))
        response.headers["Content-Disposition"] = (
            "attachment; filename=submission-%s.zip" % str(obj.created))
        response.headers["Content-Type"] = "application/zip"
        return response
開發者ID:sheep0x,項目名稱:ok,代碼行數:24,代碼來源:api.py


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