nk20/apps/activity/views.py

58 lines
1.7 KiB
Python
Raw Normal View History

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
from django.contrib.auth.mixins import LoginRequiredMixin
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 17:02:22 +00:00
from .forms import ActivityForm, GuestForm
from .models import Activity, Guest
from .tables import ActivityTable
2020-03-26 23:40:35 +00:00
2020-03-01 16:16:38 +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
success_url = reverse_lazy('activity:activity_list')
2020-03-26 23:40:35 +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
class ActivityDetailView(LoginRequiredMixin, DetailView):
2020-03-01 16:16:38 +00:00
model = Activity
2020-03-26 23:40:35 +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
success_url = reverse_lazy('activity:activity_list')
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
class ActivityEntryView(LoginRequiredMixin, TemplateView):
2020-03-01 16:16:38 +00:00
pass