Skip to content

Commit 278360f

Browse files
Merge pull request #76 from shotgunsoftware/27860_project_customization
Adds per-project visibility querying on schema methods
2 parents 758d0c1 + 3a06ab7 commit 278360f

File tree

4 files changed

+93
-30
lines changed

4 files changed

+93
-30
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ Integration and unit tests are provided.
5353

5454
## Changelog
5555

56+
**v3.0.18 - 2015 Mar 13**
57+
58+
+ Add ability to query the per-project visibility status for entities, fields and statuses. (requires Shotgun server >= v5.4.4)
59+
5660
**v3.0.17 - 2014 Jul 10**
5761

5862
+ Add ability to update last_accessed_by_current_user on Project.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
setup(
1919
name='shotgun_api3',
20-
version='3.0.17',
20+
version='3.0.18',
2121
description='Shotgun Python API ',
2222
long_description=readme,
2323
author='Shotgun Software',

shotgun_api3/shotgun.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575

7676
# ----------------------------------------------------------------------------
7777
# Version
78-
__version__ = "3.0.18.dev"
78+
__version__ = "3.0.18"
7979

8080
# ----------------------------------------------------------------------------
8181
# Errors
@@ -945,23 +945,47 @@ def followers(self, entity):
945945

946946
return self._call_rpc('followers', params)
947947

948-
def schema_entity_read(self):
948+
def schema_entity_read(self, project_entity=None):
949949
"""Gets all active entities defined in the schema.
950950
951+
:param dict project_entity: Optional, if set, each field's visibility is reported accordingly
952+
to the specified project's current visibility settings.
953+
If None, all fields are reported as visible.
954+
951955
:returns: dict of Entity Type to dict containing the display name.
952956
"""
953957

954-
return self._call_rpc("schema_entity_read", None)
958+
params = {}
959+
960+
if project_entity:
961+
params["project"] = project_entity
955962

956-
def schema_read(self):
963+
if params:
964+
return self._call_rpc("schema_entity_read", params)
965+
else:
966+
return self._call_rpc("schema_entity_read", None)
967+
968+
def schema_read(self, project_entity=None):
957969
"""Gets the schema for all fields in all entities.
958970
971+
:param dict project_entity: Optional, if set, each field's visibility is reported accordingly
972+
to the specified project's current visibility settings.
973+
If None, all fields are reported as visible.
974+
959975
:returns: nested dicts
960976
"""
961977

962-
return self._call_rpc("schema_read", None)
978+
params = {}
979+
980+
if project_entity:
981+
params["project"] = project_entity
963982

964-
def schema_field_read(self, entity_type, field_name=None):
983+
if params:
984+
return self._call_rpc("schema_read", params)
985+
else:
986+
return self._call_rpc("schema_read", None)
987+
988+
def schema_field_read(self, entity_type, field_name=None, project_entity=None):
965989
"""Gets all schema for fields in the specified entity_type or one
966990
field.
967991
@@ -972,14 +996,20 @@ def schema_field_read(self, entity_type, field_name=None):
972996
definition for. If not supplied all fields for the entity type are
973997
returned.
974998
999+
:param dict project_entity: Optional, if set, each field's visibility is reported accordingly
1000+
to the specified project's current visibility settings.
1001+
If None, all fields are reported as visible.
1002+
9751003
:returns: dict of field name to nested dicts which describe the field
9761004
"""
9771005

9781006
params = {
979-
"type" : entity_type,
1007+
"type": entity_type,
9801008
}
9811009
if field_name:
9821010
params["field_name"] = field_name
1011+
if project_entity:
1012+
params["project"] = project_entity
9831013

9841014
return self._call_rpc("schema_field_read", params)
9851015

tests/test_api_long.py

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import base
77
import random
88

9+
910
class TestShotgunApiLong(base.LiveTestBase):
10-
11+
1112
def test_automated_find(self):
1213
"""Called find for each entity type and read all fields"""
1314
all_entities = self.sg.schema_entity_read().keys()
@@ -25,57 +26,56 @@ def test_automated_find(self):
2526
if not fields:
2627
print "No fields for %s skipping" % (entity_type,)
2728
continue
28-
29-
#trying to use some different code paths to the other find test
30-
#TODO for our test project, we haven't populated these entities....
29+
30+
# trying to use some different code paths to the other find test
31+
# TODO for our test project, we haven't populated these entities....
3132
order = [{'field_name': fields.keys()[0], 'direction': direction}]
3233
if "project" in fields:
3334
filters = [['project', 'is', self.project]]
3435
else:
3536
filters = []
3637

37-
records = self.sg.find(entity_type, filters, fields=fields.keys(),
38+
records = self.sg.find(entity_type, filters, fields=fields.keys(),
3839
order=order, filter_operator=filter_operator,
3940
limit=limit, page=page)
40-
41+
4142
self.assertTrue(isinstance(records, list))
42-
43+
4344
if filter_operator == "all":
4445
filter_operator = "any"
45-
else:
46+
else:
4647
filter_operator = "all"
4748
if direction == "desc":
4849
direction = "asc"
49-
else:
50+
else:
5051
direction = "desc"
5152
limit = (limit % 5) + 1
5253
page = (page % 3) + 1
53-
5454

5555
def test_schema(self):
5656
"""Called schema functions"""
57-
57+
5858
schema = self.sg.schema_entity_read()
5959
self.assertTrue(schema, dict)
6060
self.assertTrue(len(schema) > 0)
6161

6262
schema = self.sg.schema_read()
6363
self.assertTrue(schema, dict)
6464
self.assertTrue(len(schema) > 0)
65-
65+
6666
schema = self.sg.schema_field_read("Version")
6767
self.assertTrue(schema, dict)
6868
self.assertTrue(len(schema) > 0)
69-
69+
7070
schema = self.sg.schema_field_read("Version", field_name="user")
7171
self.assertTrue(schema, dict)
7272
self.assertTrue(len(schema) > 0)
7373
self.assertTrue("user" in schema)
7474

75-
# An explantion is in order here. the field code that is created in shotgun is based on the human display name
75+
# An explanation is in order here. the field code that is created in shotgun is based on the human display name
7676
# that is provided , so for example "Money Count" would generate the field code 'sg_monkey_count' . The field
7777
# that is created in this test is retired at the end of the test but when this test is run again against
78-
# the same database ( which happens on our Continous Integration server ) trying to create a new field
78+
# the same database ( which happens on our Continuous Integration server ) trying to create a new field
7979
# called "Monkey Count" will now fail due to the new Delete Field Forever features we have added to shotgun
8080
# since there will a retired field called sg_monkey_count. The old behavior was to go ahead and create a new
8181
# "Monkey Count" field with a field code with an incremented number of the end like sg_monkey_count_1. The new
@@ -87,15 +87,44 @@ def test_schema(self):
8787
properties = { "description" : "How many monkeys were needed" }
8888
new_field_name = self.sg.schema_field_create("Version", "number", human_field_name,
8989
properties=properties)
90-
91-
properties = {"description" : "How many monkeys turned up"}
90+
91+
properties = {"description": "How many monkeys turned up"}
9292
ret_val = self.sg.schema_field_update("Version",
93-
new_field_name,
94-
properties)
93+
new_field_name,
94+
properties)
9595
self.assertTrue(ret_val)
96-
96+
9797
ret_val = self.sg.schema_field_delete("Version", new_field_name)
9898
self.assertTrue(ret_val)
99-
100-
if __name__ == '__main__':
99+
100+
def test_schema_with_project(self):
101+
"""Called schema functions"""
102+
103+
project_entity = {'type': 'Project', 'id': 0}
104+
schema = self.sg.schema_entity_read(project_entity)
105+
self.assertTrue(schema, dict)
106+
self.assertTrue(len(schema) > 0)
107+
self.assertTrue('Project' in schema)
108+
self.assertTrue('visible' in schema['Project'])
109+
110+
schema = self.sg.schema_read(project_entity)
111+
self.assertTrue(schema, dict)
112+
self.assertTrue(len(schema) > 0)
113+
self.assertTrue('Version' in schema)
114+
self.assertFalse('visible' in schema.keys())
115+
116+
schema = self.sg.schema_field_read('Version', project_entity=project_entity)
117+
self.assertTrue(schema, dict)
118+
self.assertTrue(len(schema) > 0)
119+
self.assertTrue('user' in schema)
120+
self.assertTrue('visible' in schema['user'])
121+
122+
schema = self.sg.schema_field_read('Version', 'user', project_entity)
123+
self.assertTrue(schema, dict)
124+
self.assertTrue(len(schema) > 0)
125+
self.assertTrue('user' in schema)
126+
self.assertTrue('visible' in schema['user'])
127+
128+
129+
if __name__ == '__main__':
101130
base.unittest.main()

0 commit comments

Comments
 (0)