Skip to content

Commit f122aa7

Browse files
DuncanCheeriosDuncan Sorenson
andauthored
Making displayfield optional (#31)
Co-authored-by: Duncan Sorenson <DuncanSorenson@protonmail.com>
1 parent 4e6baa8 commit f122aa7

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

pyPreservica/authorityAPI.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
class Table:
23-
def __init__(self, reference: str, name: str, security_tag: str, displayField: str, metadataConnections: list):
23+
def __init__(self, reference: str, name: str, security_tag: str, metadataConnections: list, displayField: str=None):
2424
self.reference = reference
2525
self.name = name
2626
self.security_tag = security_tag
@@ -29,10 +29,11 @@ def __init__(self, reference: str, name: str, security_tag: str, displayField: s
2929
self.fields = None
3030

3131
def __str__(self):
32+
displayField = self.displayField or "<None>"
3233
return f"Ref:\t\t\t{self.reference}\n" \
3334
f"Name:\t\t\t{self.name}\n" \
3435
f"Security Tag:\t{self.security_tag}\n" \
35-
f"Display Field:\t\t\t{self.displayField}\n" \
36+
f"Display Field:\t\t\t{displayField}\n" \
3637
f"Metadata Connections:\t\t\t{self.metadataConnections}\n" \
3738
f"Fields:\t\t\t{self.fields}\n"
3839

@@ -190,8 +191,7 @@ def table(self, reference: str) -> Table:
190191
if response.status_code == requests.codes.ok:
191192
json_response = str(response.content.decode('utf-8'))
192193
doc = json.loads(json_response)
193-
table = Table(doc['ref'], doc['name'], doc['securityDescriptor'], doc['displayField'],
194-
doc['metadataConnections'])
194+
table = Table(doc['ref'], doc['name'], doc['securityDescriptor'], doc['metadataConnections'], doc.get('displayField'))
195195
table.fields = doc['fields']
196196
return table
197197
else:
@@ -218,8 +218,7 @@ def tables(self) -> Set[Table]:
218218
doc = json.loads(json_response)
219219
results = set()
220220
for table in doc['tables']:
221-
t = Table(table['ref'], table['name'], table['securityDescriptor'], table['displayField'],
222-
table['metadataConnections'])
221+
t = Table(table['ref'], table['name'], table['securityDescriptor'], table['metadataConnections'], table.get('displayField'))
223222
results.add(t)
224223
return results
225224
else:

0 commit comments

Comments
 (0)