From 68f6cf08b290d8fff6c99f5007c7b9cfb088020d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Barrag=C3=A1n=20Merino?= Date: Fri, 2 Sep 2016 10:47:06 +0200 Subject: [PATCH] Add epics to the sitemap generator --- taiga/front/sitemaps/__init__.py | 6 ++++ taiga/front/sitemaps/epics.py | 54 ++++++++++++++++++++++++++++++++ taiga/front/sitemaps/projects.py | 28 +++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 taiga/front/sitemaps/epics.py diff --git a/taiga/front/sitemaps/__init__.py b/taiga/front/sitemaps/__init__.py index abc78ffe..8c7adfa8 100644 --- a/taiga/front/sitemaps/__init__.py +++ b/taiga/front/sitemaps/__init__.py @@ -21,11 +21,14 @@ from collections import OrderedDict from .generics import GenericSitemap from .projects import ProjectsSitemap +from .projects import ProjectEpicsSitemap from .projects import ProjectBacklogsSitemap from .projects import ProjectKanbansSitemap from .projects import ProjectIssuesSitemap from .projects import ProjectTeamsSitemap +from .epics import EpicsSitemap + from .milestones import MilestonesSitemap from .userstories import UserStoriesSitemap @@ -43,11 +46,14 @@ sitemaps = OrderedDict([ ("generics", GenericSitemap), ("projects", ProjectsSitemap), + ("project-epics-list", ProjectEpicsSitemap), ("project-backlogs", ProjectBacklogsSitemap), ("project-kanbans", ProjectKanbansSitemap), ("project-issues-list", ProjectIssuesSitemap), ("project-teams", ProjectTeamsSitemap), + ("epics", EpicsSitemap), + ("milestones", MilestonesSitemap), ("userstories", UserStoriesSitemap), diff --git a/taiga/front/sitemaps/epics.py b/taiga/front/sitemaps/epics.py new file mode 100644 index 00000000..81f391f6 --- /dev/null +++ b/taiga/front/sitemaps/epics.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2014-2016 Andrey Antukh +# Copyright (C) 2014-2016 Jesús Espino +# Copyright (C) 2014-2016 David Barragán +# Copyright (C) 2014-2016 Alejandro Alonso +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from django.db.models import Q +from django.apps import apps + +from taiga.front.templatetags.functions import resolve + +from .base import Sitemap + + +class EpicsSitemap(Sitemap): + def items(self): + epic_model = apps.get_model("epics", "Epic") + + # Get epics of public projects OR private projects if anon user can view them + queryset = epic_model.objects.filter(Q(project__is_private=False) | + Q(project__is_private=True, + project__anon_permissions__contains=["view_epics"])) + + # Exclude blocked projects + queryset = queryset.filter(project__blocked_code__isnull=True) + + # Project data is needed + queryset = queryset.select_related("project") + + return queryset + + def location(self, obj): + return resolve("epic", obj.project.slug, obj.ref) + + def lastmod(self, obj): + return obj.modified_date + + def changefreq(self, obj): + return "daily" + + def priority(self, obj): + return 0.4 diff --git a/taiga/front/sitemaps/projects.py b/taiga/front/sitemaps/projects.py index a7e45d50..77785928 100644 --- a/taiga/front/sitemaps/projects.py +++ b/taiga/front/sitemaps/projects.py @@ -51,6 +51,34 @@ class ProjectsSitemap(Sitemap): return 0.9 +class ProjectEpicsSitemap(Sitemap): + def items(self): + project_model = apps.get_model("projects", "Project") + + # Get public projects OR private projects if anon user can view them and epics + queryset = project_model.objects.filter(Q(is_private=False) | + Q(is_private=True, + anon_permissions__contains=["view_project", + "view_epics"])) + + # Exclude projects without epics enabled + queryset = queryset.exclude(is_epics_activated=False) + + return queryset + + def location(self, obj): + return resolve("epics", obj.slug) + + def lastmod(self, obj): + return obj.modified_date + + def changefreq(self, obj): + return "daily" + + def priority(self, obj): + return 0.6 + + class ProjectBacklogsSitemap(Sitemap): def items(self): project_model = apps.get_model("projects", "Project")