Sitemap

This package contains all classes for building the webapp’s sitemap dynamically. It makes use of The sitemap framework, an inbuilt Django package.

Apps

class integreat_cms.sitemap.apps.SitemapConfig(app_name, app_module)[source]

Bases: AppConfig

This is the basic configuration for the sitemap app

name: Final[str] = 'integreat_cms.sitemap'[source]

Full Python path to the application

verbose_name: Final[Promise] = 'Sitemap'[source]

Human-readable name for the application

Sitemaps

This module contains all sitemap classes which are all based on django.contrib.sitemaps.Sitemap.

class integreat_cms.sitemap.sitemaps.EventSitemap(region: Region, language: Language)[source]

Bases: WebappSitemap

This sitemap contains all urls to event translations for a specific region and language.

Attributes inherited from WebappSitemap:

Attribute priority:

The priority of this sitemap’s urls (see WebappSitemap.priority)

Parameters:
__init__(region: Region, language: Language) None[source]

This init function filters the queryset of event translation objects based on the given region and language.

Parameters:
  • region (Region) – The region of this sitemap’s urls

  • language (Language) – The language of this sitemap’s urls

Return type:

None

changefreq: str = 'daily'[source]

The usual change frequency of this sitemap’s urls

queryset: QuerySet[EventTranslation] = QuerySet[source]

The EventTranslation QuerySet of this sitemap

class integreat_cms.sitemap.sitemaps.OfferSitemap(region: Region, language: Language)[source]

Bases: WebappSitemap

This sitemap contains all urls to offers for a specific region.

Attributes inherited from WebappSitemap:

Attribute changefreq:

The usual change frequency of this sitemap’s urls (see WebappSitemap.changefreq)

Parameters:
__init__(region: Region, language: Language) None[source]

This init function filters the queryset of offers objects based on the given region.

Parameters:
  • region (Region) – The region of this sitemap’s urls

  • language (Language) – The language of this sitemap’s urls

Return type:

None

location(item: OfferTemplate) str[source]

This location function returns the absolute path for a given object returned by items().

Parameters:

item (OfferTemplate) – Objects passed from items() method

Returns:

The absolute path of the given offer object

Return type:

str

priority: float = 1.0[source]

The priority of this sitemap’s urls (1.0)

queryset: QuerySet[OfferTemplate] = QuerySet[source]

The OfferTemplate QuerySet queryset of this sitemap

sitemap_alternates(obj: OfferTemplate) list[dict[str, str]][source]

This sitemap_alternates function returns the language alternatives of offers for the use in sitemaps.

Parameters:

obj (OfferTemplate) – Objects passed from items() method

Returns:

A list of dictionaries containing the alternative translations of offers

Return type:

list[dict[str, str]]

class integreat_cms.sitemap.sitemaps.POISitemap(region: Region, language: Language)[source]

Bases: WebappSitemap

This sitemap contains all urls to POI translations for a specific region and language.

Attributes inherited from WebappSitemap:

Attribute changefreq:

The usual change frequency of this sitemap’s urls (see WebappSitemap.changefreq)

Attribute priority:

The priority of this sitemap’s urls (see WebappSitemap.priority)

Parameters:
__init__(region: Region, language: Language) None[source]

This init function filters the queryset of POI translation objects based on the given region and language.

Parameters:
  • region (Region) – The region of this sitemap’s urls

  • language (Language) – The language of this sitemap’s urls

Return type:

None

queryset: QuerySet[POITranslation] = QuerySet[source]

The POITranslation QuerySet queryset of this sitemap

class integreat_cms.sitemap.sitemaps.PageSitemap(region: Region, language: Language)[source]

Bases: WebappSitemap

This sitemap contains all urls to page translations for a specific region and language.

Attributes inherited from WebappSitemap:

Attribute changefreq:

The usual change frequency of this sitemap’s urls (see WebappSitemap.changefreq)

Parameters:
__init__(region: Region, language: Language) None[source]

This init function filters the queryset of page translation objects based on the given region and language.

Parameters:
  • region (Region) – The region of this sitemap’s urls

  • language (Language) – The language of this sitemap’s urls

Return type:

None

priority: float = 1.0[source]

The priority of this sitemap’s urls

queryset: QuerySet[PageTranslation] = QuerySet[source]

The PageTranslation QuerySet of this sitemap

class integreat_cms.sitemap.sitemaps.WebappSitemap(region: Region, language: Language)[source]

Bases: ABC, Sitemap

This is an abstract base class for all webapp sitemaps.

Parameters:
__init__(region: Region, language: Language) None[source]

This init function sets the region and language parameters.

Parameters:
  • region (Region) – The region of this sitemap’s urls

  • language (Language) – The language of this sitemap’s urls

Return type:

None

_urls(page: int, protocol: str, domain: str) list[dict[str, Any]][source]

This is a patched version of django.contrib.sitemaps.Sitemap._urls() which adds the alternative languages to the list of urls. This patch is required because the inbuilt function can only deal with the i18n backend languages and not with our custom language model. Additionally, it overwrites the protocol and domain of the urls with WEBAPP_URL because out of the box, The sitemap framework does only support this functionality when used together with The “sites” framework.

