2018-05-04 22:19:24 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
2018-05-04 22:38:32 +00:00
|
|
|
from django.http import HttpResponseRedirect
|
2020-02-12 12:10:41 +00:00
|
|
|
from django.views.generic import CreateView, DeleteView, ListView, UpdateView
|
2018-05-04 22:19:24 +00:00
|
|
|
from reversion.views import RevisionMixin
|
|
|
|
|
|
|
|
from camps.mixins import CampViewMixin
|
2020-02-12 12:10:41 +00:00
|
|
|
from info.models import InfoCategory, InfoItem
|
|
|
|
|
2018-08-04 11:45:52 +00:00
|
|
|
from ..models import Team
|
2018-07-23 21:12:57 +00:00
|
|
|
from .mixins import EnsureTeamResponsibleMixin, TeamViewMixin
|
2018-05-04 22:19:24 +00:00
|
|
|
|
|
|
|
|
2019-06-16 12:32:24 +00:00
|
|
|
class InfoCategoriesListView(
|
|
|
|
LoginRequiredMixin,
|
|
|
|
CampViewMixin,
|
|
|
|
TeamViewMixin,
|
|
|
|
EnsureTeamResponsibleMixin,
|
|
|
|
ListView,
|
|
|
|
):
|
2018-08-04 11:45:52 +00:00
|
|
|
model = InfoCategory
|
|
|
|
template_name = "team_info_categories.html"
|
2019-06-16 12:32:24 +00:00
|
|
|
slug_field = "anchor"
|
|
|
|
active_menu = "info_categories"
|
2018-08-04 11:45:52 +00:00
|
|
|
|
|
|
|
def get_team(self):
|
|
|
|
return Team.objects.get(
|
2019-06-16 12:32:24 +00:00
|
|
|
camp__slug=self.kwargs["camp_slug"], slug=self.kwargs["team_slug"]
|
2018-08-04 11:45:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-06-16 12:32:24 +00:00
|
|
|
class InfoItemCreateView(
|
|
|
|
LoginRequiredMixin,
|
|
|
|
CampViewMixin,
|
|
|
|
TeamViewMixin,
|
|
|
|
EnsureTeamResponsibleMixin,
|
|
|
|
CreateView,
|
|
|
|
):
|
2018-05-04 22:19:24 +00:00
|
|
|
model = InfoItem
|
2018-08-04 11:45:52 +00:00
|
|
|
template_name = "team_info_item_form.html"
|
2019-06-16 12:32:24 +00:00
|
|
|
fields = ["headline", "body", "anchor", "weight"]
|
|
|
|
slug_field = "anchor"
|
|
|
|
active_menu = "info_categories"
|
2018-08-04 11:45:52 +00:00
|
|
|
|
|
|
|
def get_team(self):
|
|
|
|
return Team.objects.get(
|
2019-06-16 12:32:24 +00:00
|
|
|
camp__slug=self.kwargs["camp_slug"], slug=self.kwargs["team_slug"]
|
2018-08-04 11:45:52 +00:00
|
|
|
)
|
2018-05-04 22:19:24 +00:00
|
|
|
|
2018-05-04 22:38:32 +00:00
|
|
|
def form_valid(self, form):
|
|
|
|
info_item = form.save(commit=False)
|
2019-06-16 12:32:24 +00:00
|
|
|
category = InfoCategory.objects.get(
|
|
|
|
team__camp=self.camp, anchor=self.kwargs.get("category_anchor")
|
|
|
|
)
|
2018-05-04 22:38:32 +00:00
|
|
|
info_item.category = category
|
|
|
|
info_item.save()
|
|
|
|
return HttpResponseRedirect(self.get_success_url())
|
|
|
|
|
2018-05-04 22:19:24 +00:00
|
|
|
def get_success_url(self):
|
2018-05-04 22:38:32 +00:00
|
|
|
return self.team.get_absolute_url()
|
2018-05-04 22:19:24 +00:00
|
|
|
|
2018-08-04 11:45:52 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
2019-06-16 12:32:24 +00:00
|
|
|
context["category"] = InfoCategory.objects.get(
|
|
|
|
team__camp__slug=self.kwargs["camp_slug"],
|
|
|
|
anchor=self.kwargs["category_anchor"],
|
2018-08-04 11:45:52 +00:00
|
|
|
)
|
|
|
|
return context
|
|
|
|
|
2018-05-04 22:19:24 +00:00
|
|
|
|
2019-06-16 12:32:24 +00:00
|
|
|
class InfoItemUpdateView(
|
|
|
|
LoginRequiredMixin,
|
|
|
|
CampViewMixin,
|
|
|
|
TeamViewMixin,
|
|
|
|
EnsureTeamResponsibleMixin,
|
|
|
|
RevisionMixin,
|
|
|
|
UpdateView,
|
|
|
|
):
|
2018-05-04 22:19:24 +00:00
|
|
|
model = InfoItem
|
2018-08-04 11:45:52 +00:00
|
|
|
template_name = "team_info_item_form.html"
|
2019-06-16 12:32:24 +00:00
|
|
|
fields = ["headline", "body", "anchor", "weight"]
|
|
|
|
slug_field = "anchor"
|
|
|
|
slug_url_kwarg = "item_anchor"
|
|
|
|
active_menu = "info_categories"
|
2018-08-04 11:45:52 +00:00
|
|
|
|
|
|
|
def get_team(self):
|
|
|
|
return Team.objects.get(
|
2019-06-16 12:32:24 +00:00
|
|
|
camp__slug=self.kwargs["camp_slug"], slug=self.kwargs["team_slug"]
|
2018-08-04 11:45:52 +00:00
|
|
|
)
|
2018-05-04 22:19:24 +00:00
|
|
|
|
|
|
|
def get_success_url(self):
|
2019-06-16 12:32:24 +00:00
|
|
|
next = self.request.GET.get("next")
|
2018-05-06 11:22:04 +00:00
|
|
|
if next:
|
|
|
|
return next
|
2018-05-04 22:38:32 +00:00
|
|
|
return self.team.get_absolute_url()
|
2018-05-06 19:55:50 +00:00
|
|
|
|
|
|
|
|
2019-06-16 12:32:24 +00:00
|
|
|
class InfoItemDeleteView(
|
|
|
|
LoginRequiredMixin,
|
|
|
|
CampViewMixin,
|
|
|
|
TeamViewMixin,
|
|
|
|
EnsureTeamResponsibleMixin,
|
|
|
|
RevisionMixin,
|
|
|
|
DeleteView,
|
|
|
|
):
|
2018-05-06 19:55:50 +00:00
|
|
|
model = InfoItem
|
2018-08-04 11:45:52 +00:00
|
|
|
template_name = "team_info_item_delete_confirm.html"
|
2019-06-16 12:32:24 +00:00
|
|
|
slug_field = "anchor"
|
|
|
|
slug_url_kwarg = "item_anchor"
|
|
|
|
active_menu = "info_categories"
|
2018-08-04 11:45:52 +00:00
|
|
|
|
|
|
|
def get_team(self):
|
|
|
|
return Team.objects.get(
|
2019-06-16 12:32:24 +00:00
|
|
|
camp__slug=self.kwargs["camp_slug"], slug=self.kwargs["team_slug"]
|
2018-08-04 11:45:52 +00:00
|
|
|
)
|
2018-05-06 19:55:50 +00:00
|
|
|
|
|
|
|
def get_success_url(self):
|
2019-06-16 12:32:24 +00:00
|
|
|
next = self.request.GET.get("next")
|
2018-05-06 19:55:50 +00:00
|
|
|
if next:
|
|
|
|
return next
|
|
|
|
return self.team.get_absolute_url()
|