Skip to content

Commit

Permalink
add contextvar magic
Browse files Browse the repository at this point in the history
small js optimisation
  • Loading branch information
SamDudley committed Nov 25, 2024
1 parent b2620b0 commit 2c49efb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
10 changes: 10 additions & 0 deletions core/utils/generic_helpers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import datetime
from contextvars import ContextVar

from django.contrib.admin.models import CHANGE, LogEntry
from django.contrib.contenttypes.models import ContentType

from core.models import FinancialYear


_current_financial_year = ContextVar("current_financial_year", default=None)


def get_current_financial_year():
# FIXME: decide if to include this
if var := _current_financial_year.get():
return var

y = FinancialYear.objects.filter(current=True)
if y:
current_financial_year = y.last().financial_year
Expand All @@ -27,6 +35,8 @@ def get_current_financial_year():
# calendar year
current_financial_year -= 1

_current_financial_year.set(current_financial_year)

return current_financial_year


Expand Down
4 changes: 2 additions & 2 deletions forecast/views/edit_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ class EditForecastView(
def class_name(self):
return "wide-table"

# FIXME: might be risky
# FIXME: Triple check this is safe
@cached_property
def cost_centre_details(self):
cost_centre = CostCentre.objects.select_related("directorate__group").get(
Expand Down Expand Up @@ -532,7 +532,7 @@ def get_payroll_forecast_report(self):

return data

@property
@cached_property
def future_year_display(self):
if self._future_year_display is None:
current_year = get_current_financial_year()
Expand Down
5 changes: 3 additions & 2 deletions front_end/src/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ function getCookie(name) {
return cookieValue;
}

const NumberFormat = new Intl.NumberFormat('en-GB');

export const formatValue = (value) => {
let nfObject = new Intl.NumberFormat('en-GB');
let pounds = Math.round(value)
return nfObject.format(pounds);
return NumberFormat.format(pounds);
}

/**
Expand Down

0 comments on commit 2c49efb

Please sign in to comment.