Parameters:
  • page (int) – The page for the paginator (will always be 1 in our case)

  • protocol (str) – The protocol of the urls

  • domain (str) – The domain of the urls

Returns:

A list of urls

Return type:

list[dict[str, Any]]

changefreq: str = 'monthly'[source]

The default change frequency for all sitemap’s urls

items() QuerySet[OfferTemplate | AbstractContentTranslation][source]

This functions returns the public translations contained in this sitemap.

Returns:

The queryset of translation objects

Return type:

QuerySet[OfferTemplate | AbstractContentTranslation]

static lastmod(translation: OfferTemplate | AbstractContentTranslation) datetime[source]

This functions returns the date when a translation was last modified.

Parameters:

translation (OfferTemplate | AbstractContentTranslation) – The given translation ~integreat_cms.cms.models.events.event_translation.EventTranslation, or ~integreat_cms.cms.models.pois.poi_translation.POITranslation

Returns:

The list of urls

Return type:

datetime

priority: float = 0.5[source]

The default priority for all sitemap’s urls

abstract property queryset: QuerySet[OfferTemplate | AbstractContentTranslation][source]

Each subclass needs at least a queryset attribute defined.

sitemap_alternates(obj: OfferTemplate | AbstractContentTranslation) list[dict[str, str]][source]

This function returns the sitemap alternatives for a given object

Parameters:

obj (OfferTemplate | AbstractContentTranslation) – The object

Returns:

The sitemap alternates of the given object

Return type:

list[dict[str, str]]

Urls

Django URL dispatcher for the sitemap package. It contains the following routes:

See urls for the other namespaces of this application.

For more information on this file, see URL dispatcher.

integreat_cms.sitemap.urls.app_name: Final = 'sitemap'[source]

The namespace for this URL config (see django.urls.ResolverMatch.app_name)

integreat_cms.sitemap.urls.urlpatterns: list[URLPattern] = [<URLPattern 'sitemap.xml' [name='index']>, <URLPattern 'wp-json/ig-sitemap/v1/sitemap-index.xml'>, <URLResolver <URLPattern list> (None:None) '<slug:region_slug>/<slug:language_slug>/'>][source]

The url patterns of this module (see URL dispatcher)

[
    <URLPattern 'sitemap.xml' [name='index']>,
    <URLPattern 'wp-json/ig-sitemap/v1/sitemap-index.xml'>,
    <URLResolver <URLPattern list> (None:None) '<slug:region_slug>/<slug:language_slug>/'>,
]

Utils

This module contains utils for the sitemap app.

integreat_cms.sitemap.utils.get_sitemaps(region: Region, language: Language) list[Any][source]

This helper function generates a list of all non-empty sitemaps for a given region and language It is used in SitemapIndexView and SitemapView.

Parameters:
  • region (Region) – The requested region

  • language (Language) – The requested language

Returns:

All sitemaps for the given region and language

Return type:

list[Any]

Views

This module contains views for generating the sitemap dynamically. The views are class-based patches of the inbuilt views index() and sitemap() of the django.contrib.sitemaps The sitemap framework.

class integreat_cms.sitemap.views.SitemapIndexView(**kwargs)[source]

Bases: TemplateResponseMixin, View

This view allows to generate a sitemap index dynamically. It is a patched version of django.contrib.sitemaps.views.index() with the following changes:

  • Sitemaps dynamically queried on each request, not on the application startup

  • WEBAPP_URL is used for the domain instead of the host of the sitemap

  • Empty sitemaps are not included in the index

content_type: str = 'application/xml'[source]

The content type to use for the response (see TemplateResponseMixin)

get(request: HttpRequest, *args: Any, **kwargs: Any) TemplateResponse[source]

This function handles a get request

Parameters:
  • request (HttpRequest) – The current request

  • *args (Any) – The supplied args

  • **kwargs (Any) – The supplied keyword args

Returns:

The rendered template response

Return type:

TemplateResponse

template_name: str = 'sitemap_index.xml'[source]

The template to render (see TemplateResponseMixin)

class integreat_cms.sitemap.views.SitemapView(**kwargs)[source]

Bases: TemplateResponseMixin, View

This view allows to generate a sitemap dynamically. A sitemap contains the urls of multiple WebappSitemap instances, one for each content type. It is a patched version of django.contrib.sitemaps.views.sitemap() with the following changes:

  • Sitemaps dynamically queried on each request, not on the application startup

  • HTTP 404 returned if sitemap is empty

  • Support for pagination was dropped (only needed with more than 50000 urls per region and language)

content_type: str = 'application/xml'[source]

The content type to use for the response (see TemplateResponseMixin)

get(request: HttpRequest, *args: Any, **kwargs: Any) TemplateResponse[source]

This function handles a get request

Parameters:
  • request (HttpRequest) – The current request

  • *args (Any) – The supplied args

  • **kwargs (Any) – The supplied keyword args (should contain region_slug and language_slug)

Raises:

Http404 – Raises a HTTP 404 if the either the region or language does not exist or is invalid or if the sitemap is empty.

Returns:

The rendered template response

Return type:

TemplateResponse

template_name: str = 'sitemap.xml'[source]

The template to render (see TemplateResponseMixin)