News Managers

Abstract News Manager

class integreat_cms.news_managers.abstract_news_manager.AbstractNewsManager[source]

Bases: ABC

__init__()[source]
collect_news_items(region_slug: str, language_slug: str, _channel: str) list[NewsItem][source]

Returns news items imported from the source

Parameters:
  • region_slug (str)

  • language_slug (str)

  • _channel (str)

Return type:

list[NewsItem]

find_post(region: Region, language: Language, news_raw_id: str) NewsItem[source]

Find and return a news item which matches the given ID

Parameters:
Return type:

NewsItem

get_cached_news_items(language_slug: str) list[NewsItem][source]

Return the cached news items for the given language.

If the cache key does not exist yet (i.e. the cache has not been warmed up), the news items are imported from the source on demand and the cache is populated before returning.

Parameters:

language_slug (str)

Return type:

list[NewsItem]

get_single_news(request: HttpRequest, region: Region, language: Language, news_id: str) JsonResponse[source]

Returns a news item that is imported from the source and matches the id

Parameters:
Return type:

JsonResponse

abstractmethod import_news_items() None[source]

Imports news items from the source

To be implemented in the inheriting model

Return type:

None

name: str[source]
short_name: str[source]
social_media_headers(request: HttpRequest, region: Region, language: Language, news_raw_id: str) HttpResponse[source]

Tries rendering the social media headers for a news page in a specified region and language

Parameters:
Return type:

HttpResponse

class integreat_cms.news_managers.abstract_news_manager.NewsItem[source]

Bases: TypedDict

__init__(*args, **kwargs)[source]
available_languages: dict | None[source]
channel: str | None[source]
clear()[source]

Remove all items from the dict.

content: str[source]
copy()[source]

Return a shallow copy of the dict.

display_date: datetime[source]
externalUrl: str[source]
classmethod fromkeys(iterable, value=None, /)[source]

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)[source]

Return the value for key if key is in the dictionary, else default.

id: str[source]
items()[source]

Return a set-like object providing a view on the dict’s items.

keys()[source]

Return a set-like object providing a view on the dict’s keys.

last_updated: datetime[source]
pop(k[, d]) v, remove specified key and return the corresponding value.[source]

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()[source]

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault(key, default=None, /)[source]

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

source: str[source]
title: str[source]
update([E, ]**F) None.  Update D from mapping/iterable E and F.[source]

If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()[source]

Return an object providing a view on the dict’s values.

integreat_cms.news_managers.abstract_news_manager.clean_html(html_string: str) str[source]

Remove unnecessary HTML elements from a Tü News post body.

Parameters:

html_string (str)

Return type:

str

Amalnews Manager

class integreat_cms.news_managers.amalnews_manager.AmalnewsManager[source]

Bases: AbstractNewsManager

__init__()[source]
collect_news_items(region_slug: str, language_slug: str, _channel: str) list[NewsItem][source]

Returns news items imported from the source

Parameters:
  • region_slug (str)

  • language_slug (str)

  • _channel (str)

Return type:

list[NewsItem]

find_post(region: Region, language: Language, news_raw_id: str) NewsItem[source]

Find and return a news item which matches the given ID

Parameters:
Return type:

NewsItem

get_cached_news_items(language_slug: str) list[NewsItem][source]

Return the cached news items for the given language.

If the cache key does not exist yet (i.e. the cache has not been warmed up), the news items are imported from the source on demand and the cache is populated before returning.

Parameters:

language_slug (str)

Return type:

list[NewsItem]

get_single_news(request: HttpRequest, region: Region, language: Language, news_id: str) JsonResponse[source]

Returns a news item that is imported from the source and matches the id

Parameters:
Return type:

JsonResponse

import_news_items() None[source]

Imports Amal News posts and save them as cache

Return type:

None

name: str = 'Amal News'[source]
short_name: str = 'amalnews'[source]
social_media_headers(request: HttpRequest, region: Region, language: Language, news_raw_id: str) HttpResponse[source]

Tries rendering the social media headers for a news page in a specified region and language

Parameters:
Return type:

HttpResponse

transform_post(post: _AmalnewsPost) NewsItem[source]

