@@ -129,7 +129,7 @@ def __init__(self, host, meta):
129
129
self .is_dev = False
130
130
131
131
self .version = tuple (self .version [:3 ])
132
- self ._ensure_json_supported ()
132
+ self .ensure_json_supported ()
133
133
134
134
135
135
def _ensure_support (self , feature ):
@@ -146,25 +146,28 @@ def _ensure_support(self, feature):
146
146
"%s requires server version %s or higher, " \
147
147
"server is %s" % (feature ['label' ], _version_str (feature ['version' ]), _version_str (self .version ))
148
148
)
149
+ return False
150
+ else :
151
+ return True
149
152
150
153
151
- def _ensure_json_supported (self ):
154
+ def ensure_json_supported (self ):
152
155
"""Wrapper for ensure_support"""
153
- self ._ensure_support ({
156
+ return self ._ensure_support ({
154
157
'version' : (2 , 4 , 0 ),
155
158
'label' : 'JSON API'
156
159
})
157
160
158
161
def ensure_include_archived_projects (self ):
159
162
"""Wrapper for ensure_support"""
160
- self ._ensure_support ({
163
+ return self ._ensure_support ({
161
164
'version' : (5 , 3 , 14 ),
162
165
'label' : 'include_archived_projects parameter'
163
166
})
164
167
165
168
def ensure_include_template_projects (self ):
166
169
"""Wrapper for ensure_support"""
167
- self ._ensure_support ({
170
+ return self ._ensure_support ({
168
171
'version' : (6 , 0 , 0 ),
169
172
'label' : 'include_template_projects parameter'
170
173
})
@@ -466,7 +469,7 @@ def find_one(self, entity_type, filters, fields=None, order=None,
466
469
:param include_template_projects: Optional, flag to include entities
467
470
belonging to template projects. Default: False
468
471
469
- :returns: Result
472
+ :returns: dict of requested entity's fields, or None if not found.
470
473
"""
471
474
472
475
results = self .find (entity_type , filters , fields , order ,
@@ -529,22 +532,13 @@ def find(self, entity_type, filters, fields=None, order=None,
529
532
raise ShotgunError ("Deprecated: Use of filter_operator for find()"
530
533
" is not valid any more. See the documentation on find()" )
531
534
532
- if not include_archived_projects :
533
- # This defaults to True on the server (no argument is sent)
534
- # So we only need to check the server version if it is False
535
- self .server_caps .ensure_include_archived_projects ()
536
-
537
- if include_template_projects :
538
- # This defaults to False on the server (no argument is sent)
539
- # So we only need to check the server version if it is True
540
- self .server_caps .ensure_include_template_projects ()
541
-
542
-
543
535
params = self ._construct_read_parameters (entity_type ,
544
536
fields ,
545
537
filters ,
546
538
retired_only ,
547
- order ,
539
+ order )
540
+
541
+ params = self ._construct_flag_parameters (params ,
548
542
include_archived_projects ,
549
543
include_template_projects )
550
544
@@ -583,31 +577,24 @@ def find(self, entity_type, filters, fields=None, order=None,
583
577
return self ._parse_records (records )
584
578
585
579
586
-
587
580
def _construct_read_parameters (self ,
588
581
entity_type ,
589
582
fields ,
590
583
filters ,
591
584
retired_only ,
592
- order ,
593
- include_archived_projects ,
594
- include_template_projects ):
595
- params = {}
596
- params ["type" ] = entity_type
597
- params ["return_fields" ] = fields or ["id" ]
598
- params ["filters" ] = filters
599
- params ["return_only" ] = (retired_only and 'retired' ) or "active"
600
- params ["return_paging_info" ] = True
601
- params ["paging" ] = { "entities_per_page" : self .config .records_per_page ,
602
- "current_page" : 1 }
603
-
604
- if include_archived_projects is False :
605
- # Defaults to True on the server, so only pass it if it's False
606
- params ["include_archived_projects" ] = False
585
+ order ):
607
586
608
- if include_template_projects is True :
609
- # Defaults to False on the server, so only pass it if it's True
610
- params ["include_template_projects" ] = True
587
+ params = {
588
+ "type" : entity_type ,
589
+ "return_fields" : fields or ["id" ],
590
+ "filters" : filters ,
591
+ "return_only" : (retired_only and 'retired' ) or "active" ,
592
+ "return_paging_info" : True ,
593
+ "paging" : {
594
+ "entities_per_page" : self .config .records_per_page ,
595
+ "current_page" : 1
596
+ }
597
+ }
611
598
612
599
if order :
613
600
sort_list = []
@@ -621,8 +608,32 @@ def _construct_read_parameters(self,
621
608
'direction' : sort ['direction' ]
622
609
})
623
610
params ['sorts' ] = sort_list
611
+
612
+ return params
613
+
614
+
615
+ def _construct_flag_parameters (self ,
616
+ params ,
617
+ include_archived_projects ,
618
+ include_template_projects ):
619
+
620
+ if not include_archived_projects :
621
+ # This defaults to True on the server (no argument is sent)
622
+ # So we only need to check the server version if it's False
623
+ self .server_caps .ensure_include_archived_projects ()
624
+ # Only pass it if it's False
625
+ params ["include_archived_projects" ] = False
626
+
627
+ if include_template_projects :
628
+ # This defaults to False on the server (no argument is sent)
629
+ # So we only need to check the server version if it's True
630
+ self .server_caps .ensure_include_template_projects ()
631
+ # Only pass it if it's True
632
+ params ["include_template_projects" ] = True
633
+
624
634
return params
625
635
636
+
626
637
def summarize (self ,
627
638
entity_type ,
628
639
filters ,
@@ -647,19 +658,9 @@ def summarize(self,
647
658
"summaries" : summary_fields ,
648
659
"filters" : filters }
649
660
650
- if not include_archived_projects :
651
- # This defaults to True on the server (no argument is sent)
652
- # So we only need to check the server version if it is False
653
- self .server_caps .ensure_include_archived_projects ()
654
- # Only pass it if it's False
655
- params ["include_archived_projects" ] = False
656
-
657
- if include_template_projects :
658
- # This defaults to False on the server (no argument is sent)
659
- # So we only need to check the server version if it is True
660
- self .server_caps .ensure_include_template_projects ()
661
- # Only pass it if it's True
662
- params ["include_template_projects" ] = True
661
+ params = self ._construct_flag_parameters (params ,
662
+ include_archived_projects ,
663
+ include_template_projects )
663
664
664
665
if grouping != None :
665
666
params ['grouping' ] = grouping
0 commit comments