|
32 | 32 | # https://support.shotgunsoftware.com/forums/48807-developer-api-info |
33 | 33 | # --------------------------------------------------------------------------------------------- |
34 | 34 |
|
35 | | -__version__ = "3.0.6" |
| 35 | +# based on v3.0.6 code |
| 36 | +__version__ = "3.0.x (summaries branch)" |
36 | 37 |
|
37 | 38 | # --------------------------------------------------------------------------------------------- |
38 | 39 | # SUMMARY |
|
58 | 59 | # CHANGELOG |
59 | 60 | # --------------------------------------------------------------------------------------------- |
60 | 61 | """ |
| 62 | ++v3.0.x (summaries branch) - 2011 Apr 04 |
| 63 | + + beta support for summarize() method for summary and grouping info |
| 64 | +
|
61 | 65 | +v3.0.6 - 2010 Jan 25 |
62 | 66 | + optimization: don't request paging_info unless required (and server support is available) |
63 | 67 |
|
@@ -453,6 +457,42 @@ def find_one(self, entity_type, filters, fields=None, order=None, filter_operato |
453 | 457 | else: |
454 | 458 | return None |
455 | 459 |
|
| 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 | + |
456 | 496 | def _required_keys(self, message, required_keys, data): |
457 | 497 | missing = set(required_keys) - set(data.keys()) |
458 | 498 | if missing: |
|
0 commit comments