Skip to content

Commit

Permalink
Merge pull request #10309 from archesproject/10250_fix_edtf_error_msg
Browse files Browse the repository at this point in the history
Fix edtf advanced search error message
  • Loading branch information
chrabyrd authored Nov 29, 2023
2 parents d87c16e + 2daf796 commit 81f4b1e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
24 changes: 15 additions & 9 deletions arches/app/datatypes/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,21 +553,25 @@ def add_date_to_doc(document, edtf):

def append_search_filters(self, value, node, query, request):
def add_date_to_doc(query, edtf):
invalid_filter_exception = Exception(
_(
'Only dates that specify an exact year, month, \
and day can be used with the "=", ">", "<", ">=", and "<=" operators'
)
)

if value["op"] == "eq":
if edtf.lower != edtf.upper:
raise Exception(_('Only dates that specify an exact year, month, and day can be used with the "=" operator'))
query.should(Match(field="tiles.data.%s.dates.date" % (str(node.pk)), query=edtf.lower, type="phrase_prefix"))
raise invalid_filter_exception
else:
operators = {"gte": edtf.lower, "lte": edtf.lower}
query.must(Range(field="tiles.data.%s.dates.date" % (str(node.pk)), **operators))
else:
if value["op"] == "overlaps":
operators = {"gte": edtf.lower, "lte": edtf.upper}
else:
if edtf.lower != edtf.upper:
raise Exception(
_(
'Only dates that specify an exact year, month, \
and day can be used with the ">", "<", ">=", and "<=" operators'
)
)
raise invalid_filter_exception

operators = {value["op"]: edtf.lower or edtf.upper}

Expand All @@ -580,7 +584,9 @@ def add_date_to_doc(query, edtf):
if edtf.lower is None and edtf.upper is None:
raise Exception(_("Invalid date specified."))

if value["op"] == "null" or value["op"] == "not_null":
if not value.get('op'):
pass
elif value["op"] == "null" or value["op"] == "not_null":
self.append_null_search_filters(value, node, query, request)
elif value["val"] != "" and value["val"] is not None:
edtf = ExtendedDateFormat(value["val"])
Expand Down
3 changes: 2 additions & 1 deletion arches/app/media/js/views/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ define([
this.viewModel.alert(false);
},
error: function(response, status, error) {
const alert = new AlertViewModel('ep-alert-red', arches.requestFailed.title, response.responseJSON?.message);
if(this.updateRequest.statusText !== 'abort'){
this.viewModel.alert(new AlertViewModel('ep-alert-red', arches.requestFailed.title, response.responseText));
this.viewModel.alert(alert);
}
},
complete: function(request, status) {
Expand Down
2 changes: 1 addition & 1 deletion arches/app/views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def search_results(request, returnDsl=False):
append_instance_permission_filter_dsl(request, search_results_object)
except Exception as err:
logger.exception(err)
return JSONErrorResponse(message=err)
return JSONErrorResponse(message=str(err))

dsl = search_results_object.pop("query", None)
if returnDsl:
Expand Down

0 comments on commit 81f4b1e

Please sign in to comment.