Skip to content

Commit

Permalink
fix multiple appinsights errors
Browse files Browse the repository at this point in the history
  • Loading branch information
NvdLaan committed Jun 21, 2024
1 parent d9cb820 commit 05f8fae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
14 changes: 13 additions & 1 deletion app/apps/cases/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
},
}

CASE_401 = {
"deleted": True,
"address": {
"street_name": "Geen toegang tot zaak",
"number": 401,
},
}


class Case(models.Model):
class Meta:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 8 additions & 4 deletions app/apps/itinerary/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from apps.cases.models import Case
from apps.planner.algorithm.knapsack import (
ItineraryKnapsackList,
Expand All @@ -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"""
Expand Down Expand Up @@ -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
"""
Expand All @@ -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):
"""
Expand All @@ -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)
Expand Down

0 comments on commit 05f8fae

Please sign in to comment.