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 4bc27d33e2
commit 491badc877
2 changed files with 32 additions and 26 deletions

View File

@@ -139,6 +139,7 @@
These are now a fallback if the new 'DATABASES'
setting is not specified.
- Refactor the initial setting bootstrap code.
- Use timezone aware date for document statistics
3.2.10 (2019-XX-XX)
===================

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)
)
}
)