Skip to content

Commit

Permalink
make sure that the front page loads with an empty db
Browse files Browse the repository at this point in the history
Lots of other things will probably break but at least you don't get
immediately presented with a 500 error
  • Loading branch information
struan committed May 16, 2024
1 parent b396938 commit b42f3f6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
30 changes: 18 additions & 12 deletions crowdsourcer/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,36 @@ def __call__(self, request):

def process_view(self, request, view_func, view_args, view_kwargs):
session_name = view_kwargs.get("marking_session", None)

request.current_session = None
request.current_stage = None

if session_name is not None:
current_session = MarkingSession.objects.filter(
label=session_name, active=True
).first()
else:
current_session = MarkingSession.objects.filter(active=True).first()

current_stage = current_session.stage
if current_stage is None:
current_stage = ResponseType.objects.filter(type="First Mark").first()
if current_session is not None:
current_stage = current_session.stage
if current_stage is None:
current_stage = ResponseType.objects.filter(type="First Mark").first()

request.current_stage = current_stage
request.current_session = current_session
request.current_stage = current_stage
request.current_session = current_session

def process_template_response(self, request, response):
context = response.context_data

context["marking_session"] = request.current_session
context["sessions"] = MarkingSession.objects.filter(active=True)
context["brand"] = settings.BRAND
context[
"brand_include"
] = f"crowdsourcer/cobrand/navbar_{context['brand']}.html"
if request.current_session is not None:
context["marking_session"] = request.current_session
context["sessions"] = MarkingSession.objects.filter(active=True)
context["brand"] = settings.BRAND
context[
"brand_include"
] = f"crowdsourcer/cobrand/navbar_{context['brand']}.html"

response.context_data = context
response.context_data = context

return response
6 changes: 6 additions & 0 deletions crowdsourcer/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
)


class TestEmptyDB(TestCase):
def test_home_page(self):
response = self.client.get("/")
self.assertEqual(response.status_code, 200)


class TestHomePage(TestCase):
fixtures = [
"basics.json",
Expand Down

0 comments on commit b42f3f6

Please sign in to comment.