python类REST_FRAMEWORK的实例源码

models.py 文件源码 项目:valhalla 作者: LCOGT 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def api_quota(self):
        '''Get's the amount of requests this user has made in the last 24
        hours as well as the maximum allowed by DRF's throttling framework'''
        hits = cache.get('throttle_user_{0}'.format(self.user.id))
        used = len(hits) if hits else 0
        allowed = settings.REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['user']
        return {'used': used, 'allowed': allowed}
adapters.py 文件源码 项目:drf-schema-adapter 作者: drf-forms 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def get_metadata_from_viewset(self, viewset):

        if isinstance(viewset, dict):
            output = viewset
        else:
            MetadataClass = import_string(django_settings.REST_FRAMEWORK['DEFAULT_METADATA_CLASS'])
            output = MetadataClass().determine_metadata(None, viewset)

        return output
adapters.py 文件源码 项目:drf-schema-adapter 作者: drf-forms 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def rebuild_index(self):
        MetadataClass = import_string(django_settings.REST_FRAMEWORK['DEFAULT_METADATA_CLASS'])
        context = {}
        directory = os.path.join(django_settings.BASE_DIR, settings.FRONT_APPLICATION_PATH,
                                 'app', 'data')
        context['items'] = self.walk_dir(directory, True)
        context['root_metadata'] = self.render(
            MetadataClass().determine_metadata(None, 'APIRootView')
        )
        self.write_file(context, directory, 'index.js', self.index_template_name, True)
utils.py 文件源码 项目:EvalAI 作者: Cloud-CV 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def paginated_queryset(queryset, request, pagination_class=PageNumberPagination()):
    '''
        Return a paginated result for a queryset
    '''
    paginator = pagination_class
    paginator.page_size = settings.REST_FRAMEWORK['PAGE_SIZE']
    result_page = paginator.paginate_queryset(queryset, request)
    return (paginator, result_page)


问题


面经


文章

微信
公众号

扫码关注公众号