@@ -134,7 +134,7 @@ def __init__(self, host, meta):
134
134
self .is_dev = False
135
135
136
136
self .version = tuple (self .version [:3 ])
137
- self ._ensure_json_supported ()
137
+ self .ensure_json_supported ()
138
138
139
139
140
140
def _ensure_support (self , feature ):
@@ -151,25 +151,28 @@ def _ensure_support(self, feature):
151
151
"%s requires server version %s or higher, " \
152
152
"server is %s" % (feature ['label' ], _version_str (feature ['version' ]), _version_str (self .version ))
153
153
)
154
+ return False
155
+ else :
156
+ return True
154
157
155
158
156
- def _ensure_json_supported (self ):
159
+ def ensure_json_supported (self ):
157
160
"""Wrapper for ensure_support"""
158
- self ._ensure_support ({
161
+ return self ._ensure_support ({
159
162
'version' : (2 , 4 , 0 ),
160
163
'label' : 'JSON API'
161
164
})
162
165
163
166
def ensure_include_archived_projects (self ):
164
167
"""Wrapper for ensure_support"""
165
- self ._ensure_support ({
168
+ return self ._ensure_support ({
166
169
'version' : (5 , 3 , 14 ),
167
170
'label' : 'include_archived_projects parameter'
168
171
})
169
172
170
173
def ensure_include_template_projects (self ):
171
174
"""Wrapper for ensure_support"""
172
- self ._ensure_support ({
175
+ return self ._ensure_support ({
173
176
'version' : (6 , 0 , 0 ),
174
177
'label' : 'include_template_projects parameter'
175
178
})
@@ -514,7 +517,7 @@ def find_one(self, entity_type, filters, fields=None, order=None,
514
517
:param include_template_projects: Optional, flag to include entities
515
518
belonging to template projects. Default: False
516
519
517
- :returns: Result
520
+ :returns: dict of requested entity's fields, or None if not found.
518
521
"""
519
522
520
523
results = self .find (entity_type , filters , fields , order ,
@@ -577,22 +580,13 @@ def find(self, entity_type, filters, fields=None, order=None,
577
580
raise ShotgunError ("Deprecated: Use of filter_operator for find()"
578
581
" is not valid any more. See the documentation on find()" )
579
582
580
- if not include_archived_projects :
581
- # This defaults to True on the server (no argument is sent)
582
- # So we only need to check the server version if it is False
583
- self .server_caps .ensure_include_archived_projects ()
584
-
585
- if include_template_projects :
586
- # This defaults to False on the server (no argument is sent)
587
- # So we only need to check the server version if it is True
588
- self .server_caps .ensure_include_template_projects ()
589
-
590
-
591
583
params = self ._construct_read_parameters (entity_type ,
592
584
fields ,
593
585
filters ,
594
586
retired_only ,
595
- order ,
587
+ order )
588
+
589
+ params = self ._construct_flag_parameters (params ,
596
590
include_archived_projects ,
597
591
include_template_projects )
598
592
@@ -631,31 +625,24 @@ def find(self, entity_type, filters, fields=None, order=None,
631
625
return self ._parse_records (records )
632
626
633
627
634
-
635
628
def _construct_read_parameters (self ,
636
629
entity_type ,
637
630
fields ,
638
631
filters ,
639
632
retired_only ,
640
- order ,
641
- include_archived_projects ,
642
- include_template_projects ):
643
- params = {}
644
- params ["type" ] = entity_type
645
- params ["return_fields" ] = fields or ["id" ]
646
- params ["filters" ] = filters
647
- params ["return_only" ] = (retired_only and 'retired' ) or "active"
648
- params ["return_paging_info" ] = True
649
- params ["paging" ] = { "entities_per_page" : self .config .records_per_page ,
650
- "current_page" : 1 }
651
-
652
- if include_archived_projects is False :
653
- # Defaults to True on the server, so only pass it if it's False
654
- params ["include_archived_projects" ] = False
633
+ order ):
655
634
656
- if include_template_projects is True :
657
- # Defaults to False on the server, so only pass it if it's True
658
- params ["include_template_projects" ] = True
635
+ params = {
636
+ "type" : entity_type ,
637
+ "return_fields" : fields or ["id" ],
638
+ "filters" : filters ,
639
+ "return_only" : (retired_only and 'retired' ) or "active" ,
640
+ "return_paging_info" : True ,
641
+ "paging" : {
642
+ "entities_per_page" : self .config .records_per_page ,
643
+ "current_page" : 1
644
+ }
645
+ }
659
646
660
647
if order :
661
648
sort_list = []
@@ -669,8 +656,32 @@ def _construct_read_parameters(self,
669
656
'direction' : sort ['direction' ]
670
657
})
671
658
params ['sorts' ] = sort_list
659
+
660
+ return params
661
+
662
+
663
+ def _construct_flag_parameters (self ,
664
+ params ,
665
+ include_archived_projects ,
666
+ include_template_projects ):
667
+
668
+ if not include_archived_projects :
669
+ # This defaults to True on the server (no argument is sent)
670
+ # So we only need to check the server version if it's False
671
+ self .server_caps .ensure_include_archived_projects ()
672
+ # Only pass it if it's False
673
+ params ["include_archived_projects" ] = False
674
+
675
+ if include_template_projects :
676
+ # This defaults to False on the server (no argument is sent)
677
+ # So we only need to check the server version if it's True
678
+ self .server_caps .ensure_include_template_projects ()
679
+ # Only pass it if it's True
680
+ params ["include_template_projects" ] = True
681
+
672
682
return params
673
683
684
+
674
685
def summarize (self ,
675
686
entity_type ,
676
687
filters ,
@@ -695,19 +706,9 @@ def summarize(self,
695
706
"summaries" : summary_fields ,
696
707
"filters" : filters }
697
708
698
- if not include_archived_projects :
699
- # This defaults to True on the server (no argument is sent)
700
- # So we only need to check the server version if it is False
701
- self .server_caps .ensure_include_archived_projects ()
702
- # Only pass it if it's False
703
- params ["include_archived_projects" ] = False
704
-
705
- if include_template_projects :
706
- # This defaults to False on the server (no argument is sent)
707
- # So we only need to check the server version if it is True
708
- self .server_caps .ensure_include_template_projects ()
709
- # Only pass it if it's True
710
- params ["include_template_projects" ] = True
709
+ params = self ._construct_flag_parameters (params ,
710
+ include_archived_projects ,
711
+ include_template_projects )
711
712
712
713
if grouping != None :
713
714
params ['grouping' ] = grouping
0 commit comments