Include raids in the previous/next month in the raid calendar.
This commit is contained in:
parent
b3ba6caa07
commit
37e18971db
|
@ -4,7 +4,7 @@ from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("calendar/", views.RaidCalendar.as_view(), name="raid_calendar"),
|
path("calendar/", views.RaidCalendar.as_view(), name="raid_calendar"),
|
||||||
path("calendar/<int:year>/<int:month>/", views.RaidCalendar.as_view(month_format="%m"), name="raid_calendar"),
|
path("calendar/<int:year>/<int:month>/", views.RaidCalendar.as_view(), name="raid_calendar"),
|
||||||
path("raids/create/", views.RaidCreateView.as_view(), name="raid_create"),
|
path("raids/create/", views.RaidCreateView.as_view(), name="raid_create"),
|
||||||
path("raids/<int:pk>/", views.RaidDetailView.as_view(), name="raid_detail"),
|
path("raids/<int:pk>/", views.RaidDetailView.as_view(), name="raid_detail"),
|
||||||
path("raids/<int:pk>/change/", views.RaidChangeView.as_view(), name="raid_change"),
|
path("raids/<int:pk>/change/", views.RaidChangeView.as_view(), name="raid_change"),
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import itertools
|
import itertools
|
||||||
from calendar import Calendar
|
from calendar import Calendar
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||||
|
@ -22,6 +23,7 @@ class RaidCalendar(MonthArchiveView):
|
||||||
allow_future = True
|
allow_future = True
|
||||||
date_field = "date"
|
date_field = "date"
|
||||||
ordering = "date"
|
ordering = "date"
|
||||||
|
month_format = "%m"
|
||||||
template_name_suffix = "_calendar"
|
template_name_suffix = "_calendar"
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
@ -31,6 +33,15 @@ class RaidCalendar(MonthArchiveView):
|
||||||
max_status=Max("responses__status", filter=Q(responses__character__user=self.request.user))
|
max_status=Max("responses__status", filter=Q(responses__character__user=self.request.user))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_dated_queryset(self, **lookup):
|
||||||
|
"""
|
||||||
|
Include raids one week into the previous/next month so we can show them "grayed out" in the calendar.
|
||||||
|
"""
|
||||||
|
date_field = self.get_date_field()
|
||||||
|
lookup[f"{date_field}__gte"] -= timedelta(weeks=1)
|
||||||
|
lookup[f"{date_field}__lt"] += timedelta(weeks=1)
|
||||||
|
return super().get_dated_queryset(**lookup)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
date = context["month"]
|
date = context["month"]
|
||||||
|
@ -53,19 +64,23 @@ class RaidCalendar(MonthArchiveView):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_year(self):
|
def get_year(self):
|
||||||
|
"""
|
||||||
|
Default to the current year if not provided in the url kwargs.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
return super().get_year()
|
return super().get_year()
|
||||||
except Http404:
|
except Http404:
|
||||||
return timezone.now().strftime(self.get_year_format())
|
return timezone.now().strftime(self.get_year_format())
|
||||||
|
|
||||||
def get_month(self):
|
def get_month(self):
|
||||||
|
"""
|
||||||
|
Default to the current month if not provided in the url kwargs.
|
||||||
|
TODO: Could get the month of the next raid instead.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
return super().get_month()
|
return super().get_month()
|
||||||
except Http404:
|
except Http404:
|
||||||
return timezone.now().strftime(self.get_month_format()) # TODO: Could get date of next raid instead
|
return timezone.now().strftime(self.get_month_format())
|
||||||
|
|
||||||
def get_ordering(self):
|
|
||||||
return super().get_ordering()
|
|
||||||
|
|
||||||
|
|
||||||
class RaidDetailView(SingleObjectMixin, MultiModelFormView):
|
class RaidDetailView(SingleObjectMixin, MultiModelFormView):
|
||||||
|
|
Loading…
Reference in a new issue