Use timezone aware date for document statistics

Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-11-15 17:56:14 -04:00
parent c14a98b78e
commit 27d3661017
2 changed files with 32 additions and 26 deletions

View File

@@ -18,6 +18,7 @@
to John Bentley (@johnbentleyii) for the report.
- Add missing Event class cache invalidation when
calling the refresh() method.
- Use timezone aware date for document statistics.
3.2.9 (2019-11-03)
==================

View File

@@ -1,8 +1,7 @@
from __future__ import absolute_import, unicode_literals
import datetime
from django.apps import apps
from django.utils import timezone
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _
@@ -26,14 +25,14 @@ def new_documents_per_month():
qss = qsstats.QuerySetStats(Document.passthrough.all(), 'date_added')
today = datetime.date.today()
this_year = datetime.date(year=today.year, month=1, day=1)
now = timezone.now().date()
start = timezone.datetime(year=now.year, month=1, day=1).date()
return {
'series': {
'Documents': map(
lambda x: {force_text(MONTH_NAMES[x[0].month]): x[1]},
qss.time_series(start=this_year, end=today, interval='months')
qss.time_series(start=start, end=now, interval='months')
)
}
}
@@ -48,14 +47,14 @@ def new_document_pages_per_month():
DocumentPage.objects.all(), 'document_version__document__date_added'
)
today = datetime.date.today()
this_year = datetime.date(year=today.year, month=1, day=1)
now = timezone.now().date()
start = timezone.datetime(year=now.year, month=1, day=1).date()
return {
'series': {
'Pages': map(
lambda x: {force_text(MONTH_NAMES[x[0].month]): x[1]},
qss.time_series(start=this_year, end=today, interval='months')
qss.time_series(start=start, end=now, interval='months')
)
}
}
@@ -88,14 +87,14 @@ def new_document_versions_per_month():
DocumentVersion.objects.all(), 'document__date_added'
)
today = datetime.date.today()
this_year = datetime.date(year=today.year, month=1, day=1)
now = timezone.now().date()
start = timezone.datetime(year=now.year, month=1, day=1).date()
return {
'series': {
'Versions': map(
lambda x: {force_text(MONTH_NAMES[x[0].month]): x[1]},
qss.time_series(start=this_year, end=today, interval='months')
qss.time_series(start=start, end=now, interval='months')
)
}
}
@@ -127,25 +126,27 @@ def total_document_per_month():
Document = apps.get_model(app_label='documents', model_name='Document')
qss = qsstats.QuerySetStats(Document.objects.all(), 'date_added')
this_year = datetime.date.today().year
now = timezone.now()
result = []
for month in range(1, datetime.date.today().month + 1):
for month in range(1, now.month + 1):
next_month = month + 1
if month == 12:
next_month = 1
year = this_year + 1
year = now.year + 1
else:
next_month = month + 1
year = this_year
year = now.year
result.append(
{
force_text(
MONTH_NAMES[month]
): qss.until(datetime.date(year, next_month, 1))
): qss.until(
timezone.datetime(year, next_month, 1, tzinfo=now.tzinfo)
)
}
)
@@ -164,25 +165,27 @@ def total_document_version_per_month():
qss = qsstats.QuerySetStats(
DocumentVersion.objects.all(), 'document__date_added'
)
this_year = datetime.date.today().year
now = timezone.now()
result = []
for month in range(1, datetime.date.today().month + 1):
for month in range(1, now.month + 1):
next_month = month + 1
if month == 12:
next_month = 1
year = this_year + 1
year = now.year + 1
else:
next_month = month + 1
year = this_year
year = now.year
result.append(
{
force_text(
MONTH_NAMES[month]
): qss.until(datetime.date(year, next_month, 1))
): qss.until(
timezone.datetime(year, next_month, 1, tzinfo=now.tzinfo)
)
}
)
@@ -201,25 +204,27 @@ def total_document_page_per_month():
qss = qsstats.QuerySetStats(
DocumentPage.objects.all(), 'document_version__document__date_added'
)
this_year = datetime.date.today().year
now = timezone.now()
result = []
for month in range(1, datetime.date.today().month + 1):
for month in range(1, now.month + 1):
next_month = month + 1
if month == 12:
next_month = 1
year = this_year + 1
year = now.year + 1
else:
next_month = month + 1
year = this_year
year = now.year
result.append(
{
force_text(
MONTH_NAMES[month]
): qss.until(datetime.date(year, next_month, 1))
): qss.until(
timezone.datetime(year, next_month, 1, tzinfo=now.tzinfo)
)
}
)