Skip to content

Commit

Permalink
Task/wp11 add remove excep button (#165)
Browse files Browse the repository at this point in the history
* - Updated queries to default to lowercase for
status and request_type.
- Got Add and Remove button working

* - Add and remove exception buttons that populate with AJAX
call to the DB:

* Updated so field type cannont be blank on submission

* Updated query and view to account for iterations
for multiple inserts

* Changed name of justification field per UTH

* Update to let view logic iterate through threshold
requests rather than the DB query

* Removing diff

---------

Co-authored-by: edmondsgarrett <[email protected]>
Co-authored-by: fnets <[email protected]>
  • Loading branch information
3 people committed Jun 1, 2023
1 parent be90a4e commit 0142df5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ <h4>Requested Threshold Reduction</h4>
<div class="field-wrapper numberinput required">
<div class="field-errors" style="display: none"></div>

<label name="date-row" for="expiration-date">Expiriation Date<sup>*</sup><span class="asterisk">*</span> </label>
<label name="date-row" for="expiration-date_1">Expiriation Date<sup>*</sup><span class="asterisk">*</span> </label>

<input type="date" name="expiration-date" class="numeric" id="expiration-date" inputmode="numeric"
<input type="date" name="expiration-date_1" class="numeric" id="expiration-date_1" inputmode="numeric"
pattern="\d{4}-\d{2}-\d{2}" required />
</div>


<div class="field-wrapper numberinput required">
<div class="field-errors" style="display: none"></div>
<label name="date-row" for="threshold-requested">
<label name="date-row" for="threshold-requested_1">
Requested Threshold Percentage <span class="asterisk">*</span>
</label>

<div class="s-affixed-input-wrapper">
<input type="number" name="threshold-requested" class="textinput" id="threshold-requested"
<input type="number" name="threshold-requested_1" class="textinput" id="threshold-requested_1"
inputmode="numeric" min="0" max="99" required />
<span class="s-affixed-input-wrapper__suffix">%</span>
</div>
Expand All @@ -122,7 +122,7 @@ <h4 id="exception_header_5" style="display:none">Requested Threshold Reduction 5
<button class="c-button c-button--secondary" id="exception-drop-btn" type="button">- Remove Last Threshold
Exception</button>
<hr />
<h4>Justification</h4>
<h4>Request Justification</h4>
<div class="field-wrapper textarea required">
<p>Provide rationale for the exception request, outlining the reasons why the
organization is unable to comply with the relevant requirements. Provide as
Expand Down
17 changes: 13 additions & 4 deletions apcd-cms/src/apps/exception/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,20 @@ def post(self, request):

submitter = next(submitter for submitter in submitters if int(submitter[0]) == int(form['business-name']))
if _err_msg(submitter):
errors.append(_err_msg(submitter))
errors.append(_err_msg(submitter))

max_iterations = 1

except_response = apcd_database.create_threshold_exception(form, submitter)
if _err_msg(except_response):
errors.append(_err_msg(except_response))
for i in range(2, 6):
if form.get('field-threshold-exception_{}'.format(i)):
max_iterations += 1
else:
break

for iteration in range(max_iterations):
except_response = apcd_database.create_threshold_exception(form, iteration + 1, submitter)
if _err_msg(except_response):
errors.append(_err_msg(except_response))

if len(errors):
template = loader.get_template(
Expand Down
12 changes: 6 additions & 6 deletions apcd-cms/src/apps/utils/apcd_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ def create_other_exception(form, sub_data):
conn.close()


def create_threshold_exception(form, sub_data):
def create_threshold_exception(form, iteration, sub_data):
cur = None
conn = None
values = ()
Expand Down Expand Up @@ -767,17 +767,17 @@ def create_threshold_exception(form, sub_data):
) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
"""
values = (
form["business-name"],
_clean_value(form["business-name"]),
sub_data[1],
sub_data[2],
sub_data[3],
_clean_value(form['requestor-name']),
_clean_email(form['requestor-email']),
"threshold",
_clean_date(form['expiration-date']),
_clean_date(form['expiration-date_{}'.format(iteration)]),
_clean_value(form['file_type']),
_clean_value(form['field-threshold-exception']),
_clean_value(form['threshold-requested']),
_clean_value(form['field-threshold-exception_{}'.format(iteration)]),
_clean_value(form['threshold-requested_{}'.format(iteration)]),
_clean_value(form['justification']),
"pending"
)
Expand Down Expand Up @@ -1146,7 +1146,7 @@ def get_submitter_for_extend_or_except(user):
FROM submitter_users
JOIN submitters
ON submitter_users.submitter_id = submitters.submitter_id and submitter_users.user_id = (%s)
ORDER BY submitter_users.submitter_id
ORDER BY submitters.apcd_id, submitter_users.submitter_id
"""
cur = conn.cursor()
cur.execute(query, (user,))
Expand Down

0 comments on commit 0142df5

Please sign in to comment.