1
1
import graphene
2
+ from django .apps import apps
2
3
from django .conf import settings
3
4
from django .core .cache import InvalidCacheBackendError , caches
4
5
from easy_thumbnails .files import get_thumbnailer
9
10
cache = None
10
11
11
12
12
- class File (graphene .ObjectType ):
13
- url = graphene .String (required = True )
14
- # contentType = graphene.String()
15
- # bytes = graphene.Int()
13
+ if apps .is_installed ("baseapp_files" ):
14
+ from baseapp_files .graphql .object_types import FileObjectType
15
+ else :
16
+ class FileObjectType (graphene .ObjectType ):
17
+ url = graphene .String ()
18
+ # contentType = graphene.String()
19
+ # bytes = graphene.Int()
20
+
21
+ class Meta :
22
+ name = "File"
16
23
17
24
18
25
class ThumbnailField (graphene .Field ):
19
- def __init__ (self , type = File , ** kwargs ):
26
+ def __init__ (self , type = FileObjectType , ** kwargs ):
20
27
kwargs .update (
21
28
{
22
29
"args" : {
@@ -40,7 +47,7 @@ def built_thumbnail(instance, info, width, height, **kwargs):
40
47
cache_key = self ._get_cache_key (instance , width , height )
41
48
value_from_cache = cache .get (cache_key )
42
49
if value_from_cache :
43
- return File (url = value_from_cache )
50
+ return FileObjectType (url = value_from_cache )
44
51
45
52
thumbnailer = get_thumbnailer (instance )
46
53
url = thumbnailer .get_thumbnail ({"size" : (width , height )}).url
@@ -49,7 +56,7 @@ def built_thumbnail(instance, info, width, height, **kwargs):
49
56
if cache :
50
57
cache .set (cache_key , absolute_url , timeout = None )
51
58
52
- return File (url = absolute_url )
59
+ return FileObjectType (url = absolute_url )
53
60
54
61
return built_thumbnail
55
62
0 commit comments