Skip to content

Commit

Permalink
Events, but not bedpres, behind login
Browse files Browse the repository at this point in the history
  • Loading branch information
Vemund Aakre committed Apr 4, 2024
1 parent a5aa1f2 commit 644a753
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion nablapps/events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

import datetime

from django.conf import settings
from django.contrib.admin.models import ADDITION, DELETION, LogEntry
from django.contrib.auth import get_user_model
from django.contrib.auth import REDIRECT_FIELD_NAME, get_user_model
from django.contrib.auth.views import redirect_to_login
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.http import Http404, HttpResponse, HttpResponseRedirect
Expand Down Expand Up @@ -271,6 +273,15 @@ class EventDetailView(AdminLinksMixin, MessageMixin, DetailView):
context_object_name = "event"
template_name = "events/event_detail.html"

def get(self, request, *args, **kwargs):
self.object = self.get_object()
context = self.get_context_data(object=self.object)
if not self.object.is_bedpres and not request.user.is_authenticated:
return redirect_to_login(
request.get_full_path(), settings.LOGIN_URL, REDIRECT_FIELD_NAME
)
return self.render_to_response(context)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
event = self.object
Expand Down

0 comments on commit 644a753

Please sign in to comment.