88from graphene_django .types import DjangoObjectType
99from graphene_django .filter import DjangoFilterConnectionField
1010from graphene_django .converter import convert_django_field
11- # from sorl.thumbnail import get_thumbnail
11+ from sorl .thumbnail import get_thumbnail
1212from gsmap .models import Municipality , Snapshot , SnapshotPermission , Workspace
1313
1414
@@ -45,15 +45,20 @@ class SnapshotNode(DjangoObjectType):
4545 class Meta :
4646 model = Snapshot
4747 fields = [
48- 'is_showcase' , 'title' , 'topic' , 'data' , 'municipality' , 'predecessor'
48+ 'is_showcase' , 'title' , 'topic' , 'data' , 'municipality' ,
49+ 'predecessor'
50+ ]
51+ filter_fields = [
52+ 'municipality__id' , 'municipality__canton' , 'is_showcase'
4953 ]
50- filter_fields = ['municipality__id' , 'municipality__canton' , 'is_showcase' ]
5154 interfaces = [graphene .relay .Node ]
5255
5356 data = generic .GenericScalar (source = 'data' )
5457 pk = graphene .String (source = 'id' )
5558 thumbnail = graphene .String ()
5659 screenshot = graphene .String ()
60+ screenshot_facebook = graphene .String ()
61+ screenshot_twitter = graphene .String ()
5762
5863 @classmethod
5964 def get_queryset (cls , queryset , info ):
@@ -65,6 +70,20 @@ def resolve_screenshot(self, info):
6570 def resolve_thumbnail (self , info ):
6671 return self .thumbnail
6772
73+ def resolve_screenshot_facebook (self , info ):
74+ screenshot = get_thumbnail (self .screenshot ,
75+ '1200x630' ,
76+ crop = 'bottom' ,
77+ format = 'PNG' )
78+ return screenshot
79+
80+ def resolve_screenshot_twitter (self , info ):
81+ screenshot = get_thumbnail (self .screenshot ,
82+ '1200x600' ,
83+ crop = 'bottom' ,
84+ format = 'PNG' )
85+ return screenshot
86+
6887
6988class MunicipalityNode (DjangoObjectType ):
7089 class Meta :
@@ -83,7 +102,8 @@ class Meta:
83102 perimeter_bounds = graphene .List (graphene .Float )
84103
85104 def resolve_snapshots (self , info ):
86- return Snapshot .objects .filter (Q_SNAPSHOT_ONLY_PUBLIC & Q (municipality__id = self .pk ))
105+ return Snapshot .objects .filter (Q_SNAPSHOT_ONLY_PUBLIC
106+ & Q (municipality__id = self .pk ))
87107
88108 def resolve_perimeter_centroid (self , info ):
89109 return self .perimeter .centroid
@@ -95,9 +115,7 @@ def resolve_perimeter_bounds(self, info):
95115class WorkspaceNode (DjangoObjectType ):
96116 class Meta :
97117 model = Workspace
98- fields = [
99- 'title' , 'description'
100- ]
118+ fields = ['title' , 'description' ]
101119 interfaces = [graphene .relay .Node ]
102120
103121 pk = graphene .String (source = 'id' )
@@ -113,7 +131,6 @@ class Query(object):
113131
114132 snapshot = graphene .relay .Node .Field (SnapshotNode )
115133 snapshots = DjangoFilterConnectionField (
116- SnapshotNode , filterset_class = SnapshotOnlyPublicFilter
117- )
134+ SnapshotNode , filterset_class = SnapshotOnlyPublicFilter )
118135
119136 workspace = graphene .relay .Node .Field (WorkspaceNode )
0 commit comments