-
Notifications
You must be signed in to change notification settings - Fork 198
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
nemoDreamer
wants to merge
3
commits into
master
Choose a base branch
from
ticket/28441_hide_template_projects_by_default
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,19 +157,30 @@ 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): | ||
def ensure_include_archived_projects(self, value=True): | ||
"""Wrapper for ensure_support""" | ||
self._ensure_support({ | ||
# This defaults to True on the server | ||
# So we only need to raise a version error if it's False | ||
return self._ensure_support({ | ||
'version': (5, 3, 14), | ||
'label': 'include_archived_projects parameter' | ||
}) | ||
}, (value == False)) | ||
|
||
def ensure_include_template_projects(self, value=False): | ||
"""Wrapper for ensure_support""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value not documented. |
||
# This defaults to False on the server | ||
# So we only need to raise a version error if it's True | ||
return self._ensure_support({ | ||
'version': (6, 0, 0), | ||
'label': 'include_template_projects parameter' | ||
}, (value == True)) | ||
|
||
def ensure_per_project_customization(self): | ||
"""Wrapper for ensure_support""" | ||
|
@@ -485,7 +496,8 @@ def info(self): | |
return self._call_rpc("info", None, include_auth_params=False) | ||
|
||
def find_one(self, entity_type, filters, fields=None, order=None, | ||
filter_operator=None, retired_only=False, include_archived_projects=True): | ||
filter_operator=None, retired_only=False, | ||
include_archived_projects=True, include_template_projects=False): | ||
"""Calls the find() method and returns the first result, or None. | ||
|
||
:param entity_type: Required, entity type (string) to find. | ||
|
@@ -504,24 +516,34 @@ def find_one(self, entity_type, filters, fields=None, order=None, | |
:param limit: Optional, number of entities to return per page. | ||
Defaults to 0 which returns all entities that match. | ||
|
||
:param page: Optional, page of results to return. By default all | ||
results are returned. Use together with limit. | ||
|
||
:param retired_only: Optional, flag to return only entities that have | ||
been retried. Defaults to False which returns only entities which | ||
have not been retired. | ||
|
||
:param page: Optional, page of results to return. By default all | ||
results are returned. Use together with limit. | ||
|
||
:param include_archived_projects: Optional, flag to include entities | ||
whose projects have been archived. Default: True | ||
|
||
:param include_template_projects: Optional, flag to include entities | ||
belonging to template projects. Default: False | ||
|
||
:returns: dict of requested entity's fields, or None if not found. | ||
""" | ||
|
||
results = self.find(entity_type, filters, fields, order, | ||
filter_operator, 1, retired_only, include_archived_projects=include_archived_projects) | ||
filter_operator, 1, retired_only, | ||
include_archived_projects=include_archived_projects, | ||
include_template_projects=include_template_projects) | ||
|
||
if results: | ||
return results[0] | ||
return None | ||
|
||
def find(self, entity_type, filters, fields=None, order=None, | ||
filter_operator=None, limit=0, retired_only=False, page=0, | ||
include_archived_projects=True): | ||
include_archived_projects=True, include_template_projects=False): | ||
"""Find entities matching the given filters. | ||
|
||
:param entity_type: Required, entity type (string) to find. | ||
|
@@ -548,7 +570,10 @@ def find(self, entity_type, filters, fields=None, order=None, | |
have not been retired. | ||
|
||
:param include_archived_projects: Optional, flag to include entities | ||
whose projects have been archived | ||
whose projects have been archived. Default: True | ||
|
||
:param include_template_projects: Optional, flag to include entities | ||
belonging to template projects. Default: False | ||
|
||
:returns: list of the dicts for each entity with the requested fields, | ||
and their id and type. | ||
|
@@ -567,18 +592,15 @@ 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() | ||
|
||
|
||
params = self._construct_read_parameters(entity_type, | ||
fields, | ||
filters, | ||
retired_only, | ||
order, | ||
include_archived_projects) | ||
order) | ||
|
||
params = self._construct_flag_parameters(params, | ||
include_archived_projects, | ||
include_template_projects) | ||
|
||
if limit and limit <= self.config.records_per_page: | ||
params["paging"]["entities_per_page"] = limit | ||
|
@@ -615,26 +637,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): | ||
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): | ||
|
||
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 = [] | ||
|
@@ -648,6 +668,21 @@ 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 self.server_caps.ensure_include_archived_projects(include_archived_projects): | ||
params["include_archived_projects"] = include_archived_projects | ||
|
||
if self.server_caps.ensure_include_template_projects(include_template_projects): | ||
params["include_template_projects"] = include_template_projects | ||
|
||
return params | ||
|
||
|
||
|
@@ -665,7 +700,8 @@ def summarize(self, | |
summary_fields, | ||
filter_operator=None, | ||
grouping=None, | ||
include_archived_projects=True): | ||
include_archived_projects=True, | ||
include_template_projects=False): | ||
""" | ||
Return group and summary information for entity_type for summary_fields | ||
based on the given filters. | ||
|
@@ -678,18 +714,13 @@ def summarize(self, | |
if isinstance(filters, (list, tuple)): | ||
filters = _translate_filters(filters, filter_operator) | ||
|
||
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() | ||
|
||
params = {"type": entity_type, | ||
"summaries": summary_fields, | ||
"filters": filters} | ||
|
||
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 | ||
params = self._construct_flag_parameters(params, | ||
include_archived_projects, | ||
include_template_projects) | ||
|
||
if grouping != None: | ||
params['grouping'] = grouping | ||
|
@@ -1624,6 +1655,7 @@ def _call_rpc(self, method, params, include_auth_params=True, first=False): | |
|
||
""" | ||
|
||
log_time = datetime.datetime.now() | ||
LOG.debug("Starting rpc call to %s with params %s" % ( | ||
method, params)) | ||
|
||
|
@@ -1638,7 +1670,10 @@ def _call_rpc(self, method, params, include_auth_params=True, first=False): | |
} | ||
http_status, resp_headers, body = self._make_call("POST", | ||
self.config.api_path, encoded_payload, req_headers) | ||
LOG.debug("Completed rpc call to %s" % (method)) | ||
|
||
log_time = datetime.datetime.now() - log_time | ||
LOG.debug("Completed rpc call to %s in %s" % (method, str(log_time))) | ||
|
||
try: | ||
self._parse_http_status(http_status) | ||
except ProtocolError, e: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value not documented.