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
- classmethod create(entry)[source]
Factory that creates an app config from an entry in INSTALLED_APPS.
- 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.
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.
- _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 withWEBAPP_URL
because out of the box, The sitemap framework does only support this functionality when used together with The “sites” framework.
- 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
- 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:
- 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.
- _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 withWEBAPP_URL
because out of the box, The sitemap framework does only support this functionality when used together with The “sites” framework.
- 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
- 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:
- 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:
- 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.
- _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 withWEBAPP_URL
because out of the box, The sitemap framework does only support this functionality when used together with The “sites” framework.
- 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
- 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:
- 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.
- _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 withWEBAPP_URL
because out of the box, The sitemap framework does only support this functionality when used together with The “sites” framework.
- 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
- 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:
- class integreat_cms.sitemap.sitemaps.WebappSitemap(region: Region, language: Language)[source]
-
This is an abstract base class for all webapp sitemaps.
- __init__(region: Region, language: Language) None [source]
This init function sets the region and language parameters.
- _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 withWEBAPP_URL
because out of the box, The sitemap framework does only support this functionality when used together with The “sites” framework.
- 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
- 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:
Urls
Django URL dispatcher for the sitemap package. It contains the following routes:
/sitemap.xml
is routed toSitemapIndexView
/<region_slug>/<language_slug>/sitemap.xml
is routed toSitemapView
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
andSitemapView
.
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 sitemapEmpty sitemaps are not included in the index
- __init__(**kwargs)[source]
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- 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
- 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.
- 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
- 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 ofdjango.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.
- 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
andlanguage_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.
- 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
- template_name: str = 'sitemap.xml'[source]
The template to render (see
TemplateResponseMixin
)