From 05f8fae31cd88d84d3a68cd45dbf6c099819fc67 Mon Sep 17 00:00:00 2001 From: Nino Date: Fri, 21 Jun 2024 13:29:57 +0200 Subject: [PATCH] fix multiple appinsights errors --- app/apps/cases/models.py | 14 +++++++++++++- app/apps/itinerary/models.py | 12 ++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/apps/cases/models.py b/app/apps/cases/models.py index da5564fe..263499f1 100644 --- a/app/apps/cases/models.py +++ b/app/apps/cases/models.py @@ -18,6 +18,14 @@ }, } +CASE_401 = { + "deleted": True, + "address": { + "street_name": "Geen toegang tot zaak", + "number": 401, + }, +} + class Case(models.Model): class Meta: @@ -50,6 +58,10 @@ def fetch_case(self, auth_header=None): ) if response.status_code == 404: return CASE_404 + + if response.status_code == 401: + return CASE_401 + response.raise_for_status() case_data = response.json() @@ -84,7 +96,7 @@ def fetch_events(self, auth_header=None): response = requests.get( url, - timeout=5, + timeout=20, headers=get_headers(auth_header), ) response.raise_for_status() diff --git a/app/apps/itinerary/models.py b/app/apps/itinerary/models.py index 6d9d6519..8ab63ba5 100644 --- a/app/apps/itinerary/models.py +++ b/app/apps/itinerary/models.py @@ -1,3 +1,5 @@ +import logging + from apps.cases.models import Case from apps.planner.algorithm.knapsack import ( ItineraryKnapsackList, @@ -12,6 +14,8 @@ from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models +logger = logging.getLogger(__name__) + class Itinerary(models.Model): """Itinerary for visiting cases""" @@ -384,7 +388,7 @@ def set_position_to_last(self): last_item = itinerary_items[-1] self.position = last_item.position + 1 - def check_items_same_position(self): + def items_with_same_position_exist(self): """ Don't allow saving if another item in the list has the same position """ @@ -393,8 +397,7 @@ def check_items_same_position(self): ) items_with_same_position = items_with_same_position.exclude(pk=self.pk) - if items_with_same_position.exists(): - raise ValueError("An item with this position already exists") + return items_with_same_position.exists() def check_items_same_case(self): """ @@ -421,7 +424,8 @@ def save(self, *args, **kwargs): # If no position is given, set the item to the last in list self.set_position_to_last() - self.check_items_same_position() + if self.items_with_same_position_exist(): + return self.check_items_same_case() super().save(*args, **kwargs)