Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket/28441 hide template projects by default #79

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
For #28441: refactored to clean up duplication in flag checks
nemoDreamer committed Apr 3, 2015
commit d5914e49b00ef605ce213d3a174004091088499b
97 changes: 47 additions & 50 deletions shotgun_api3/shotgun.py
Original file line number Diff line number Diff line change
@@ -134,7 +134,7 @@ def __init__(self, host, meta):
self.is_dev = False

self.version = tuple(self.version[:3])
self._ensure_json_supported()
self.ensure_json_supported()


def _ensure_support(self, feature, raise_hell=True):
@@ -157,23 +157,23 @@ def _ensure_support(self, feature, raise_hell=True):
return True


def _ensure_json_supported(self):
def ensure_json_supported(self):
"""Wrapper for ensure_support"""
self._ensure_support({
return self._ensure_support({
'version': (2, 4, 0),
'label': 'JSON API'
})

def ensure_include_archived_projects(self):
"""Wrapper for ensure_support"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value not documented.

self._ensure_support({
return self._ensure_support({
'version': (5, 3, 14),
'label': 'include_archived_projects parameter'
})

def ensure_include_template_projects(self):
"""Wrapper for ensure_support"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value not documented.

self._ensure_support({
return self._ensure_support({
'version': (6, 0, 0),
'label': 'include_template_projects parameter'
})
@@ -525,7 +525,7 @@ def find_one(self, entity_type, filters, fields=None, order=None,
:param include_template_projects: Optional, flag to include entities
belonging to template projects. Default: False

:returns: Result
:returns: dict of requested entity's fields, or None if not found.
"""

results = self.find(entity_type, filters, fields, order,
@@ -588,22 +588,13 @@ def find(self, entity_type, filters, fields=None, order=None,
raise ShotgunError("Deprecated: Use of filter_operator for find()"
" is not valid any more. See the documentation on find()")

if not include_archived_projects:
# This defaults to True on the server (no argument is sent)
# So we only need to check the server version if it is False
self.server_caps.ensure_include_archived_projects()

if include_template_projects:
# This defaults to False on the server (no argument is sent)
# So we only need to check the server version if it is True
self.server_caps.ensure_include_template_projects()


params = self._construct_read_parameters(entity_type,
fields,
filters,
retired_only,
order,
order)

params = self._construct_flag_parameters(params,
include_archived_projects,
include_template_projects)

@@ -642,31 +633,24 @@ def find(self, entity_type, filters, fields=None, order=None,
return self._parse_records(records)



def _construct_read_parameters(self,
entity_type,
fields,
filters,
retired_only,
order,
include_archived_projects,
include_template_projects):
params = {}
params["type"] = entity_type
params["return_fields"] = fields or ["id"]
params["filters"] = filters
params["return_only"] = (retired_only and 'retired') or "active"
params["return_paging_info"] = True
params["paging"] = { "entities_per_page": self.config.records_per_page,
"current_page": 1 }

if include_archived_projects is False:
# Defaults to True on the server, so only pass it if it's False
params["include_archived_projects"] = False
order):

if include_template_projects is True:
# Defaults to False on the server, so only pass it if it's True
params["include_template_projects"] = True
params = {
"type": entity_type,
"return_fields": fields or ["id"],
"filters": filters,
"return_only": (retired_only and 'retired') or "active",
"return_paging_info": True,
"paging": {
"entities_per_page": self.config.records_per_page,
"current_page": 1
}
}

if order:
sort_list = []
@@ -680,6 +664,29 @@ def _construct_read_parameters(self,
'direction' : sort['direction']
})
params['sorts'] = sort_list

return params


def _construct_flag_parameters(self,
params,
include_archived_projects,
include_template_projects):

if not include_archived_projects:
# This defaults to True on the server (no argument is sent)
# So we only need to check the server version if it's False
self.server_caps.ensure_include_archived_projects()
# Only pass it if it's False
params["include_archived_projects"] = False

if include_template_projects:
# This defaults to False on the server (no argument is sent)
# So we only need to check the server version if it's True
self.server_caps.ensure_include_template_projects()
# Only pass it if it's True
params["include_template_projects"] = True

return params


@@ -715,19 +722,9 @@ def summarize(self,
"summaries": summary_fields,
"filters": filters}

if not include_archived_projects:
# This defaults to True on the server (no argument is sent)
# So we only need to check the server version if it is False
self.server_caps.ensure_include_archived_projects()
# Only pass it if it's False
params["include_archived_projects"] = False

if include_template_projects:
# This defaults to False on the server (no argument is sent)
# So we only need to check the server version if it is True
self.server_caps.ensure_include_template_projects()
# Only pass it if it's True
params["include_template_projects"] = True
params = self._construct_flag_parameters(params,
include_archived_projects,
include_template_projects)

if grouping != None:
params['grouping'] = grouping
8 changes: 4 additions & 4 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -74,18 +74,18 @@ def test_server_version_json(self):
sc = ServerCapabilities("foo", {"version" : (2,4,0)})

sc.version = (2,3,99)
self.assertRaises(api.ShotgunError, sc._ensure_json_supported)
self.assertRaises(api.ShotgunError, sc.ensure_json_supported)
self.assertRaises(api.ShotgunError, ServerCapabilities, "foo",
{"version" : (2,2,0)})

sc.version = (0,0,0)
self.assertRaises(api.ShotgunError, sc._ensure_json_supported)
self.assertRaises(api.ShotgunError, sc.ensure_json_supported)

sc.version = (2,4,0)
sc._ensure_json_supported()
sc.ensure_json_supported()

sc.version = (2,5,0)
sc._ensure_json_supported()
sc.ensure_json_supported()


def test_session_uuid(self):