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

__init__(app_name, app_module)[source]
classmethod create(entry)[source]

Factory that creates an app config from an entry in INSTALLED_APPS.

default_auto_field[source]
get_model(model_name, require_ready=True)[source]

Return the model with the given case-insensitive model_name.

Raise LookupError if no model exists with this name.

get_models(include_auto_created=False, include_swapped=False)[source]

Return an iterable of models.

By default, the following models aren’t included:

  • auto-created models for many-to-many relations without an explicit intermediate table,

  • models that have been swapped out.

Set the corresponding keyword argument to True to include such models. Keyword arguments aren’t documented; they’re a private API.

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

Full Python path to the application

ready()[source]

Override this method in subclasses to run code when Django starts.

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

_abc_impl = <_abc._abc_data object>[source]
_get(name, item, default=None)[source]
_items()[source]
_languages()[source]
_location(item, force_lang_code=None)[source]
_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]]

alternates = False[source]
changefreq: str = 'daily'[source]

The usual change frequency of this sitemap’s urls

get_domain(site=None)[source]
get_languages_for_item(item)[source]

Languages for which this item is displayed.

get_latest_lastmod()[source]
get_protocol(protocol=None)[source]
get_urls(page=1, site=None, protocol=None)[source]
i18n = False[source]
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]

languages = None[source]
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

limit = 50000[source]
location(item)[source]
property paginator[source]
priority: float = 0.5[source]

The default priority for all sitemap’s urls

protocol = None[source]
queryset: QuerySet[EventTranslation] = QuerySet[source]

The EventTranslation QuerySet of this sitemap

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]]

x_default = False[source]
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

_abc_impl = <_abc._abc_data object>[source]
_get(name, item, default=None)[source]
_items()[source]
_languages()[source]
_location(item, force_lang_code=None)[source]
_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]]

alternates = False[source]
changefreq: str = 'monthly'[source]

The default change frequency for all sitemap’s urls

get_domain(site=None)[source]
get_languages_for_item(item)[source]

Languages for which this item is displayed.

get_latest_lastmod()[source]
get_protocol(protocol=None)[source]
get_urls(page=1, site=None, protocol=None)[source]
i18n = False[source]
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]

languages = None[source]
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

limit = 50000[source]
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

property paginator[source]
priority: float = 1.0[source]

The priority of this sitemap’s urls (1.0)

protocol = None[source]
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]]

x_default = False[source]
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

_abc_impl = <_abc._abc_data object>[source]
_get(name, item, default=None)[source]
_items()[source]
_languages()[source]
_location(item, force_lang_code=None)[source]
_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]]

alternates = False[source]
changefreq: str = 'monthly'[source]

The default change frequency for all sitemap’s urls

get_domain(site=None)[source]
get_languages_for_item(item)[source]

Languages for which this item is displayed.

get_latest_lastmod()[source]
get_protocol(protocol=None)[source]
get_urls(page=1, site=None, protocol=None)[source]
i18n = False[source]
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]

languages = None[source]
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

limit = 50000[source]
location(item)[source]
property paginator[source]
priority: float = 0.5[source]

The default priority for all sitemap’s urls

protocol = None[source]
queryset: QuerySet[POITranslation] = QuerySet[source]

The POITranslation QuerySet queryset of this sitemap

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]]

x_default = False[source]
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

_abc_impl = <_abc._abc_data object>[source]
_get(name, item, default=None)[source]
_items()[source]
_languages()[source]
_location(item, force_lang_code=None)[source]
_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]]

alternates = False[source]
changefreq: str = 'monthly'[source]

The default change frequency for all sitemap’s urls

get_domain(site=None)[source]
get_languages_for_item(item)[source]

Languages for which this item is displayed.

get_latest_lastmod()[source]
get_protocol(protocol=None)[source]
get_urls(page=1, site=None, protocol=None)[source]
i18n = False[source]
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]

languages = None[source]
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

limit = 50000[source]
location(item)[source]
property paginator[source]
priority: float = 1.0[source]

The priority of this sitemap’s urls

protocol = None[source]
queryset: QuerySet[PageTranslation] = QuerySet[source]

The PageTranslation QuerySet of this sitemap

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]]

x_default = False[source]
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

_abc_impl = <_abc._abc_data object>[source]
_get(name, item, default=None)[source]
_items()[source]
_languages()[source]
_location(item, force_lang_code=None)[source]
_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]]

alternates = False[source]
changefreq: str = 'monthly'[source]

The default change frequency for all sitemap’s urls

get_domain(site=None)[source]
get_languages_for_item(item)[source]

Languages for which this item is displayed.

get_latest_lastmod()[source]
get_protocol(protocol=None)[source]
get_urls(page=1, site=None, protocol=None)[source]
i18n = False[source]
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]

languages = None[source]
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

limit = 50000[source]
location(item)[source]
property paginator[source]
priority: float = 0.5[source]

The default priority for all sitemap’s urls

protocol = None[source]
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]]

x_default = False[source]

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

__init__(**kwargs)[source]

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

classmethod as_view(**initkwargs)[source]

Main entry point for a request-response process.

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

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

dispatch(request, *args, **kwargs)[source]
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

get_template_names()[source]

Return a list of template names to be used for the request. Must return a list. May not be called if render_to_response() is overridden.

http_method_names = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace'][source]
http_method_not_allowed(request, *args, **kwargs)[source]
options(request, *args, **kwargs)[source]

Handle responding to requests for the OPTIONS HTTP verb.

render_to_response(context, **response_kwargs)[source]

Return a response, using the response_class for this view, with a template rendered with the given context.

Pass response_kwargs to the constructor of the response class.

response_class[source]

alias of TemplateResponse

setup(request, *args, **kwargs)[source]

Initialize attributes shared by all view methods.

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

The template to render (see TemplateResponseMixin)

view_is_async = False[source]
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)

__init__(**kwargs)[source]

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

classmethod as_view(**initkwargs)[source]

Main entry point for a request-response process.

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

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

dispatch(request, *args, **kwargs)[source]
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

get_template_names()[source]

Return a list of template names to be used for the request. Must return a list. May not be called if render_to_response() is overridden.

http_method_names = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace'][source]
http_method_not_allowed(request, *args, **kwargs)[source]
options(request, *args, **kwargs)[source]

Handle responding to requests for the OPTIONS HTTP verb.

render_to_response(context, **response_kwargs)[source]

Return a response, using the response_class for this view, with a template rendered with the given context.

Pass response_kwargs to the constructor of the response class.

response_class[source]

alias of TemplateResponse

setup(request, *args, **kwargs)[source]

Initialize attributes shared by all view methods.

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

The template to render (see TemplateResponseMixin)

view_is_async = False[source]