From ec000da6c801c1629b4101f6cbeb336212af3538 Mon Sep 17 00:00:00 2001 From: Oliver Sauder Date: Thu, 4 Jan 2018 09:29:19 +0100 Subject: [PATCH] Fix django deprecation warnings --- timed/employment/models.py | 9 +++++++-- timed/employment/tests/test_absence_balance.py | 2 +- timed/employment/tests/test_absence_credit.py | 2 +- timed/employment/tests/test_absence_type.py | 2 +- timed/employment/tests/test_employment.py | 2 +- timed/employment/tests/test_location.py | 2 +- timed/employment/tests/test_overtime_credit.py | 2 +- timed/employment/tests/test_public_holiday.py | 2 +- timed/employment/tests/test_user.py | 2 +- timed/employment/tests/test_worktime_balance.py | 2 +- timed/projects/models.py | 2 ++ timed/projects/tests/test_billing_type.py | 2 +- timed/projects/tests/test_cost_center.py | 2 +- timed/projects/tests/test_customer.py | 2 +- timed/projects/tests/test_project.py | 2 +- timed/projects/tests/test_task.py | 2 +- timed/reports/tests/test_customer_statistic.py | 2 +- timed/reports/tests/test_month_statistic.py | 2 +- timed/reports/tests/test_project_statistic.py | 2 +- timed/reports/tests/test_task_statistic.py | 2 +- timed/reports/tests/test_user_statistic.py | 2 +- timed/reports/tests/test_work_report.py | 2 +- timed/reports/tests/test_year_statistic.py | 2 +- timed/subscription/models.py | 8 +++++--- timed/tests/client.py | 2 +- timed/tracking/models.py | 14 +++++++++++--- timed/tracking/tests/test_absence.py | 2 +- timed/tracking/tests/test_activity.py | 2 +- timed/tracking/tests/test_activity_block.py | 2 +- timed/tracking/tests/test_attendance.py | 2 +- timed/tracking/tests/test_report.py | 2 +- 31 files changed, 52 insertions(+), 35 deletions(-) diff --git a/timed/employment/models.py b/timed/employment/models.py index 037de1c0e..3a0c5c584 100644 --- a/timed/employment/models.py +++ b/timed/employment/models.py @@ -48,6 +48,7 @@ class PublicHoliday(models.Model): name = models.CharField(max_length=50) date = models.DateField() location = models.ForeignKey(Location, + on_delete=models.CASCADE, related_name='public_holidays') def __str__(self): @@ -132,9 +133,10 @@ class AbsenceCredit(models.Model): """ user = models.ForeignKey(settings.AUTH_USER_MODEL, + on_delete=models.CASCADE, related_name='absence_credits') comment = models.CharField(max_length=255, blank=True) - absence_type = models.ForeignKey(AbsenceType) + absence_type = models.ForeignKey(AbsenceType, on_delete=models.PROTECT) date = models.DateField() days = models.IntegerField(default=0) transfer = models.BooleanField(default=False) @@ -151,6 +153,7 @@ class OvertimeCredit(models.Model): """ user = models.ForeignKey(settings.AUTH_USER_MODEL, + on_delete=models.CASCADE, related_name='overtime_credits') comment = models.CharField(max_length=255, blank=True) date = models.DateField() @@ -209,8 +212,10 @@ class Employment(models.Model): """ user = models.ForeignKey(settings.AUTH_USER_MODEL, + on_delete=models.CASCADE, related_name='employments') - location = models.ForeignKey(Location, related_name='employments') + location = models.ForeignKey(Location, related_name='employments', + on_delete=models.PROTECT) percentage = models.IntegerField(validators=[ MinValueValidator(0), MaxValueValidator(100)]) diff --git a/timed/employment/tests/test_absence_balance.py b/timed/employment/tests/test_absence_balance.py index f724e523c..5e7b189d9 100644 --- a/timed/employment/tests/test_absence_balance.py +++ b/timed/employment/tests/test_absence_balance.py @@ -1,6 +1,6 @@ from datetime import date, timedelta -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status from timed.employment.factories import (AbsenceCreditFactory, diff --git a/timed/employment/tests/test_absence_credit.py b/timed/employment/tests/test_absence_credit.py index 461ffc757..b7fb3a212 100644 --- a/timed/employment/tests/test_absence_credit.py +++ b/timed/employment/tests/test_absence_credit.py @@ -1,4 +1,4 @@ -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status from timed.employment.factories import (AbsenceCreditFactory, diff --git a/timed/employment/tests/test_absence_type.py b/timed/employment/tests/test_absence_type.py index c886106b4..a571f09f6 100644 --- a/timed/employment/tests/test_absence_type.py +++ b/timed/employment/tests/test_absence_type.py @@ -1,4 +1,4 @@ -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status from timed.employment.factories import AbsenceTypeFactory diff --git a/timed/employment/tests/test_employment.py b/timed/employment/tests/test_employment.py index c9c34e622..6961e4c96 100644 --- a/timed/employment/tests/test_employment.py +++ b/timed/employment/tests/test_employment.py @@ -3,7 +3,7 @@ from datetime import date, timedelta import pytest -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status from timed.employment import factories diff --git a/timed/employment/tests/test_location.py b/timed/employment/tests/test_location.py index 0fdd33d41..5aa46e762 100644 --- a/timed/employment/tests/test_location.py +++ b/timed/employment/tests/test_location.py @@ -1,4 +1,4 @@ -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status from timed.employment.factories import LocationFactory diff --git a/timed/employment/tests/test_overtime_credit.py b/timed/employment/tests/test_overtime_credit.py index 8c197c726..16c5b62ae 100644 --- a/timed/employment/tests/test_overtime_credit.py +++ b/timed/employment/tests/test_overtime_credit.py @@ -1,6 +1,6 @@ """Tests for the overtime credits endpoint.""" -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status from timed.employment.factories import OvertimeCreditFactory, UserFactory diff --git a/timed/employment/tests/test_public_holiday.py b/timed/employment/tests/test_public_holiday.py index 88fafcfa9..6ae063d20 100644 --- a/timed/employment/tests/test_public_holiday.py +++ b/timed/employment/tests/test_public_holiday.py @@ -1,6 +1,6 @@ from datetime import date -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status from timed.employment.factories import PublicHolidayFactory diff --git a/timed/employment/tests/test_user.py b/timed/employment/tests/test_user.py index 5a9b2940b..64593d981 100644 --- a/timed/employment/tests/test_user.py +++ b/timed/employment/tests/test_user.py @@ -2,7 +2,7 @@ import pytest from django.contrib.auth import get_user_model -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status from timed.employment.factories import (AbsenceTypeFactory, EmploymentFactory, diff --git a/timed/employment/tests/test_worktime_balance.py b/timed/employment/tests/test_worktime_balance.py index 8122ba05f..9cef6d8da 100644 --- a/timed/employment/tests/test_worktime_balance.py +++ b/timed/employment/tests/test_worktime_balance.py @@ -1,7 +1,7 @@ from datetime import date, timedelta import pytest -from django.core.urlresolvers import reverse +from django.urls import reverse from django.utils.duration import duration_string from rest_framework import status diff --git a/timed/projects/models.py b/timed/projects/models.py index afc86d861..222458928 100644 --- a/timed/projects/models.py +++ b/timed/projects/models.py @@ -73,6 +73,7 @@ class Project(models.Model): archived = models.BooleanField(default=False) estimated_time = models.DurationField(blank=True, null=True) customer = models.ForeignKey('projects.Customer', + on_delete=models.CASCADE, related_name='projects') billing_type = models.ForeignKey(BillingType, on_delete=models.SET_NULL, blank=True, null=True, @@ -108,6 +109,7 @@ class Task(models.Model): estimated_time = models.DurationField(blank=True, null=True) archived = models.BooleanField(default=False) project = models.ForeignKey('projects.Project', + on_delete=models.CASCADE, related_name='tasks') cost_center = models.ForeignKey(CostCenter, on_delete=models.SET_NULL, blank=True, null=True, diff --git a/timed/projects/tests/test_billing_type.py b/timed/projects/tests/test_billing_type.py index e3d597561..b7d1ed5c0 100644 --- a/timed/projects/tests/test_billing_type.py +++ b/timed/projects/tests/test_billing_type.py @@ -1,4 +1,4 @@ -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework.status import HTTP_200_OK from timed.projects.factories import BillingTypeFactory diff --git a/timed/projects/tests/test_cost_center.py b/timed/projects/tests/test_cost_center.py index 66e034ca8..0dbf07f75 100644 --- a/timed/projects/tests/test_cost_center.py +++ b/timed/projects/tests/test_cost_center.py @@ -1,4 +1,4 @@ -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework.status import HTTP_200_OK from timed.projects.factories import CostCenterFactory diff --git a/timed/projects/tests/test_customer.py b/timed/projects/tests/test_customer.py index 38190e30d..5d0de9d63 100644 --- a/timed/projects/tests/test_customer.py +++ b/timed/projects/tests/test_customer.py @@ -1,6 +1,6 @@ """Tests for the customers endpoint.""" -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status from timed.projects.factories import CustomerFactory diff --git a/timed/projects/tests/test_project.py b/timed/projects/tests/test_project.py index 26f8fd78d..079d1da7a 100644 --- a/timed/projects/tests/test_project.py +++ b/timed/projects/tests/test_project.py @@ -1,7 +1,7 @@ """Tests for the projects endpoint.""" from datetime import timedelta -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status from timed.employment.factories import UserFactory diff --git a/timed/projects/tests/test_task.py b/timed/projects/tests/test_task.py index 5c595ff64..99af34788 100644 --- a/timed/projects/tests/test_task.py +++ b/timed/projects/tests/test_task.py @@ -1,7 +1,7 @@ """Tests for the tasks endpoint.""" from datetime import date, timedelta -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status from timed.projects.factories import TaskFactory diff --git a/timed/reports/tests/test_customer_statistic.py b/timed/reports/tests/test_customer_statistic.py index f0bfe3969..eb4d0bf11 100644 --- a/timed/reports/tests/test_customer_statistic.py +++ b/timed/reports/tests/test_customer_statistic.py @@ -1,6 +1,6 @@ from datetime import timedelta -from django.core.urlresolvers import reverse +from django.urls import reverse from timed.tracking.factories import ReportFactory diff --git a/timed/reports/tests/test_month_statistic.py b/timed/reports/tests/test_month_statistic.py index a167b1796..7ceaac40f 100644 --- a/timed/reports/tests/test_month_statistic.py +++ b/timed/reports/tests/test_month_statistic.py @@ -1,6 +1,6 @@ from datetime import date, timedelta -from django.core.urlresolvers import reverse +from django.urls import reverse from timed.tracking.factories import ReportFactory diff --git a/timed/reports/tests/test_project_statistic.py b/timed/reports/tests/test_project_statistic.py index e312eec71..5e82d8929 100644 --- a/timed/reports/tests/test_project_statistic.py +++ b/timed/reports/tests/test_project_statistic.py @@ -1,6 +1,6 @@ from datetime import timedelta -from django.core.urlresolvers import reverse +from django.urls import reverse from timed.tracking.factories import ReportFactory diff --git a/timed/reports/tests/test_task_statistic.py b/timed/reports/tests/test_task_statistic.py index 127be35e1..45bbd9980 100644 --- a/timed/reports/tests/test_task_statistic.py +++ b/timed/reports/tests/test_task_statistic.py @@ -1,6 +1,6 @@ from datetime import timedelta -from django.core.urlresolvers import reverse +from django.urls import reverse from timed.projects.factories import TaskFactory from timed.tracking.factories import ReportFactory diff --git a/timed/reports/tests/test_user_statistic.py b/timed/reports/tests/test_user_statistic.py index 2d5c8f08c..644844dd1 100644 --- a/timed/reports/tests/test_user_statistic.py +++ b/timed/reports/tests/test_user_statistic.py @@ -1,6 +1,6 @@ from datetime import timedelta -from django.core.urlresolvers import reverse +from django.urls import reverse from timed.tracking.factories import ReportFactory diff --git a/timed/reports/tests/test_work_report.py b/timed/reports/tests/test_work_report.py index 0f464c4bb..90dc77ed7 100644 --- a/timed/reports/tests/test_work_report.py +++ b/timed/reports/tests/test_work_report.py @@ -4,7 +4,7 @@ import ezodf import pytest -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework.status import HTTP_200_OK, HTTP_400_BAD_REQUEST from timed.projects.factories import (CustomerFactory, ProjectFactory, diff --git a/timed/reports/tests/test_year_statistic.py b/timed/reports/tests/test_year_statistic.py index 4b9595a01..e9742ab91 100644 --- a/timed/reports/tests/test_year_statistic.py +++ b/timed/reports/tests/test_year_statistic.py @@ -1,6 +1,6 @@ from datetime import date, timedelta -from django.core.urlresolvers import reverse +from django.urls import reverse from timed.tracking.factories import ReportFactory diff --git a/timed/subscription/models.py b/timed/subscription/models.py index e013e629c..754ddb8a5 100644 --- a/timed/subscription/models.py +++ b/timed/subscription/models.py @@ -23,7 +23,7 @@ def __str__(self): class Package(models.Model): """Representing a subscription package.""" - subscription = models.ForeignKey(Subscription) + subscription = models.ForeignKey(Subscription, on_delete=models.CASCADE) duration = models.DurationField() price = MoneyField(max_digits=7, decimal_places=2, default_currency='CHF') @@ -36,7 +36,8 @@ class SubscriptionProject(models.Model): A project can only be assigned to one subscription. """ - project = models.OneToOneField('projects.Project') + project = models.OneToOneField('projects.Project', + on_delete=models.CASCADE) subscription = models.ForeignKey(Subscription, on_delete=models.CASCADE) @@ -63,6 +64,7 @@ class CustomerPassword(models.Model): once customer center will go live. """ - customer = models.OneToOneField('projects.Customer') + customer = models.OneToOneField('projects.Customer', + on_delete=models.CASCADE) password = models.CharField(_('password'), max_length=128, null=True, blank=True) diff --git a/timed/tests/client.py b/timed/tests/client.py index 94180965f..5a47eb005 100644 --- a/timed/tests/client.py +++ b/timed/tests/client.py @@ -2,7 +2,7 @@ import json -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import exceptions, status from rest_framework.test import APIClient from rest_framework_jwt.settings import api_settings diff --git a/timed/tracking/models.py b/timed/tracking/models.py index 3ca497568..d417b3f58 100644 --- a/timed/tracking/models.py +++ b/timed/tracking/models.py @@ -19,8 +19,10 @@ class Activity(models.Model): task = models.ForeignKey('projects.Task', null=True, blank=True, + on_delete=models.SET_NULL, related_name='activities') user = models.ForeignKey(settings.AUTH_USER_MODEL, + on_delete=models.CASCADE, related_name='activities') @property @@ -56,6 +58,7 @@ class ActivityBlock(models.Model): """ activity = models.ForeignKey('tracking.Activity', + on_delete=models.CASCADE, related_name='blocks') from_time = models.TimeField() to_time = models.TimeField(blank=True, null=True) @@ -77,6 +80,7 @@ class Attendance(models.Model): from_time = models.TimeField() to_time = models.TimeField() user = models.ForeignKey(settings.AUTH_USER_MODEL, + on_delete=models.CASCADE, related_name='attendances') def __str__(self): @@ -106,13 +110,15 @@ class Report(models.Model): duration = models.DurationField() review = models.BooleanField(default=False) not_billable = models.BooleanField(default=False) - task = models.ForeignKey('projects.Task', related_name='reports') + task = models.ForeignKey('projects.Task', related_name='reports', + on_delete=models.PROTECT) activity = models.ForeignKey(Activity, null=True, blank=True, on_delete=models.SET_NULL, related_name='reports') user = models.ForeignKey(settings.AUTH_USER_MODEL, + on_delete=models.PROTECT, related_name='reports') verified_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, @@ -161,7 +167,7 @@ def get_queryset(self): models.Q(end_date__isnull=True) ), start_date__lte=models.OuterRef('date'), - user_id=models.OuterRef(models.OuterRef('user')) + user=models.OuterRef(models.OuterRef('user')) ).values('location')[:1] queryset = super().get_queryset() @@ -183,8 +189,10 @@ class Absence(models.Model): comment = models.TextField(blank=True) date = models.DateField() type = models.ForeignKey('employment.AbsenceType', - related_name='absences') + related_name='absences', + on_delete=models.PROTECT) user = models.ForeignKey(settings.AUTH_USER_MODEL, + on_delete=models.CASCADE, related_name='absences') objects = AbsenceManager() diff --git a/timed/tracking/tests/test_absence.py b/timed/tracking/tests/test_absence.py index 1f00434ae..ff5a58265 100644 --- a/timed/tracking/tests/test_absence.py +++ b/timed/tracking/tests/test_absence.py @@ -1,6 +1,6 @@ import datetime -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status from timed.employment.factories import (AbsenceTypeFactory, EmploymentFactory, diff --git a/timed/tracking/tests/test_activity.py b/timed/tracking/tests/test_activity.py index 63ab3f5c0..06a729524 100644 --- a/timed/tracking/tests/test_activity.py +++ b/timed/tracking/tests/test_activity.py @@ -1,6 +1,6 @@ from datetime import date, timedelta -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status from timed.projects.factories import TaskFactory diff --git a/timed/tracking/tests/test_activity_block.py b/timed/tracking/tests/test_activity_block.py index f2c5e0bd4..b30f397c0 100644 --- a/timed/tracking/tests/test_activity_block.py +++ b/timed/tracking/tests/test_activity_block.py @@ -2,7 +2,7 @@ from datetime import time -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status from timed.tracking.factories import ActivityBlockFactory, ActivityFactory diff --git a/timed/tracking/tests/test_attendance.py b/timed/tracking/tests/test_attendance.py index f3e6ca5c8..7b4d97ec1 100644 --- a/timed/tracking/tests/test_attendance.py +++ b/timed/tracking/tests/test_attendance.py @@ -1,4 +1,4 @@ -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status from timed.tracking.factories import AttendanceFactory diff --git a/timed/tracking/tests/test_report.py b/timed/tracking/tests/test_report.py index 2d1102d3a..d401042a5 100644 --- a/timed/tracking/tests/test_report.py +++ b/timed/tracking/tests/test_report.py @@ -4,7 +4,7 @@ import pyexcel import pytest -from django.core.urlresolvers import reverse +from django.urls import reverse from django.utils.duration import duration_string from rest_framework import status