2020-01-21 06:35:58 +00:00
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.contrib.sitemaps import Sitemap
|
|
|
|
from django.urls import reverse
|
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
|
from judge.models import BlogPost, Contest, Organization, Problem, Solution
|
|
|
|
|
|
|
|
|
|
|
|
class ProblemSitemap(Sitemap):
|
2022-05-14 17:57:27 +00:00
|
|
|
changefreq = "daily"
|
2020-01-21 06:35:58 +00:00
|
|
|
priority = 0.8
|
|
|
|
|
|
|
|
def items(self):
|
2022-05-14 17:57:27 +00:00
|
|
|
return Problem.get_public_problems().values_list("code")
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
def location(self, obj):
|
2022-05-14 17:57:27 +00:00
|
|
|
return reverse("problem_detail", args=obj)
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UserSitemap(Sitemap):
|
2022-05-14 17:57:27 +00:00
|
|
|
changefreq = "hourly"
|
2020-01-21 06:35:58 +00:00
|
|
|
priority = 0.5
|
|
|
|
|
|
|
|
def items(self):
|
2022-05-14 17:57:27 +00:00
|
|
|
return User.objects.values_list("username")
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
def location(self, obj):
|
2022-05-14 17:57:27 +00:00
|
|
|
return reverse("user_page", args=obj)
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ContestSitemap(Sitemap):
|
2022-05-14 17:57:27 +00:00
|
|
|
changefreq = "hourly"
|
2020-01-21 06:35:58 +00:00
|
|
|
priority = 0.5
|
|
|
|
|
|
|
|
def items(self):
|
2022-05-14 17:57:27 +00:00
|
|
|
return Contest.objects.filter(
|
|
|
|
is_visible=True, is_private=False, is_organization_private=False
|
|
|
|
).values_list("key")
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
def location(self, obj):
|
2022-05-14 17:57:27 +00:00
|
|
|
return reverse("contest_view", args=obj)
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OrganizationSitemap(Sitemap):
|
2022-05-14 17:57:27 +00:00
|
|
|
changefreq = "hourly"
|
2020-01-21 06:35:58 +00:00
|
|
|
priority = 0.5
|
|
|
|
|
|
|
|
def items(self):
|
2022-05-14 17:57:27 +00:00
|
|
|
return Organization.objects.values_list("id", "slug")
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
def location(self, obj):
|
2022-05-14 17:57:27 +00:00
|
|
|
return reverse("organization_home", args=obj)
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BlogPostSitemap(Sitemap):
|
2022-05-14 17:57:27 +00:00
|
|
|
changefreq = "hourly"
|
2020-01-21 06:35:58 +00:00
|
|
|
priority = 0.7
|
|
|
|
|
|
|
|
def items(self):
|
2022-05-14 17:57:27 +00:00
|
|
|
return BlogPost.objects.filter(
|
|
|
|
visible=True, is_organization_private=False, publish_on__lte=timezone.now()
|
|
|
|
).values_list("id", "slug")
|
|
|
|
|
2020-01-21 06:35:58 +00:00
|
|
|
def location(self, obj):
|
2022-05-14 17:57:27 +00:00
|
|
|
return reverse("blog_post", args=obj)
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SolutionSitemap(Sitemap):
|
2022-05-14 17:57:27 +00:00
|
|
|
changefreq = "hourly"
|
2020-01-21 06:35:58 +00:00
|
|
|
priority = 0.8
|
|
|
|
|
|
|
|
def items(self):
|
2022-05-14 17:57:27 +00:00
|
|
|
return Solution.objects.filter(
|
|
|
|
is_public=True, publish_on__lte=timezone.now(), problem__isnull=False
|
|
|
|
).values_list("problem__code")
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
def location(self, obj):
|
2022-05-14 17:57:27 +00:00
|
|
|
return reverse("problem_editorial", args=obj)
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class HomePageSitemap(Sitemap):
|
|
|
|
priority = 1.0
|
2022-05-14 17:57:27 +00:00
|
|
|
changefreq = "daily"
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
def items(self):
|
2022-05-14 17:57:27 +00:00
|
|
|
return ["home"]
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
def location(self, obj):
|
|
|
|
return reverse(obj)
|
|
|
|
|
|
|
|
|
|
|
|
class UrlSitemap(Sitemap):
|
|
|
|
def __init__(self, pages):
|
|
|
|
self.pages = pages
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
return self.pages
|
|
|
|
|
|
|
|
def location(self, obj):
|
2022-05-14 17:57:27 +00:00
|
|
|
return obj["location"] if isinstance(obj, dict) else obj
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
def priority(self, obj):
|
2022-05-14 17:57:27 +00:00
|
|
|
return obj.get("priority", 0.5) if isinstance(obj, dict) else 0.5
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
def changefreq(self, obj):
|
2022-05-14 17:57:27 +00:00
|
|
|
return obj.get("changefreq", "daily") if isinstance(obj, dict) else "daily"
|