Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
jag1g13 committed Jan 23, 2020
2 parents 0535bf9 + 1172813 commit be6da60
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 64 deletions.
19 changes: 6 additions & 13 deletions lowfat/forms.py
Expand Up @@ -9,7 +9,6 @@
EmailField,
FileField,
Form,
HiddenInput,
ModelForm,
Select,
SelectMultiple,
Expand Down Expand Up @@ -287,6 +286,7 @@ class Meta:
"added",
"approved",
"updated",
"approval_chain",
]

labels = {
Expand Down Expand Up @@ -323,7 +323,6 @@ class Meta:
usel10n=True,
bootstrap_version=3
),
'approval_chain': HiddenInput,
}


Expand Down Expand Up @@ -441,9 +440,6 @@ def __init__(self, *args, **kwargs):
self.fields['focus'].widget.choices.insert(0, ('', '---------'))
self.fields['focus'].initial = ''

# For non-public funds use fellows approval chain
self.fields['approval_chain'].initial = ApprovalChain.FELLOWS


class FundPublicForm(GarlicForm):
forenames = CharField(
Expand Down Expand Up @@ -504,6 +500,7 @@ class Meta:
"added",
"approved",
"updated",
"approval_chain",
]

labels = {
Expand Down Expand Up @@ -539,7 +536,6 @@ class Meta:
usel10n=True,
bootstrap_version=3
),
'approval_chain': HiddenInput,
}


Expand Down Expand Up @@ -656,9 +652,6 @@ def __init__(self, *args, **kwargs):
self.fields['focus'].widget.choices.insert(0, ('', '---------'))
self.fields['focus'].initial = ''

# For public funds use onetime request approval chain
self.fields['approval_chain'].initial = ApprovalChain.ONE_TIME


class FundGDPRForm(GarlicForm):
class Meta:
Expand Down Expand Up @@ -881,7 +874,7 @@ def __init__(self, *args, **kwargs):
if "initial" in kwargs and "fund" in kwargs["initial"]:
self.fields['fund'].queryset = Fund.objects.filter(id=kwargs["initial"]["fund"].id)
else:
self.fields['fund'].queryset = Fund.objects.filter(status__in=['A'])
self.fields['fund'].queryset = Fund.objects.filter(status__in=FUND_STATUS_APPROVED_SET)

class ExpenseShortlistedForm(GarlicForm):
class Meta:
Expand Down Expand Up @@ -930,7 +923,7 @@ def __init__(self, *args, **kwargs):
)
)

self.fields['fund'].queryset = Fund.objects.filter(status__in={'A', 'M'})
self.fields['fund'].queryset = Fund.objects.filter(status__in=FUND_STATUS_APPROVED_SET)


class ExpenseReviewForm(GarlicForm):
Expand Down Expand Up @@ -1062,10 +1055,10 @@ def __init__(self, *args, user=None, **kwargs):
if "initial" in kwargs and "fund" in kwargs["initial"]:
self.fields['fund'].queryset = Fund.objects.filter(id=kwargs["initial"]["fund"].id)
else:
self.fields['fund'].queryset = Fund.objects.filter(status__in=['A'])
self.fields['fund'].queryset = Fund.objects.filter(status__in=FUND_STATUS_APPROVED_SET)

if user:
self.fields['fund'].queryset = Fund.objects.filter(status__in=['A'])
self.fields['fund'].queryset = Fund.objects.filter(status__in=FUND_STATUS_APPROVED_SET)

if self.is_staff:
# Force staff to select one author
Expand Down
43 changes: 21 additions & 22 deletions lowfat/management/commands/fixstatus.py
Expand Up @@ -2,7 +2,7 @@

from django.core.management.base import BaseCommand

from lowfat.models import Fund, Expense
from lowfat.models import FUND_STATUS_APPROVED_SET, Fund, Expense

class Command(BaseCommand):
help = "Fix the status on the database."
Expand All @@ -16,27 +16,26 @@ def handle(self, *args, **options):

# Fund status
# Move approved to archived
for fund in Fund.objects.all():
if fund.status == "A":
day = datetime.timedelta(1)
if fund.added - datetime.datetime(2017, 12, 31) < day:
# Check for expenses
# Check for blog posts
for fund in Fund.objects.filter(status__in=FUND_STATUS_APPROVED_SET).all():
day = datetime.timedelta(1)
if fund.added - datetime.datetime(2017, 12, 31) < day:
# Check for expenses
# Check for blog posts
print("Changing status for {}".format(fund))
fund.status = "F"
fund.save()
else:
can_be_archive = True
expenses = Expense.objects.filter(
fund=fund,
)
if not expenses:
can_be_archive = False
for expense in expenses:
if expense.status in ["S", "C"]:
can_be_archive = False
break
if can_be_archive:
print("Changing status for {}".format(fund))
fund.status = "F"
fund.save()
else:
can_be_archive = True
expenses = Expense.objects.filter(
fund=fund,
)
if not expenses:
can_be_archive = False
for expense in expenses:
if expense.status in ["S", "C"]:
can_be_archive = False
break
if can_be_archive:
print("Changing status for {}".format(fund))
fund.status = "F"
fund.save()
32 changes: 19 additions & 13 deletions lowfat/models.py
Expand Up @@ -88,6 +88,12 @@ class TagMeta:
('X', 'Remove'), # When the fellow decided to remove their request.
)

