From 413fa081176ddde5d1aab0dcb96545400a9a55f2 Mon Sep 17 00:00:00 2001 From: Stefan Borer Date: Fri, 7 Feb 2020 14:39:49 +0100 Subject: [PATCH] chore(deps): upgrade to django 2, python 3.8 and everything else Upgrade from django 1 to 2, along with other dependencies. Only minor changes were required, including that monthly reports use a constructed primary key that now has the format "YYYYMM" instead of "YYYY-M". --- Dockerfile | 2 +- requirements.txt | 24 +++++++++---------- timed/projects/views.py | 4 ++-- .../management/commands/redmine_report.py | 6 +++-- timed/reports/tests/test_month_statistic.py | 4 ++-- .../test_notify_supervisors_shorttime.py | 2 +- timed/reports/views.py | 6 ++--- 7 files changed, 25 insertions(+), 23 deletions(-) diff --git a/Dockerfile b/Dockerfile index 65bda76f..fd152afc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.6 +FROM python:3.8 WORKDIR /app diff --git a/requirements.txt b/requirements.txt index 1fb59427..08092095 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,20 +1,20 @@ -python-dateutil==2.8.0 -django==1.11.22 # pyup: >=1.11,<1.12 -django-auth-ldap==1.7.0 -django-filter==2.1.0 -django-multiselectfield==0.1.8 -djangorestframework==3.9.4 +python-dateutil==2.8.1 +django==2.2.10 # pyup: <3.0 +django-auth-ldap==2.1.0 +django-filter==2.2.0 +django-multiselectfield==0.1.11 +djangorestframework==3.11.0 djangorestframework-jwt==1.11.0 -djangorestframework-jsonapi==2.7.0 -psycopg2-binary==2.8.2 -pytz==2019.1 +djangorestframework-jsonapi==3.0.0 +psycopg2-binary==2.8.4 +pytz==2019.3 pyexcel-webio==0.1.4 -pyexcel-io==0.5.17 +pyexcel-io==0.5.20 django-excel==0.0.10 pyexcel-ods3==0.5.3 -pyexcel-xlsx==0.5.7 +pyexcel-xlsx==0.5.8 pyexcel-ezodf==0.3.4 django-environ==0.4.5 -django-money==0.14.4 +django-money==1.0 python-redmine==2.2.1 uwsgi==2.0.18 diff --git a/timed/projects/views.py b/timed/projects/views.py index 9eb1d9b9..7f9d5c40 100644 --- a/timed/projects/views.py +++ b/timed/projects/views.py @@ -1,7 +1,7 @@ """Viewsets for the projects app.""" from rest_framework.viewsets import ReadOnlyModelViewSet -from rest_framework_json_api.views import PrefetchForIncludesHelperMixin +from rest_framework_json_api.views import PreloadIncludesMixin from timed.projects import filters, models, serializers @@ -38,7 +38,7 @@ def get_queryset(self): return models.CostCenter.objects.all() -class ProjectViewSet(PrefetchForIncludesHelperMixin, ReadOnlyModelViewSet): +class ProjectViewSet(PreloadIncludesMixin, ReadOnlyModelViewSet): """Project view set.""" serializer_class = serializers.ProjectSerializer diff --git a/timed/redmine/management/commands/redmine_report.py b/timed/redmine/management/commands/redmine_report.py index 1f93a45a..4257a430 100644 --- a/timed/redmine/management/commands/redmine_report.py +++ b/timed/redmine/management/commands/redmine_report.py @@ -53,8 +53,10 @@ def handle(self, *args, **options): .values("id") ) # calculate total hours - projects = Project.objects.filter(id__in=affected_projects).annotate( - total_hours=Sum("tasks__reports__duration") + projects = ( + Project.objects.filter(id__in=affected_projects) + .order_by("name") + .annotate(total_hours=Sum("tasks__reports__duration")) ) for project in projects: diff --git a/timed/reports/tests/test_month_statistic.py b/timed/reports/tests/test_month_statistic.py index 28fc5311..9643af6c 100644 --- a/timed/reports/tests/test_month_statistic.py +++ b/timed/reports/tests/test_month_statistic.py @@ -18,12 +18,12 @@ def test_month_statistic_list(auth_client): expected_json = [ { "type": "month-statistics", - "id": "2015-12", + "id": "201512", "attributes": {"year": 2015, "month": 12, "duration": "03:00:00"}, }, { "type": "month-statistics", - "id": "2016-1", + "id": "201601", "attributes": {"year": 2016, "month": 1, "duration": "01:00:00"}, }, ] diff --git a/timed/reports/tests/test_notify_supervisors_shorttime.py b/timed/reports/tests/test_notify_supervisors_shorttime.py index be64eca2..e7693d58 100644 --- a/timed/reports/tests/test_notify_supervisors_shorttime.py +++ b/timed/reports/tests/test_notify_supervisors_shorttime.py @@ -39,7 +39,7 @@ def test_notify_supervisors(db, mailoutbox): mail = mailoutbox[0] assert mail.to == [supervisor.email] body = mail.body - assert "Time range: 17.07.2017 - 23.07.2017\nRatio: 0.9" in body + assert "Time range: July 17, 2017 - July 23, 2017\nRatio: 0.9" in body expected = ("{0} 35.0/42.5 (Ratio 0.82 Delta -7.5 Balance -9.0)").format( supervisee.get_full_name() ) diff --git a/timed/reports/views.py b/timed/reports/views.py index 603edf9d..e90b09ba 100644 --- a/timed/reports/views.py +++ b/timed/reports/views.py @@ -5,8 +5,8 @@ from zipfile import ZipFile from django.conf import settings -from django.db.models import F, Sum, Value -from django.db.models.functions import Concat, ExtractMonth, ExtractYear +from django.db.models import F, Sum +from django.db.models.functions import ExtractMonth, ExtractYear from django.http import HttpResponse, HttpResponseBadRequest from ezodf import Cell, opendoc from rest_framework.viewsets import GenericViewSet, ReadOnlyModelViewSet @@ -49,7 +49,7 @@ def get_queryset(self): ) queryset = queryset.values("year", "month") queryset = queryset.annotate(duration=Sum("duration")) - queryset = queryset.annotate(pk=Concat("year", Value("-"), "month")) + queryset = queryset.annotate(pk=F("year") * 100 + F("month")) return queryset