Beispiel #1
0
# -*- coding: utf-8 -*-
from rest_framework import VERSION


VERSION = [int(i) for i in VERSION.split('.')]

IS_DRF_3 = VERSION >= [3, 0, 0]
Beispiel #2
0
from rest_framework import VERSION as rest_framework_version


REST_FRAMEWORK_VERSIONS = [
    '2.1',
    '2.2',
    '2.3',
    '2.4',
    '3.0',
    '3.1',
    '3.2',
    '3.3',
    '3.4',
    '3.5',
    '3.6',
    '3.7',
]


VERSION = '.'.join(rest_framework_version.split('.')[:2])
EXACT_VERSION = rest_framework_version
BASE_URL = 'http://www.cdrf.co'
Beispiel #3
0
from rest_framework import VERSION as rest_framework_version


REST_FRAMEWORK_VERSIONS = [
    '2.1',
    '2.2',
    '2.3',
    '2.4',
    '3.0',
    '3.1',
    '3.2',
]


VERSION = '.'.join(rest_framework_version.split('.')[:2])
EXACT_VERSION = rest_framework_version
BASE_URL = 'http://www.cdrf.co'
Beispiel #4
0
 def test(self):
     expected = tuple(map(int, VERSION.split('.')))
     self.assertEqual(get_rest_framework_version(), expected)
Beispiel #5
0
from rest_framework import VERSION

version = tuple(map(int, VERSION.split(".")))

if version[:2] >= (3, 10):
    from rest_framework.schemas.coreapi import is_custom_action  # noqa
else:
    from rest_framework.schemas.generators import is_custom_action  # noqa
Beispiel #6
0
# coding=utf8
# -*- coding: utf8 -*-
# vim: set fileencoding=utf8 :

from __future__ import unicode_literals
from django.conf import settings
from rest_framework import VERSION, serializers
from rest_framework.response import Response
from rest_messaging.pagination import MessagePagination

DRFVLIST = [int(x) for x in VERSION.split(".")]


def compat_serializer_method_field(method_name=None):
    """ method_name changed in DRF > 3. See http://www.django-rest-framework.org/topics/3.0-announcement/#optional-argument-to-serializermethodfield. """
    if DRFVLIST[0] >= 3:
        return serializers.SerializerMethodField()
    else:
        return serializers.SerializerMethodField(method_name=method_name)


def compat_serializer_check_is_valid(serializer):
    """ http://www.django-rest-framework.org/topics/3.0-announcement/#using-is_validraise_exceptiontrue """
    if DRFVLIST[0] >= 3:
        serializer.is_valid(raise_exception=True)
    else:
        if not serializer.is_valid():
            serializers.ValidationError(
                'The serializer raises a validation error')

Beispiel #7
0
from rest_framework.routers import DefaultRouter
from rest_framework import VERSION
from .views import FobiFormEntryViewSet

__title__ = 'fobi.contrib.apps.drf_integration.urls'
__author__ = 'Artur Barseghyan <*****@*****.**>'
__copyright__ = '2014-2019 Artur Barseghyan'
__license__ = 'GPL 2.0/LGPL 2.1'
__all__ = (
    'urlpatterns',
    'fobi_router',
)

DRF_VERSION = [int(_v) for _v in VERSION.split('.')]
basename = 'basename'
if DRF_VERSION[:2] < [3, 10]:
    basename = 'base_name'

router_kwargs = {basename: 'fobi_form_entry'}

fobi_router = DefaultRouter()
fobi_router.register(r'fobi-form-entry', FobiFormEntryViewSet, **router_kwargs)
urlpatterns = fobi_router.urls
import pytest
from django.test import RequestFactory, override_settings
from rest_condition import And, Not, Or
from rest_framework import VERSION as DRFVERSION
from rest_framework.authentication import BasicAuthentication, SessionAuthentication
from rest_framework.permissions import (AllowAny, DjangoModelPermissions,
                                        IsAdminUser, IsAuthenticated)
from rest_framework.request import Request

from rest_framework_json_api.optional import OAuth2Authentication, TokenMatchesOASRequirements

from example import views

drf_version = tuple(int(x) for x in DRFVERSION.split('.'))

if drf_version >= (3, 10):
    from rest_framework_json_api.schemas.openapi import AutoSchema, SchemaGenerator


def create_request(path):
    factory = RequestFactory()
    request = Request(factory.get(path))
    return request


def create_view_with_kw(view_cls, method, request, initkwargs):
    generator = SchemaGenerator()
    view = generator.create_view(view_cls.as_view(initkwargs), method, request)
    return view

# coding=utf8
# -*- coding: utf8 -*-
# vim: set fileencoding=utf8 :

from __future__ import unicode_literals
from django.conf import settings
from rest_framework import VERSION, serializers
from rest_framework.response import Response
from rest_messaging.pagination import MessagePagination


DRFVLIST = [int(x) for x in VERSION.split(".")]


def compat_serializer_method_field(method_name=None):
    """ method_name changed in DRF > 3. See http://www.django-rest-framework.org/topics/3.0-announcement/#optional-argument-to-serializermethodfield. """
    if DRFVLIST[0] >= 3:
        return serializers.SerializerMethodField()
    else:
        return serializers.SerializerMethodField(method_name=method_name)


def compat_serializer_check_is_valid(serializer):
    """ http://www.django-rest-framework.org/topics/3.0-announcement/#using-is_validraise_exceptiontrue """
    if DRFVLIST[0] >= 3:
        serializer.is_valid(raise_exception=True)
    else:
        if not serializer.is_valid():
            serializers.ValidationError('The serializer raises a validation error')