#: Set of statuses which constitute an approved fund
FUND_STATUS_APPROVED_SET = {
'A',
'M',
}

FUND_STATUS_LONG_DESCRIPTION = {
'U': "We didn't start to process your request yet.",
'P': "One of your staffs is reviewing your request. You should have our reply soon.",
Expand Down Expand Up @@ -521,43 +527,43 @@ def fullname_link(self):
)

def claimantship_available(self):
"""Return the remain claimantship grant."""
"""Return the remaining claimantship grant."""
money_available = 0
if self.inauguration_grant_expiration > date.today():
money_available = self.claimantship_grant - self.claimantship_committed() - self.claimantship_spent()

return money_available

def claimantship_passed(self):
"""Return the ammount alread spent from the claimantship grant."""
"""Return the amount already spent from the claimantship grant."""
money_passed = 0
if self.inauguration_grant_expiration < date.today():
money_passed = self.claimantship_grant - self.claimantship_committed() - self.claimantship_spent()

return money_passed

def claimantship_committed(self):
"""Return the ammount committed from the claimantship grant."""
"""Return the amount committed from the claimantship grant."""
this_claimant_funds = Fund.objects.filter(
claimant=self,
status__in=['A'],
status__in=FUND_STATUS_APPROVED_SET,
grant_heading="F"
)

spent_from_committed = 0
for fund in this_claimant_funds:
spent_from_committed += sum([expense.amount_claimed for expense in Expense.objects.filter(
fund=fund,
status__in=['A', 'F']
status__in=['A', 'M', 'F']
)])

return sum([fund.budget_approved for fund in this_claimant_funds]) - spent_from_committed

def claimantship_spent(self):
"""Return the ammount alread spent from the claimantship grant."""
"""Return the amount already spent from the claimantship grant."""
this_claimant_expenses = Expense.objects.filter(
fund__claimant=self,
status__in=['A', 'F'],
status__in=['A', 'M', 'F'],
grant_heading="F"
)

Expand Down Expand Up @@ -746,7 +752,7 @@ def save(self, *args, **kwargs): # pylint: disable=arguments-differ
else:
self.grant_heading = "C"

if self.status == "A":
if self.status in FUND_STATUS_APPROVED_SET:
self.approved = datetime.now()

if self.required_blog_posts is None:
Expand Down Expand Up @@ -797,22 +803,22 @@ def budget_total(self):
)

def expenses_claimed(self):
"""Return the total ammount of expenses claimant."""
"""Return the total amount of expenses claimant."""
this_fund_expenses = Expense.objects.filter(
fund=self,
status__in=["S", "C", "A"]
status__in=["S", "C", "A", "M"]
)
return sum([expense.amount_claimed for expense in this_fund_expenses])

def expenses_claimed_left(self):
"""Return the total ammount left to claimant."""
"""Return the total amount left to claimant."""
return self.budget_total() - self.expenses_claimed()

def expenses_authorized_for_payment(self):
"""Return the total ammount of expenses authorized_for_payment."""
"""Return the total amount of expenses authorized_for_payment."""
this_fund_expenses = Expense.objects.filter(
fund=self,
status__in=["A"]
status__in=FUND_STATUS_APPROVED_SET
)
return sum([expense.amount_authorized_for_payment for expense in this_fund_expenses])

Expand Down
2 changes: 1 addition & 1 deletion lowfat/settings.py
Expand Up @@ -15,7 +15,7 @@


URL_SRC = "https://github.com/softwaresaved/lowfat"
VERSION = "1.18.0"
VERSION = "1.18.1"

