Skip to content

Commit

Permalink
Merge pull request #430 from ubccr/allocation-change-error-fix
Browse files Browse the repository at this point in the history
Allocation change error fix
  • Loading branch information
aebruno authored Jul 7, 2022
2 parents 5ea5784 + 48bd502 commit a4053af
Show file tree
Hide file tree
Showing 2 changed files with 28 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
6 changes: 6 additions & 0 deletions coldfront/core/utils/management/commands/load_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ def handle(self, *args, **options):
status=AllocationStatusChoice.objects.get(name='Active'),
start_date=start_date,
end_date=end_date,
is_changeable=True,
justification='I need access to my nodes.'
)

Expand Down Expand Up @@ -305,6 +306,7 @@ def handle(self, *args, **options):
status=AllocationStatusChoice.objects.get(name='Active'),
start_date=start_date,
end_date=datetime.datetime.now() + relativedelta(days=10),
is_changeable=True,
justification='I need access to university cluster.'
)

Expand Down Expand Up @@ -359,6 +361,7 @@ def handle(self, *args, **options):
start_date=start_date,
end_date=end_date,
quantity=10,
is_changeable=True,
justification='I need extra storage.'
)

Expand All @@ -378,6 +381,7 @@ def handle(self, *args, **options):
status=AllocationStatusChoice.objects.get(name='Active'),
start_date=start_date,
end_date=end_date,
is_changeable=True,
justification='I need compute time on metered cluster.'
)
allocation_obj.resources.add(
Expand Down Expand Up @@ -484,6 +488,7 @@ def handle(self, *args, **options):
status=AllocationStatusChoice.objects.get(name='Active'),
start_date=start_date,
end_date=end_date,
is_changeable=True,
justification='Need to host my own site.'
)

Expand Down Expand Up @@ -520,6 +525,7 @@ def handle(self, *args, **options):
status=AllocationStatusChoice.objects.get(name='Active'),
start_date=start_date,
end_date=end_date,
is_changeable=True,
justification='Need extra storage for webserver.'
)

Expand Down

0 comments on commit a4053af

Please sign in to comment.