@@ -27,62 +27,61 @@ def unknown_constructor(loader, suffix, node):
27
27
return str ("" )
28
28
self .add_multi_constructor ('' , unknown_constructor )
29
29
30
- # Register the type constructors
31
- for key , value in get_basic_yaml_constructors (initialize_full_loader = self .initialize_full_loader ).items ():
32
- self .add_constructor (key , value )
30
+ else :
33
31
34
- # If we want the full loader initialized, then we will expect that doc_db,
35
- # session, User, and Group are not None, then add these as data constructors,
36
- # see https://github.com/signebedi/libreforms-fastapi/issues/150.
32
+ # Register the type constructors
33
+ for key , value in get_basic_yaml_constructors (). items ():
34
+ self . add_constructor ( key , value )
37
35
38
- def data_constructor_all_usernames (loader , node ):
39
- if self .initialize_full_loader and User is not None and session is not None :
40
- return ["" ]+ [x .to_dict (just_the_basics = True )['username' ] for x in session .query (User ).all ()]
41
- else :
42
- return ["" ]
36
+ # If we want the full loader initialized, then we will expect that doc_db,
37
+ # session, User, and Group are not None, then add these as data constructors,
38
+ # see https://github.com/signebedi/libreforms-fastapi/issues/150.
43
39
44
- self .add_constructor ('!all_usernames' , data_constructor_all_usernames )
45
-
46
- def data_constructor_all_group_names (loader , node ):
47
- if self .initialize_full_loader and Group is not None and session is not None :
48
- return ["" ]+ [x .to_dict ()['name' ] for x in session .query (Group ).all ()]
49
- else :
50
- return ["" ]
51
-
52
- self .add_constructor ('!all_groups' , data_constructor_all_group_names )
40
+ def data_constructor_all_usernames (loader , node ):
41
+ if self .initialize_full_loader and User is not None and session is not None :
42
+ return ["" ]+ [x .to_dict (just_the_basics = True )['username' ] for x in session .query (User ).all ()]
43
+ else :
44
+ return ["" ]
53
45
54
- def data_constructor_dynamic_forms ( form_name , initialize_full_loader , doc_db ):
46
+ self . add_constructor ( '!all_usernames' , data_constructor_all_usernames )
55
47
56
- def dynamic_method (loader , data ):
57
- if self .initialize_full_loader and doc_db is not None :
58
- return ["" ]+ doc_db . _get_existing_document_ids ( form_name )
48
+ def data_constructor_all_group_names (loader , node ):
49
+ if self .initialize_full_loader and Group is not None and session is not None :
50
+ return ["" ]+ [ x . to_dict ()[ 'name' ] for x in session . query ( Group ). all ()]
59
51
else :
60
52
return ["" ]
61
53
62
- return dynamic_method
63
-
64
- # This little block of code is going to give us a world of difficulty
65
- # when we don't pass doc_db but want to validate the yaml ... how do we
66
- # access the form names other than doc_db._get_form_names()so we can
67
- # remove `if doc_db is not None:`?
68
- if doc_db is not None :
69
- for form_name in doc_db ._get_form_names ():
70
- self .add_constructor (
71
- f'!all_forms_{ form_name } ' ,
72
- data_constructor_dynamic_forms (
73
- form_name ,
74
- self .initialize_full_loader ,
75
- doc_db = doc_db
54
+ self .add_constructor ('!all_groups' , data_constructor_all_group_names )
55
+
56
+ def data_constructor_dynamic_forms (form_name , initialize_full_loader , doc_db ):
57
+
58
+ def dynamic_method (loader , data ):
59
+ if self .initialize_full_loader and doc_db is not None :
60
+ return ["" ]+ doc_db ._get_existing_document_ids (form_name )
61
+ else :
62
+ return ["" ]
63
+
64
+ return dynamic_method
65
+
66
+ # This little block of code is going to give us a world of difficulty
67
+ # when we don't pass doc_db but want to validate the yaml ... how do we
68
+ # access the form names other than doc_db._get_form_names()so we can
69
+ # remove `if doc_db is not None:`?
70
+ if doc_db is not None :
71
+ for form_name in doc_db ._get_form_names ():
72
+ self .add_constructor (
73
+ f'!all_forms_{ form_name } ' ,
74
+ data_constructor_dynamic_forms (
75
+ form_name ,
76
+ self .initialize_full_loader ,
77
+ doc_db = doc_db
78
+ )
76
79
)
77
- )
78
80
79
81
return CustomFullLoader
80
82
81
83
82
- def get_basic_yaml_constructors (
83
- initialize_full_loader : bool = False ,
84
- ** kwargs
85
- ):
84
+ def get_basic_yaml_constructors (** kwargs ):
86
85
"""
87
86
This factory is used to build a dictionary of built-in and custom constructors that
88
87
will be used in serialize the internal, dictionary representation of the form config.
@@ -92,31 +91,31 @@ def get_basic_yaml_constructors(
92
91
def type_constructor_int (loader , node ):
93
92
# If initialize_full_loader is not True, then we really
94
93
# don't need to manage any special constructors at all.
95
- return int if initialize_full_loader else ""
94
+ return int
96
95
97
96
def type_constructor_str (loader , node ):
98
- return str if initialize_full_loader else ""
97
+ return str
99
98
100
99
def type_constructor_date (loader , node ):
101
- return date if initialize_full_loader else ""
100
+ return date
102
101
103
102
def type_constructor_datetime (loader , node ):
104
- return datetime if initialize_full_loader else ""
103
+ return datetime
105
104
106
105
def type_constructor_time (loader , node ):
107
- return time if initialize_full_loader else ""
106
+ return time
108
107
109
108
def type_constructor_timedelta (loader , node ):
110
- return timedelta if initialize_full_loader else ""
109
+ return timedelta
111
110
112
111
def type_constructor_list (loader , node ):
113
- return list if initialize_full_loader else ""
112
+ return list
114
113
115
114
def type_constructor_tuple (loader , node ):
116
- return tuple if initialize_full_loader else ""
115
+ return tuple
117
116
118
117
def type_constructor_bytes (loader , node ):
119
- return bytes if initialize_full_loader else ""
118
+ return bytes
120
119
121
120
# We create a constructor mapping that we'll use later to
122
121
# register the constructors.
0 commit comments