Skip to content
This repository has been archived by the owner on Nov 7, 2019. It is now read-only.

Commit

Permalink
apps/organisations: Except unresolvable paths
Browse files Browse the repository at this point in the history
If a path does not exists, e.g. on not existing static files, the template
tag would throw a `Resolver404` exception, crashing the base template, which
again gets used by the 404 template, which leads to a 500 error instead of
404.
  • Loading branch information
rmader authored and fuzzylogic2000 committed Sep 26, 2019
1 parent ec6c9e5 commit 162d006
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions apps/organisations/templatetags/organisation_tags.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django import template
from django.urls import Resolver404
from django.urls import resolve

from apps.organisations.models import Organisation
Expand All @@ -9,10 +10,10 @@
@register.simple_tag(takes_context=True)
def get_current_organisation(context):
request = context.request
resolver = resolve(request.path_info)
if resolver.kwargs and 'organisation_slug' in resolver.kwargs:
try:
try:
resolver = resolve(request.path_info)
if resolver.kwargs and 'organisation_slug' in resolver.kwargs:
return Organisation.objects.get(
slug=resolver.kwargs['organisation_slug'])
except Organisation.DoesNotExist:
pass
except (Resolver404, Organisation.DoesNotExist):
pass

0 comments on commit 162d006

Please sign in to comment.