Skip to content

Commit

Permalink
💚 FIX CI build by adding better errorhandling
Browse files Browse the repository at this point in the history
  • Loading branch information
stefrado committed Oct 22, 2024
1 parent 3e1d07f commit dd6a9f5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/sdg/utils/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from sdg.conf.utils import org_type_cfg
from sdg.producten.models import NotificationViewed, ProductVersie
from django.utils.timezone import now
from dateutil.relativedelta import relativedelta


def settings(request):
Expand Down Expand Up @@ -31,13 +33,25 @@ def settings(request):
def has_new_notifications(request):
if request.user and request.user.is_anonymous is not True:
# Get the user's NotificationViewed instance
notification_viewed = NotificationViewed.objects.get(gebruiker=request.user)
try:
notification_viewed = NotificationViewed.objects.get(gebruiker=request.user)
except NotificationViewed.DoesNotExist:
notification_viewed = None


# Get the last_viewed_date from data
try:
last_viewed_date = notification_viewed.last_viewed_date
except AttributeError:
# default last_viewed_date is 12 months ago
last_viewed_date = now() - relativedelta(months=12)


# Get the latest product version after the last_viewed_date else None.
latest_notification = (
ProductVersie.objects.filter(
product__referentie_product=None,
gewijzigd_op__gt=notification_viewed.last_viewed_date,
gewijzigd_op__gt=last_viewed_date,
)
.order_by("-gewijzigd_op")
.first()
Expand Down

0 comments on commit dd6a9f5

Please sign in to comment.