Transforms a post of Amal News so it can be used by the news endpoint directly

Parameters:

post (_AmalnewsPost)

Return type:

NewsItem

Pushnews Manager

class integreat_cms.news_managers.pushnews_manager.PushnewsManager[source]

Bases: AbstractNewsManager

__init__()[source]
collect_news_items(region_slug: str, language_slug: str, channel: str) list[NewsItem][source]

Returns push notification news for common news endpoint

Parameters:
  • region_slug (str)

  • language_slug (str)

  • channel (str)

Return type:

list[NewsItem]

collect_news_items_for_fcm(region_slug: str, language_slug: str, channel: str) list[dict[str, Any]][source]

Returns push notification news for fcm endpoint

Parameters:
  • region_slug (str)

  • language_slug (str)

  • channel (str)

Return type:

list[dict[str, Any]]

find_post(region: Region, language: Language, news_raw_id: str) NewsItem[source]

Find and return a news item which matches the given ID

Parameters:
Return type:

NewsItem

get_cached_news_items(language_slug: str) list[NewsItem][source]

Return the cached news items for the given language.

If the cache key does not exist yet (i.e. the cache has not been warmed up), the news items are imported from the source on demand and the cache is populated before returning.

Parameters:

language_slug (str)

Return type:

list[NewsItem]

get_single_news(request: HttpRequest, region: Region, language: Language, news_id: str) JsonResponse[source]

Returns a push notification that matches the id

Parameters:
Return type:

JsonResponse

import_news_items() None[source]

Push notifications live in our own database, so there is nothing to import.

Return type:

None

name: str = 'Local News'[source]
short_name: str = 'local'[source]
social_media_headers(request: HttpRequest, region: Region, language: Language, news_raw_id: str) HttpResponse[source]

Tries rendering the social media headers for a news page in a specified region and language

Parameters:
Return type:

HttpResponse

transform_notification(pnt: PushNotificationTranslation) NewsItem[source]

Function to create a JSON from a single push notification translation Object.

Parameters:

pnt (PushNotificationTranslation) – A push notification translation

Returns:

data necessary for API

Return type:

NewsItem

transform_notification_for_fcm(pnt: PushNotificationTranslation) dict[str, Any][source]

Function to create a JSON from a single push notification translation Object for fcm endpoint

The endpoint fcm/ requires timestamp and id in int.

Parameters:

pnt (PushNotificationTranslation) – A push notification translation

Returns:

data necessary for API

Return type:

dict[str, Any]

Registry

Registry of the available news source managers.

Tunews Manager

class integreat_cms.news_managers.tunews_manager.TunewsManager[source]

Bases: AbstractNewsManager

__init__()[source]
collect_news_items(region_slug: str, language_slug: str, _channel: str) list[NewsItem][source]

Returns news items imported from the source

Parameters:
  • region_slug (str)

  • language_slug (str)

  • _channel (str)

Return type:

list[NewsItem]

find_post(region: Region, language: Language, news_raw_id: str) NewsItem[source]

Find and return a news item which matches the given ID

Parameters:
Return type:

NewsItem

get_cached_news_items(language_slug: str) list[NewsItem][source]

Return the cached news items for the given language.

If the cache key does not exist yet (i.e. the cache has not been warmed up), the news items are imported from the source on demand and the cache is populated before returning.

Parameters:

language_slug (str)

Return type:

list[NewsItem]

get_single_news(request: HttpRequest, region: Region, language: Language, news_id: str) JsonResponse[source]

Returns a news item that is imported from the source and matches the id

Parameters:
Return type:

JsonResponse

import_news_items() None[source]

Imports Tü News posts and save them as cache

Return type:

None

name: str = 'Tü News'[source]
short_name: str = 'tunews'[source]
social_media_headers(request: HttpRequest, region: Region, language: Language, news_raw_id: str) HttpResponse[source]

Tries rendering the social media headers for a news page in a specified region and language

Parameters:
Return type:

HttpResponse

transform_post(post: _TunewsPost) NewsItem[source]

Transforms a post of Tü News so it can be used by the news endpoint directly

Parameters:

post (_TunewsPost)

Return type:

NewsItem