-
Notifications
You must be signed in to change notification settings - Fork 35
/
utils.py
43 lines (31 loc) · 1.32 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
This module contains utils for the sitemap app.
"""
from __future__ import annotations
import logging
from typing import TYPE_CHECKING
from .sitemaps import EventSitemap, OfferSitemap, PageSitemap, POISitemap
if TYPE_CHECKING:
from typing import Any
from integreat_cms.cms.models.languages.language import Language
from integreat_cms.cms.models.regions.region import Region
logger = logging.getLogger(__name__)
def get_sitemaps(region: Region, language: Language) -> list[Any]:
"""
This helper function generates a list of all non-empty sitemaps for a given region and language
It is used in :class:`~integreat_cms.sitemap.views.SitemapIndexView` and :class:`~integreat_cms.sitemap.views.SitemapView`.
:param region: The requested region
:param language: The requested language
:return: All sitemaps for the given region and language
"""
sitemaps = [
PageSitemap(region, language),
POISitemap(region, language),
OfferSitemap(region, language),
]
if region.events_enabled:
sitemaps.append(EventSitemap(region, language))
# Only return sitemaps which actually contain items
sitemaps = [sitemap for sitemap in sitemaps if sitemap.items().exists()]
logger.debug("Sitemaps for %r and %r: %r", region, language, sitemaps)
return sitemaps