Skip to content

Commit

Permalink
Modified: metadata document structure (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
signebedi committed Mar 24, 2024
1 parent 5e89ebe commit c6b47f7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libreforms_fastapi/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ async def api_form_search(form_name: str, background_tasks: BackgroundTasks, req
if form_name not in get_form_names():
raise HTTPException(status_code=404, detail=f"Form '{form_name}' not found")

if search_term is None:
if search_term is None or len(search_term) == 0:
return {"error": "No search term provided"}

# Ugh, I'd like to find a more efficient way to get the user data. But alas, that
Expand Down
6 changes: 2 additions & 4 deletions libreforms_fastapi/utils/document_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ def create_document(self, form_name:str, json_data, metadata={}):
"metadata": {
# self.document_id_field: document_id,
self.is_deleted_field: metadata.get(self.is_deleted_field, False),
self.document_id_field: document_id,
self.form_name_field: form_name,
self.timezone_field: metadata.get(self.timezone_field, self.timezone.key),
self.created_at_field: metadata.get(self.created_at_field, current_timestamp.isoformat()),
self.last_modified_field: metadata.get(self.last_modified_field, current_timestamp.isoformat()),
Expand Down Expand Up @@ -393,10 +395,6 @@ def fuzzy_search_documents(self, search_term:str, limit_users:Union[bool, dict]=
elif isinstance(limit_users[f], str):
d = [x for x in d if x['metadata'][self.created_by_field] == limit_users[f]]

for item in d:
item['metadata'][self.document_id_field] = item.doc_id
item['metadata'][self.form_name_field] = f

data.extend(d)


Expand Down

0 comments on commit c6b47f7

Please sign in to comment.