Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Description Bug when Approving an Allocation Request #455

Merged
merged 5 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion coldfront/core/allocation/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def clean(self):
start_date = cleaned_data.get("start_date")
end_date = cleaned_data.get("end_date")

if start_date and end_date < start_date:
if start_date and end_date and end_date < start_date:
raise forms.ValidationError(
'End date cannot be less than start date'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ <h3><i class="fas fa-list" aria-hidden="true"></i> Allocation Information</h3>
{% if request.user.is_superuser %}
<div class="float-right">
{% if allocation.status.name == 'New' or allocation.status.name == 'Renewal Requested' %}
<a href="{% url 'allocation-activate-request' allocation.pk %}" class="btn btn-success mr-1 confirm-activate">Approve</a>
<a href="{% url 'allocation-deny-request' allocation.pk %}" class="btn btn-danger mr-1 confirm-deny">Deny</a>
<button name="approved" class="btn btn-success mr-1 confirm-activate">Approve</button>
<button name="denied" class="btn btn-danger mr-1 confirm-deny">Deny</button>
{% endif %}
<button type="submit" class="btn btn-primary"><i class="fas fa-sync" aria-hidden="true"></i> Update</button>
{% endif %}
Expand Down
29 changes: 24 additions & 5 deletions coldfront/core/allocation/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import logging
from datetime import date
import json

from dateutil.relativedelta import relativedelta
from django import forms
Expand Down Expand Up @@ -209,11 +210,19 @@ def post(self, request, *args, **kwargs):

if start_date and allocation_obj.start_date != start_date:
allocation_obj.start_date = start_date


if end_date and allocation_obj.end_date != end_date:
allocation_obj.end_date = end_date

allocation_obj.save()

if 'approved' in request.POST:
return HttpResponseRedirect(reverse('allocation-activate-request', kwargs={'pk': pk}))

if 'denied' in request.POST:
return HttpResponseRedirect(reverse('allocation-deny-request', kwargs={'pk': pk}))

if old_status != 'Active' == new_status:
if not start_date:
start_date = datetime.datetime.now()
Expand Down Expand Up @@ -948,13 +957,23 @@ def get(self, request, pk):

allocation_status_active_obj = AllocationStatusChoice.objects.get(
name='Active')
start_date = datetime.datetime.now()
end_date = datetime.datetime.now(
) + relativedelta(days=ALLOCATION_DEFAULT_ALLOCATION_LENGTH)
if allocation_obj.start_date == None and allocation_obj.end_date == None:
start_date = datetime.datetime.now()
end_date = datetime.datetime.now(
) + relativedelta(days=ALLOCATION_DEFAULT_ALLOCATION_LENGTH)
allocation_obj.start_date = start_date
allocation_obj.end_date = end_date

if allocation_obj.start_date != None and allocation_obj.end_date == None:
end_date = allocation_obj.start_date + relativedelta(days=ALLOCATION_DEFAULT_ALLOCATION_LENGTH)
allocation_obj.end_date = end_date

if allocation_obj.start_date == None and allocation_obj.end_date != None:
if ((allocation_obj.end_date - relativedelta(days=ALLOCATION_DEFAULT_ALLOCATION_LENGTH)) >= datetime.datetime.now().date()):
start_date = allocation_obj.end_date - relativedelta(days=ALLOCATION_DEFAULT_ALLOCATION_LENGTH)
allocation_obj.start_date = start_date

allocation_obj.status = allocation_status_active_obj
allocation_obj.start_date = start_date
allocation_obj.end_date = end_date
allocation_obj.save()

messages.success(request, 'Allocation to {} has been ACTIVATED for {} {} ({})'.format(
Expand Down