14
14
# limitations under the License.
15
15
#
16
16
import functools
17
- from typing import Union , List
17
+ from typing import Dict , List , Union , Tuple
18
18
19
19
from .server_context import ServerContext
20
20
from labkey .query import QueryFilter
@@ -207,12 +207,12 @@ def __init__(self, **kwargs):
207
207
208
208
def to_json (self ):
209
209
data = {
210
- "backgroundColor " : self .background_color ,
210
+ "backgroundcolor " : self .background_color ,
211
211
"bold" : self .bold ,
212
212
"filter" : self .filter ,
213
213
"italic" : self .italic ,
214
214
"strikethrough" : self .strike_through ,
215
- "textColor " : self .text_color ,
215
+ "textcolor " : self .text_color ,
216
216
}
217
217
218
218
return data
@@ -392,12 +392,12 @@ def create(
392
392
domain = None
393
393
394
394
# domainDesign is not required when creating a domain from a template
395
- if domain_definition [ "domainDesign" ] is not None :
395
+ if domain_definition . get ( "domainDesign" , None ) is not None :
396
396
domain_fields = domain_definition ["domainDesign" ]["fields" ]
397
397
domain_definition ["domainDesign" ]["fields" ] = list (
398
398
map (__format_conditional_filters , domain_fields )
399
399
)
400
-
400
+
401
401
raw_domain = server_context .make_request (url , json = domain_definition )
402
402
403
403
if raw_domain is not None :
@@ -436,13 +436,50 @@ def get(
436
436
"""
437
437
url = server_context .build_url ("property" , "getDomain.api" , container_path = container_path )
438
438
payload = {"schemaName" : schema_name , "queryName" : query_name }
439
- domain = None
440
439
raw_domain = server_context .make_request (url , payload , method = "GET" )
441
440
441
+ if raw_domain is not None :
442
+ return Domain (** raw_domain )
443
+
444
+ return None
445
+
446
+
447
+ def get_domain_details (
448
+ server_context : ServerContext ,
449
+ schema_name : str = None ,
450
+ query_name : str = None ,
451
+ domain_id : int = None ,
452
+ domain_kind : str = None ,
453
+ container_path : str = None ,
454
+ ) -> Tuple [Domain , Dict ]:
455
+ """
456
+ Gets a domain design and its associated options.
457
+ :param server_context: A LabKey server context. See utils.create_server_context.
458
+ :param schema_name: schema of table
459
+ :param query_name: table name of domain to get
460
+ :param domain_id: id of domain to get
461
+ :param domain_kind: domainKind of domain to get
462
+ :param container_path: labkey container path if not already set in context
463
+ :return: Domain, Dict
464
+ """
465
+ url = server_context .build_url (
466
+ "property" , "getDomainDetails.api" , container_path = container_path
467
+ )
468
+ payload = {
469
+ "schemaName" : schema_name ,
470
+ "queryName" : query_name ,
471
+ "domainId" : domain_id ,
472
+ "domainKind" : domain_kind ,
473
+ }
474
+ response = server_context .make_request (url , payload , method = "GET" )
475
+ raw_domain = response .get ("domainDesign" , None )
476
+ domain = None
477
+ options = response .get ("options" , None )
478
+
442
479
if raw_domain is not None :
443
480
domain = Domain (** raw_domain )
444
481
445
- return domain
482
+ return domain , options
446
483
447
484
448
485
def infer_fields (
@@ -473,6 +510,7 @@ def save(
473
510
query_name : str ,
474
511
domain : Domain ,
475
512
container_path : str = None ,
513
+ options : Dict = None ,
476
514
) -> any :
477
515
"""
478
516
Saves the provided domain design
@@ -481,6 +519,7 @@ def save(
481
519
:param query_name: query name of domain
482
520
:param domain: Domain to save
483
521
:param container_path: labkey container path if not already set in context
522
+ :param options: associated domain options to be saved
484
523
:return:
485
524
"""
486
525
url = server_context .build_url ("property" , "saveDomain.api" , container_path = container_path )
@@ -490,6 +529,9 @@ def save(
490
529
"schemaName" : schema_name ,
491
530
}
492
531
532
+ if options is not None :
533
+ payload ["options" ] = options
534
+
493
535
return server_context .make_request (url , json = payload )
494
536
495
537
@@ -513,10 +555,30 @@ def drop(self, schema_name: str, query_name: str, container_path: str = None):
513
555
def get (self , schema_name : str , query_name : str , container_path : str = None ):
514
556
return get (self .server_context , schema_name , query_name , container_path )
515
557
558
+ @functools .wraps (get_domain_details )
559
+ def get_domain_details (
560
+ self ,
561
+ schema_name : str = None ,
562
+ query_name : str = None ,
563
+ domain_id : int = None ,
564
+ domain_kind : str = None ,
565
+ container_path : str = None ,
566
+ ):
567
+ return get_domain_details (
568
+ self .server_context , schema_name , query_name , domain_id , domain_kind , container_path
569
+ )
570
+
516
571
@functools .wraps (infer_fields )
517
572
def infer_fields (self , data_file : any , container_path : str = None ):
518
573
return infer_fields (self .server_context , data_file , container_path )
519
574
520
575
@functools .wraps (save )
521
- def save (self , schema_name : str , query_name : str , domain : Domain , container_path : str = None ):
522
- return save (self .server_context , schema_name , query_name , domain , container_path )
576
+ def save (
577
+ self ,
578
+ schema_name : str ,
579
+ query_name : str ,
580
+ domain : Domain ,
581
+ container_path : str = None ,
582
+ options : Dict = None ,
583
+ ):
584
+ return save (self .server_context , schema_name , query_name , domain , container_path , options )
0 commit comments