Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/utils.py
# Copyright (C) 2017-2020 The Software Heritage developers | # Copyright (C) 2017-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from datetime import datetime, timezone | from datetime import datetime, timezone | ||||
import os | |||||
import re | import re | ||||
from typing import Any, Dict, Optional | from typing import Any, Dict, Optional | ||||
from bs4 import BeautifulSoup | from bs4 import BeautifulSoup | ||||
from docutils.core import publish_parts | from docutils.core import publish_parts | ||||
import docutils.parsers.rst | import docutils.parsers.rst | ||||
import docutils.utils | import docutils.utils | ||||
from docutils.writers.html5_polyglot import HTMLTranslator, Writer | from docutils.writers.html5_polyglot import HTMLTranslator, Writer | ||||
▲ Show 20 Lines • Show All 243 Lines • ▼ Show 20 Lines | def context_processor(request): | ||||
return { | return { | ||||
"swh_object_icons": swh_object_icons, | "swh_object_icons": swh_object_icons, | ||||
"available_languages": None, | "available_languages": None, | ||||
"swh_client_config": config["client_config"], | "swh_client_config": config["client_config"], | ||||
"oidc_enabled": bool(config["keycloak"]["server_url"]), | "oidc_enabled": bool(config["keycloak"]["server_url"]), | ||||
"browsers_supported_image_mimes": browsers_supported_image_mimes, | "browsers_supported_image_mimes": browsers_supported_image_mimes, | ||||
"keycloak": config["keycloak"], | "keycloak": config["keycloak"], | ||||
"site_base_url": request.build_absolute_uri("/"), | "site_base_url": request.build_absolute_uri("/"), | ||||
"DJANGO_SETTINGS_MODULE": os.environ["DJANGO_SETTINGS_MODULE"], | |||||
} | } | ||||
class EnforceCSRFAuthentication(SessionAuthentication): | class EnforceCSRFAuthentication(SessionAuthentication): | ||||
""" | """ | ||||
Helper class to enforce CSRF validation on a DRF view | Helper class to enforce CSRF validation on a DRF view | ||||
when a user is not authenticated. | when a user is not authenticated. | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |