2020-03-01 16:16:38 +00:00
|
|
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-03-27 12:50:02 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
2020-03-27 15:19:33 +00:00
|
|
|
from django.urls import reverse_lazy
|
2020-03-26 23:40:35 +00:00
|
|
|
from django.views.generic import CreateView, DetailView, UpdateView, TemplateView
|
2020-03-27 00:31:54 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2020-03-01 16:16:38 +00:00
|
|
|
from django_tables2.views import SingleTableView
|
|
|
|
|
2020-03-27 20:18:27 +00:00
|
|
|
from permission.backends import PermissionBackend
|
2020-03-27 17:02:22 +00:00
|
|
|
from .forms import ActivityForm, GuestForm
|
|
|
|
from .models import Activity, Guest
|
2020-03-27 20:18:27 +00:00
|
|
|
from .tables import ActivityTable, GuestTable
|
2020-03-26 23:40:35 +00:00
|
|
|
|
2020-03-01 16:16:38 +00:00
|
|
|
|
2020-03-27 12:50:02 +00:00
|
|
|
class ActivityCreateView(LoginRequiredMixin, CreateView):
|
2020-03-01 16:16:38 +00:00
|
|
|
model = Activity
|
2020-03-27 00:31:54 +00:00
|
|
|
form_class = ActivityForm
|
2020-03-27 20:18:27 +00:00
|
|
|
|
|
|
|
def get_success_url(self, **kwargs):
|
|
|
|
return reverse_lazy('activity:activity_detail', kwargs={"pk": self.kwargs["pk"]})
|
2020-03-26 23:40:35 +00:00
|
|
|
|
|
|
|
|
2020-03-27 12:50:02 +00:00
|
|
|
class ActivityListView(LoginRequiredMixin, SingleTableView):
|
2020-03-01 16:16:38 +00:00
|
|
|
model = Activity
|
2020-03-27 17:02:22 +00:00
|
|
|
table_class = ActivityTable
|
2020-03-27 00:31:54 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
ctx = super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
ctx['title'] = _("Upcoming activities")
|
|
|
|
|
|
|
|
return ctx
|
2020-03-01 16:16:38 +00:00
|
|
|
|
2020-03-26 23:40:35 +00:00
|
|
|
|
2020-03-27 12:50:02 +00:00
|
|
|
class ActivityDetailView(LoginRequiredMixin, DetailView):
|
2020-03-01 16:16:38 +00:00
|
|
|
model = Activity
|
2020-03-27 18:47:43 +00:00
|
|
|
context_object_name = "activity"
|
2020-03-01 16:16:38 +00:00
|
|
|
|
2020-03-27 20:18:27 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
ctx = super().get_context_data()
|
|
|
|
|
|
|
|
table = GuestTable(data=Guest.objects.filter(activity=self.object)
|
|
|
|
.filter(PermissionBackend.filter_queryset(self.request.user, Guest, "view")))
|
|
|
|
ctx["guests"] = table
|
|
|
|
|
|
|
|
return ctx
|
|
|
|
|
2020-03-26 23:40:35 +00:00
|
|
|
|
2020-03-27 12:50:02 +00:00
|
|
|
class ActivityUpdateView(LoginRequiredMixin, UpdateView):
|
2020-03-01 16:16:38 +00:00
|
|
|
model = Activity
|
2020-03-27 00:31:54 +00:00
|
|
|
form_class = ActivityForm
|
2020-03-27 20:18:27 +00:00
|
|
|
|
|
|
|
def get_success_url(self, **kwargs):
|
|
|
|
return reverse_lazy('activity:activity_detail', kwargs={"pk": self.kwargs["pk"]})
|
2020-03-26 23:40:35 +00:00
|
|
|
|
|
|
|
|
2020-03-27 17:02:22 +00:00
|
|
|
class ActivityInviteView(LoginRequiredMixin, CreateView):
|
|
|
|
model = Guest
|
|
|
|
form_class = GuestForm
|
|
|
|
template_name = "activity/activity_invite.html"
|
|
|
|
|
2020-03-27 18:16:38 +00:00
|
|
|
def form_valid(self, form):
|
|
|
|
form.instance.activity = Activity.objects.get(pk=self.kwargs["pk"])
|
|
|
|
return super().form_valid(form)
|
|
|
|
|
|
|
|
def get_success_url(self, **kwargs):
|
|
|
|
return reverse_lazy('activity:activity_detail', kwargs={"pk": self.kwargs["pk"]})
|
|
|
|
|
2020-03-27 17:02:22 +00:00
|
|
|
|
2020-03-27 12:50:02 +00:00
|
|
|
class ActivityEntryView(LoginRequiredMixin, TemplateView):
|
2020-03-01 16:16:38 +00:00
|
|
|
pass
|