Skip to content

Commit

Permalink
backend validation of mutually inclusive criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinDo committed Dec 19, 2023
1 parent ec2bfbf commit aee5d4b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/frontend_celery/webapp/variant/variant_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,15 @@ def is_valid_scheme(selected_criteria, scheme):

all_selected_criteria_names = [selected_criteria[x]['criterium_name'] for x in selected_criteria if selected_criteria[x]['is_selected']]

mutually_inclusive_target_to_source = {}
for source in scheme_criteria:
current_mutually_inclusive_criteria = scheme_criteria[source]["mutually_inclusive_criteria"]
for target in current_mutually_inclusive_criteria:
functions.extend_dict(mutually_inclusive_target_to_source, target, source)

print(mutually_inclusive_target_to_source)
print(selected_criteria)

# ensure that only valid criteria were submitted
for criterium_id in selected_criteria:
current_criterium = selected_criteria[criterium_id]
Expand Down Expand Up @@ -425,6 +434,12 @@ def is_valid_scheme(selected_criteria, scheme):
is_valid = False
message = "A mutually exclusive criterium to " + str(criterium_name) + " was selected. Remember to not select " + str(criterium_name) + " together with any of " + str(current_mutually_exclusive_criteria) + ". The classification was not submitted."
break
# ensure that mutually inclusive criteria were only selected when their target is present
current_mutually_inclusive_sources = mutually_inclusive_target_to_source.get(criterium_name, [])
if not all([x in all_selected_criteria_names for x in current_mutually_inclusive_sources]):
is_valid = False
message = "If you want to select " + str(criterium_name) + " You also have to provide evidence for " + str(current_mutually_inclusive_sources) + ". The classification was not submitted."
break

return is_valid, message

Expand Down

0 comments on commit aee5d4b

Please sign in to comment.