Skip to content

Commit 1638c4b

Browse files
committed
Moved Hyperlink class to utils.py
1 parent ea54f11 commit 1638c4b

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

rest_framework_json_api/utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,21 @@ def extract_included(fields, resource, resource_instance):
395395
)
396396

397397
return format_keys(included_data)
398+
399+
400+
class Hyperlink(six.text_type):
401+
"""
402+
A string like object that additionally has an associated name.
403+
We use this for hyperlinked URLs that may render as a named link
404+
in some contexts, or render as a plain URL in others.
405+
406+
Comes from Django REST framework 3.2
407+
https://github.com/tomchristie/django-rest-framework
408+
"""
409+
410+
def __new__(self, url, name):
411+
ret = six.text_type.__new__(self, url)
412+
ret.name = name
413+
return ret
414+
415+
is_hyperlink = True

rest_framework_json_api/views.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
from django.db.models import Model
44
from django.db.models.query import QuerySet
55
from django.db.models.manager import Manager
6-
from django.utils import six
76
from rest_framework import generics
87
from rest_framework.response import Response
98
from rest_framework.exceptions import NotFound, MethodNotAllowed
109
from rest_framework.reverse import reverse
1110

1211
from rest_framework_json_api.exceptions import Conflict
1312
from rest_framework_json_api.serializers import ResourceIdentifierObjectSerializer
14-
from rest_framework_json_api.utils import format_relation_name, get_resource_type_from_instance, OrderedDict
13+
from rest_framework_json_api.utils import format_relation_name, get_resource_type_from_instance, OrderedDict, Hyperlink
1514

1615

1716
class RelationshipView(generics.GenericAPIView):
@@ -34,23 +33,6 @@ def get_url(self, name, view_name, kwargs, request):
3433
attributes are not configured to correctly match the URL conf.
3534
"""
3635

37-
class Hyperlink(six.text_type):
38-
"""
39-
A string like object that additionally has an associated name.
40-
We use this for hyperlinked URLs that may render as a named link
41-
in some contexts, or render as a plain URL in others.
42-
43-
Comes from Django REST framework 3.2
44-
https://github.com/tomchristie/django-rest-framework
45-
"""
46-
47-
def __new__(self, url, name):
48-
ret = six.text_type.__new__(self, url)
49-
ret.name = name
50-
return ret
51-
52-
is_hyperlink = True
53-
5436
# Return None if the view name is not supplied
5537
if not view_name:
5638
return None

0 commit comments

Comments
 (0)