@@ -203,6 +203,7 @@ def _initialize_metadata_fields(self):
203
203
self .ip_address_field = "ip_address"
204
204
self .created_by_field = "created_by"
205
205
self .signature_field = "signatures"
206
+ self .form_stage_field = "form_stage"
206
207
self .last_editor_field = "last_editor"
207
208
# self.approved_field = "approved"
208
209
# self.approved_by_field = "approved_by"
@@ -223,6 +224,7 @@ def _initialize_metadata_fields(self):
223
224
self .ip_address_field ,
224
225
self .created_by_field ,
225
226
self .signature_field ,
227
+ self .form_stage_field ,
226
228
self .last_editor_field ,
227
229
# self.approved_field,
228
230
# self.approved_by_field,
@@ -296,6 +298,12 @@ def get_all_documents(self, form_name:str, exclude_deleted:bool=True):
296
298
"""Retrieves all entries from the specified form's database."""
297
299
pass
298
300
301
+
302
+ @abstractmethod
303
+ def get_all_documents_by_stage (self , form_name :str , stage_name :str , exclude_deleted :bool = True ):
304
+ """Retrieves all entries from the specified form's database when they reside in a specified stage."""
305
+ pass
306
+
299
307
@abstractmethod
300
308
def get_one_document (self , form_name :str , search_query , exclude_deleted :bool = True ):
301
309
"""Retrieves a single entry that matches the search query."""
@@ -1090,6 +1098,33 @@ def get_all_documents(
1090
1098
1091
1099
return documents
1092
1100
1101
+ def get_all_documents_by_stage (
1102
+ self ,
1103
+ form_name :str ,
1104
+ stage_name :str ,
1105
+ exclude_deleted :bool = True
1106
+ ) -> list :
1107
+ """Retrieves all entries from the specified form's database where metadata['form_stage'] equals stage_name."""
1108
+
1109
+ # Ensure the form exists in the configuration
1110
+ self ._check_form_exists (form_name )
1111
+
1112
+ # Query the database for documents with the specified stage_name. I'm using Query here,
1113
+ # which I don't do very often. Considering pivoting to just using straight python logic instead...
1114
+ query = (self .Form .metadata ['form_stage' ] == stage_name )
1115
+
1116
+ if exclude_deleted :
1117
+ query &= (self .Form .metadata [self .is_deleted_field ] == False )
1118
+
1119
+ documents = self .databases [form_name ].search (query )
1120
+
1121
+ # Construct a list of Document IDs ... this is better for caching because
1122
+ # other form data might change without needing to trigger cache invalidation...
1123
+ # So, storing the full document is alluring, but will lead to unwise assumptions.
1124
+ document_ids = [x .doc_id for x in documents ]
1125
+
1126
+ return document_ids
1127
+
1093
1128
def get_one_document (
1094
1129
self ,
1095
1130
form_name :str ,
0 commit comments