SETTINGS_EXPORT = [
'URL_SRC',
Expand Down
4 changes: 2 additions & 2 deletions lowfat/templates/lowfat/funds.html
@@ -1,13 +1,13 @@
{% if user.is_staff %}
<ul class="nav nav-tabs">
<li role="presentation" {% if funding_requests_status == 'UPAMRF' %}class="active"{% endif %}>
<a href="?funding_requests=UPARF&expenses={{ expenses_status }}&blogs={{ blogs_status }}">All</a>
<a href="?funding_requests=UPAMRF&expenses={{ expenses_status }}&blogs={{ blogs_status }}">All</a>
</li>
<li role="presentation" {% if funding_requests_status == 'UP' %}class="active"{% endif %}>
<a href="?funding_requests=UP&expenses={{ expenses_status }}&blogs={{ blogs_status }}">Pending</a>
</li>
<li role="presentation" {% if funding_requests_status == 'AM' %}class="active"{% endif %}>
<a href="?funding_requests=A&expenses={{ expenses_status }}&blogs={{ blogs_status }}">Approved</a>
<a href="?funding_requests=AM&expenses={{ expenses_status }}&blogs={{ blogs_status }}">Approved</a>
</li>
<li role="presentation" {% if funding_requests_status == 'R' %}class="active"{% endif %}>
<a href="?funding_requests=R&expenses={{ expenses_status }}&blogs={{ blogs_status }}">Rejected</a>
Expand Down
36 changes: 23 additions & 13 deletions lowfat/views.py
Expand Up @@ -108,7 +108,9 @@ def dashboard(request):
if not request.user.is_staff:
try:
claimant = Claimant.objects.get(user=request.user)
except: # pylint: disable=bare-except

except Claimant.DoesNotExist:
logger.warning('No claimant found for user %s', request.user.username)
return HttpResponseRedirect(reverse('django.contrib.flatpages.views.flatpage', kwargs={'url': '/welcome/'}))

# Setup query parameters
Expand Down Expand Up @@ -358,7 +360,7 @@ def _claimant_detail(request, claimant):
funds = Fund.objects.filter(
claimant=claimant,
can_be_advertise_after=True,
status__in="AMF"
status__in=FUND_STATUS_APPROVED_SET
)
context.update(
{
Expand Down Expand Up @@ -459,6 +461,9 @@ def fund_form(request, **kargs): # pylint: disable=too-many-branches,too-many-s
if request.POST:
# Handle submission
if formset.is_valid():
# Use Fellows approval chain for requests using this form
formset.instance.approval_chain = ApprovalChain.FELLOWS

fund = formset.save()
messages.success(request, 'Funding request saved.')
if not formset.cleaned_data["not_send_email_field"]:
Expand Down Expand Up @@ -518,6 +523,9 @@ def fund_form_public(request):
)

if request.POST and formset.is_valid():
# Use One-Time approval chain for requests using this form
formset.instance.approval_chain = ApprovalChain.ONE_TIME

# Handle submission
username = "{}.{}".format(
formset.cleaned_data["forenames"].lower(),
Expand Down Expand Up @@ -634,7 +642,7 @@ def fund_review(request, fund_id):

if formset.is_valid():
fund = formset.save()
if fund.status in "AM" and fund.approver == None: # pylint: disable=singleton-comparison
if fund.status in FUND_STATUS_APPROVED_SET and fund.approver == None: # pylint: disable=singleton-comparison
fund.approver = request.user
fund.save()
messages.success(request, 'Funding request updated.')
Expand Down Expand Up @@ -701,7 +709,7 @@ def fund_past(request):
funds = Fund.objects.filter(
start_date__lt=django.utils.timezone.now(),
category="H",
status__in="AMF",
status__in=FUND_STATUS_APPROVED_SET,
can_be_advertise_after=True,
)

Expand Down Expand Up @@ -755,18 +763,18 @@ def fund_import(request):

@login_required
def expense_form(request, **kargs):
# Setup Expense to edit if provide
# Setup Expense to edit if provided
expense_to_edit = None

if "fund_id" in kargs and "expense_relative_number" in kargs:
try:
expense_to_edit = Expense.objects.get(
fund__id=kargs["fund_id"],
relative_number=kargs["expense_relative_number"]
)
except: # pylint: disable=bare-except
expense_to_edit = None

except Expense.DoesNotExist:
messages.error(request, "The expense that you want to edit doesn't exist.")
else:
expense_to_edit = None

# Setup Fund if provided
fund_id = request.GET.get("fund_id")
Expand All @@ -781,8 +789,10 @@ def expense_form(request, **kargs):

try:
claimant = Claimant.objects.get(user=request.user)
except: # pylint: disable=bare-except

except Claimant.DoesNotExist:
claimant = None

if claimant and not claimant.fellow:
formset = ExpenseShortlistedForm(
request.POST or None,
Expand Down Expand Up @@ -822,7 +832,7 @@ def expense_form(request, **kargs):
return HttpResponseRedirect(reverse('django.contrib.flatpages.views.flatpage', kwargs={'url': '/unavailable/'}))
formset.fields["fund"].queryset = Fund.objects.filter(
claimant__in=claimant,
status__in=['A']
status__in=FUND_STATUS_APPROVED_SET
)

# Show submission form.
Expand Down Expand Up @@ -1149,13 +1159,13 @@ def blog_form(request, **kargs): # pylint: disable=too-many-branches
return HttpResponseRedirect(reverse('django.contrib.flatpages.views.flatpage', kwargs={'url': '/unavailable/'}))
formset.fields["fund"].queryset = Fund.objects.filter(
claimant=claimant,
status__in=['A']
status__in=FUND_STATUS_APPROVED_SET
)
elif request.GET.get("claimant_id"):
claimant = Claimant.objects.get(id=request.GET.get("claimant_id"))
formset.fields["fund"].queryset = Fund.objects.filter(
claimant=claimant,
status__in=['A']
status__in=FUND_STATUS_APPROVED_SET
)

# Show submission form.
Expand Down

0 comments on commit be6da60

Please sign in to comment.