Skip to content

Commit

Permalink
Fix #428
Browse files Browse the repository at this point in the history
  • Loading branch information
aebruno committed Jul 7, 2022
1 parent 5ea5784 commit eec2d5f
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions coldfront/core/allocation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2204,6 +2204,7 @@ def post(self, request, *args, **kwargs):
allocation_attributes_to_change = self.get_allocation_attributes_to_change(
allocation_obj)

# TODO: this logic is a mess. Needs to be cleaned up
if allocation_attributes_to_change:
formset = formset_factory(self.formset_class, max_num=len(
allocation_attributes_to_change))
Expand All @@ -2213,7 +2214,8 @@ def post(self, request, *args, **kwargs):
if form.is_valid() and formset.is_valid():
form_data = form.cleaned_data

if form_data.get('end_date_extension') != 0: change_requested = True
if form_data.get('end_date_extension') != 0:
change_requested = True

for entry in formset:
formset_data = entry.cleaned_data
Expand Down Expand Up @@ -2307,30 +2309,29 @@ def post(self, request, *args, **kwargs):
messages.success(
request, 'Allocation change request successfully submitted.')

pi_name = '{} {} ({})'.format(allocation_obj.project.pi.first_name,
allocation_obj.project.pi.last_name, allocation_obj.project.pi.username)
resource_name = allocation_obj.get_parent_resource
domain_url = get_domain_url(self.request)
url = '{}{}'.format(domain_url, reverse('allocation-change-list'))
pi_name = '{} {} ({})'.format(allocation_obj.project.pi.first_name,
allocation_obj.project.pi.last_name, allocation_obj.project.pi.username)
resource_name = allocation_obj.get_parent_resource
domain_url = get_domain_url(self.request)
url = '{}{}'.format(domain_url, reverse('allocation-change-list'))

if EMAIL_ENABLED:
template_context = {
'pi': pi_name,
'resource': resource_name,
'url': url
}
if EMAIL_ENABLED:
template_context = {
'pi': pi_name,
'resource': resource_name,
'url': url
}

send_email_template(
'New Allocation Change Request: {} - {}'.format(
pi_name, resource_name),
'email/new_allocation_change_request.txt',
template_context,
EMAIL_SENDER,
[EMAIL_TICKET_SYSTEM_ADDRESS, ]
)
send_email_template(
'New Allocation Change Request: {} - {}'.format(
pi_name, resource_name),
'email/new_allocation_change_request.txt',
template_context,
EMAIL_SENDER,
[EMAIL_TICKET_SYSTEM_ADDRESS, ]
)

return HttpResponseRedirect(reverse('allocation-detail', kwargs={'pk': pk}))

else:
messages.error(request, 'You must request a change.')
return HttpResponseRedirect(reverse('allocation-change', kwargs={'pk': pk}))
Expand Down

0 comments on commit eec2d5f

Please sign in to comment.