Skip to content

Commit

Permalink
Remove maintenance element if no description or frequency.
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-ide committed Dec 10, 2024
1 parent 5d075b7 commit 03bd786
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions webapp/views/maintenance/maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,21 @@ def populate_maintenance_form(form: MaintenanceForm, maintenance_node: Node):
return redirect(url)

if request.method == 'POST' and form.validate_on_submit():
save = False
if is_dirty_form(form):
save = True

if save:
maintenace_description = form.description.data
valid, msg = is_valid_xml_fragment(maintenace_description, names.MAINTENANCE)
if not valid:
flash(invalid_xml_error_message(msg, False, names.DESCRIPTION), 'error')
return render_get_maintenance_page(eml_node, form, filename)

update_frequency = form.update_frequency.data
create_maintenance(dataset_node, maintenace_description, update_frequency)
save_both_formats(filename=filename, eml_node=eml_node)
# Rather than check if the form is dirty, we're going to go ahead and save the form.
# The reason is this: if the maintenance description consists of whitespace only, or whitespace
# plus one or more paras containing only whitespace, the form will be not considered dirty, and
# we want to be able to clear out such content. A reason why that matters is that if the description
# and update frequency are both empty, the maintenance item should not have a badge. So fully clearing it
# out is important to be able to do.
maintenace_description = form.description.data
valid, msg = is_valid_xml_fragment(maintenace_description, names.MAINTENANCE)
if not valid:
flash(invalid_xml_error_message(msg, False, names.DESCRIPTION), 'error')
return render_get_maintenance_page(eml_node, form, filename)

update_frequency = form.update_frequency.data
create_maintenance(dataset_node, maintenace_description, update_frequency)
save_both_formats(filename=filename, eml_node=eml_node)

form_value = request.form
form_dict = form_value.to_dict(flat=False)
Expand Down

0 comments on commit 03bd786

Please sign in to comment.