Skip to content

Commit

Permalink
Add a clean method for form validation #98
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <tdruez@nexb.com>
  • Loading branch information
tdruez committed Nov 29, 2024
1 parent b50365f commit 1fe4c2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions product_portfolio/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,3 +990,10 @@ def helper(self):
helper.modal_title = "Vulnerability analysis"
helper.modal_id = "vulnerability-analysis-modal"
return helper

def clean(self):
main_fields = ["state", "justification", "responses", "detail"]
if not any(self.cleaned_data.get(field_name) for field_name in main_fields):
raise ValidationError(
"At least one of state, justification, responses or detail must be provided."
)
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@
{% if tabsets.Imports %}
{% include 'product_portfolio/includes/scancode_project_status_modal.html' %}
{% endif %}
{% include 'product_portfolio/modals/vulnerability_analysis_modal.html' %}
{% if request.user.dataspace.enable_vulnerablecodedb_access and not tabsets.Vulnerabilities.disabled %}
{% include 'product_portfolio/modals/vulnerability_analysis_modal.html' %}
{% endif %}
{% endblock %}

{% block extrastyle %}
Expand Down Expand Up @@ -233,7 +235,7 @@
</script>
{% endif %}

{% if request.user.dataspace.enable_vulnerablecodedb_access %}
{% if request.user.dataspace.enable_vulnerablecodedb_access and not tabsets.Vulnerabilities.disabled %}
<script>
$(document).ready(function () {
let vulnerability_modal = $('#vulnerability-analysis-modal');
Expand Down

0 comments on commit 1fe4c2c

Please sign in to comment.