Skip to content

Commit cb3cfc3

Browse files
author
KP
committed
add summarize() method for requesting summary and grouped summary information
1 parent f616dfd commit cb3cfc3

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

shotgun_api3.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
# https://support.shotgunsoftware.com/forums/48807-developer-api-info
3333
# ---------------------------------------------------------------------------------------------
3434

35-
__version__ = "3.0.6"
35+
# based on v3.0.6 code
36+
__version__ = "3.0.x (summaries branch)"
3637

3738
# ---------------------------------------------------------------------------------------------
3839
# SUMMARY
@@ -58,6 +59,9 @@
5859
# CHANGELOG
5960
# ---------------------------------------------------------------------------------------------
6061
"""
62+
+v3.0.x (summaries branch) - 2011 Apr 04
63+
+ beta support for summarize() method for summary and grouping info
64+
6165
+v3.0.6 - 2010 Jan 25
6266
+ optimization: don't request paging_info unless required (and server support is available)
6367
@@ -453,6 +457,42 @@ def find_one(self, entity_type, filters, fields=None, order=None, filter_operato
453457
else:
454458
return None
455459

460+
def summarize(self, entity_type, filters, summary_fields, filter_operator=None, grouping=None):
461+
"""
462+
Return group and summary information for entity_type for summary_fields
463+
based on the given filters.
464+
"""
465+
if not isinstance(filters, list):
466+
raise ValueError("summarize() 'filters' parameter must be a list")
467+
468+
if not isinstance(grouping, list) and grouping != None:
469+
raise ValueError("summarize() 'grouping' parameter must be a list or None")
470+
471+
new_filters = {}
472+
if not filter_operator or filter_operator == "all":
473+
new_filters["logical_operator"] = "and"
474+
else:
475+
new_filters["logical_operator"] = "or"
476+
477+
new_filters["conditions"] = []
478+
for f in filters:
479+
new_filters["conditions"].append( {"path":f[0],"relation":f[1],"values":f[2:]} )
480+
481+
filters = new_filters
482+
483+
req = {
484+
"type": entity_type,
485+
"summaries": summary_fields,
486+
"filters": filters,
487+
}
488+
if grouping != None:
489+
req['grouping'] = grouping
490+
491+
resp = self._api3.summarize(req)
492+
results = resp["results"]
493+
494+
return results
495+
456496
def _required_keys(self, message, required_keys, data):
457497
missing = set(required_keys) - set(data.keys())
458498
if missing:

0 commit comments

Comments
 (0)