54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
"""To geneate a Sitemap with all events."""
|
|
from datetime import date
|
|
|
|
from django.contrib.sitemaps import Sitemap
|
|
from django.urls import reverse
|
|
|
|
from events.models import Event
|
|
from kasu.sitemaps import GenericSitemap
|
|
from .models import SeasonRanking
|
|
|
|
|
|
class EventRankingSitemap(GenericSitemap):
|
|
@staticmethod
|
|
def items():
|
|
"""add all upcoming and archived events to the sitemap."""
|
|
return Event.objects.all().exclude(eventranking=None)
|
|
|
|
@staticmethod
|
|
def location(event):
|
|
return reverse('event-ranking', kwargs={'event': event.id})
|
|
|
|
|
|
class EventHanchanSitemap(GenericSitemap):
|
|
@staticmethod
|
|
def items():
|
|
"""add all upcoming and archived events to the sitemap."""
|
|
return Event.objects.all().exclude(eventranking=None)
|
|
|
|
@staticmethod
|
|
def location(event):
|
|
return reverse('event-hanchan-list', kwargs={'event': event.id})
|
|
|
|
|
|
class MajongSeasonSitemap(Sitemap):
|
|
priority = 0.5
|
|
|
|
@staticmethod
|
|
def items():
|
|
seasons = SeasonRanking.objects.all().distinct('season').order_by(
|
|
'season')
|
|
seasons = seasons.values_list('season', flat=True)
|
|
return seasons
|
|
|
|
@staticmethod
|
|
def location(season):
|
|
return reverse('mahjong-ladder', kwargs={'season': season})
|
|
|
|
@staticmethod
|
|
def changefreq(season):
|
|
if season == date.today().year:
|
|
return 'weekly'
|
|
else:
|
|
return 'never'
|