Skip to content

Commit

Permalink
task/WP-212 clear notes excep exten edit modal (#189)
Browse files Browse the repository at this point in the history
* Allow notes on extension modal to be cleared

* Allow exception notes to be cleared in edit modal

* Removing diff

* Remove diff

* Diff

* If notes are null, display blank on extension modal

---------

Co-authored-by: edmondsgarrett <[email protected]>
  • Loading branch information
sophia-massie and edmondsgarrett authored Aug 15, 2023
1 parent 1fa10b6 commit e9ff424
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h4 class="modal-header">Edit Selected Extension</h4>

<div class="field-errors" style="display: none"></div>
<textarea name="notes" cols="40" rows="5" class="textinput" type="text" id="notes"
minlength="2" maxlength="2000">{{r.notes}}</textarea>
minlength="2" maxlength="2000">{{r.notes|default:''}}</textarea>
<div class="help-text">
2000 character limit
</div>
Expand Down
25 changes: 14 additions & 11 deletions apcd-cms/src/apps/utils/apcd_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,8 +1181,7 @@ def update_extension(form):
'applicable-data-period': 'applicable_data_period',
'status': 'status',
'outcome': 'outcome',
'approved-expiration-date': 'approved_expiration_date',
'notes': 'notes'
'approved-expiration-date': 'approved_expiration_date'
}
# To make sure fields are not blank.
# If they aren't, add column to update set operation
Expand All @@ -1191,8 +1190,9 @@ def update_extension(form):
if value not in (None, ""):
set_values.append(f"{column_name} = %s")

operation += ", ".join(set_values) + " WHERE extension_id = %s"
## add last update to all extension updates
# to allow notes to be cleared, need to move notes out of the loop that ignores none
operation += ", ".join(set_values) + ", notes = %s WHERE extension_id = %s"
## add last update time to all extension updates
values = [
datetime.now(),
]
Expand All @@ -1206,6 +1206,9 @@ def update_extension(form):
# else server side clean values
else:
values.append(_clean_value(value))

# to allow notes to be cleared, need to move notes out of the loop that ignores none
values.append(_clean_value(form['notes']))
## to make sure extension id is last in query to match with WHERE statement
values.append(_clean_value(form['extension_id']))

Expand All @@ -1217,8 +1220,6 @@ def update_extension(form):
finally:
if cur is not None:
cur.close()
if conn is not None:
conn.close()

def get_submitter_for_extend_or_except(user):
cur = None
Expand Down Expand Up @@ -1383,17 +1384,16 @@ def update_exception(form):
'approved': 'approved_expiration_date',
'status': 'status',
'outcome': 'outcome',
'notes': 'notes'
}
# To make sure fields are not blank.
# If they aren't, add column to update operation
for field, column_name in columns.items():
value = form.get(field)
if value not in (None, ""):
set_values.append(f"{column_name} = %s")

operation += ", ".join(set_values) + " WHERE exception_id = %s"
## add last update to all extension updates
# to allow notes to be cleared, need to move notes out of the loop that ignores none
operation += ", ".join(set_values) + ", notes = %s WHERE exception_id = %s"
## add last update time to all exceptions updates
values = [
datetime.now(),
]
Expand All @@ -1404,9 +1404,12 @@ def update_exception(form):
# to make sure applicable data period field is the right type for insert to DB
if column_name == 'applicable_data_period':
values.append(int(value.replace('-', '')))
# server side clean values
# server side clean values
else:
values.append(_clean_value(value))

# to allow notes to be cleared, need to move notes out of the loop that ignores none
values.append(_clean_value(form['notes']))
## to make sure extension id is last in query to match with WHERE statement
values.append(_clean_value(form['exception_id']))

Expand Down

0 comments on commit e9ff424

Please sign in to comment.