Skip to content

Commit

Permalink
make EventCalendarView LoginRequired
Browse files Browse the repository at this point in the history
  • Loading branch information
felixrindt authored and jeriox committed Jul 17, 2022
1 parent 3c6e835 commit dcf6f05
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions ephios/core/views/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,30 @@ def get_context_data(self, *, object_list=None, **kwargs):
return super().get_context_data(**kwargs)


class EventCalendarView(LoginRequiredMixin, TemplateView):
template_name = "core/event_calendar.html"

def get_context_data(self, **kwargs):
today = datetime.today()
year = int(self.request.GET.get("year", today.year))
month = int(self.request.GET.get("month", today.month))
events = get_objects_for_user(self.request.user, "core.view_event", klass=Event)
shifts = Shift.objects.filter(
event__in=events, start_time__month=month, start_time__year=year
)
calendar = ShiftCalendar(shifts)
kwargs.setdefault("calendar", mark_safe(calendar.formatmonth(year, month)))
nextyear, nextmonth = _nextmonth(year, month)
kwargs.setdefault(
"next_month_url", f"{reverse('core:event_list')}?year={nextyear}&month={nextmonth}"
)
prevyear, prevmonth = _prevmonth(year, month)
kwargs.setdefault(
"previous_month_url", f"{reverse('core:event_list')}?year={prevyear}&month={prevmonth}"
)
return super().get_context_data(**kwargs)


class EventDetailView(CustomPermissionRequiredMixin, CanonicalSlugDetailMixin, DetailView):
model = Event
permission_required = "core.view_event"
Expand Down Expand Up @@ -319,30 +343,6 @@ def form_valid(self, form):
return redirect(self.object.get_absolute_url())


class EventCalendarView(TemplateView):
template_name = "core/event_calendar.html"

def get_context_data(self, **kwargs):
today = datetime.today()
year = int(self.request.GET.get("year", today.year))
month = int(self.request.GET.get("month", today.month))
events = get_objects_for_user(self.request.user, "core.view_event", klass=Event)
shifts = Shift.objects.filter(
event__in=events, start_time__month=month, start_time__year=year
)
calendar = ShiftCalendar(shifts)
kwargs.setdefault("calendar", mark_safe(calendar.formatmonth(year, month)))
nextyear, nextmonth = _nextmonth(year, month)
kwargs.setdefault(
"next_month_url", f"{reverse('core:event_list')}?year={nextyear}&month={nextmonth}"
)
prevyear, prevmonth = _prevmonth(year, month)
kwargs.setdefault(
"previous_month_url", f"{reverse('core:event_list')}?year={prevyear}&month={prevmonth}"
)
return super().get_context_data(**kwargs)


class EventListTypeSettingView(RedirectView):
def get_redirect_url(self, *args, **kwargs):
return reverse("core:event_list")
Expand Down

0 comments on commit dcf6f05

Please sign in to comment.