Coverage for ivatar/context_processors.py: 100%
21 statements
« prev ^ index » next coverage.py v7.11.3, created at 2025-11-16 00:07 +0000
« prev ^ index » next coverage.py v7.11.3, created at 2025-11-16 00:07 +0000
1"""
2Default: useful variables for the base page templates.
3"""
5from django.conf import settings
6from ipware import get_client_ip # type: ignore
9def basepage(request):
10 """
11 Our contextprocessor adds additional context variables
12 in order to be used in the templates
13 """
14 context = {}
15 if "openid_identifier" in request.GET:
16 context["openid_identifier"] = request.GET[
17 "openid_identifier"
18 ] # pragma: no cover
19 client_ip = get_client_ip(request)[0]
20 context["client_ip"] = client_ip
21 context["ivatar_version"] = getattr(settings, "IVATAR_VERSION", "2.0")
22 context["site_name"] = getattr(settings, "SITE_NAME", "libravatar")
23 context["site_url"] = request.build_absolute_uri("/")[:-1]
24 context["max_file_size"] = getattr(settings, "MAX_PHOTO_SIZE", 10485760)
25 context["BASE_URL"] = getattr(settings, "BASE_URL", "http://localhost:8000/avatar/")
26 context["SECURE_BASE_URL"] = getattr(
27 settings, "SECURE_BASE_URL", "https://localhost:8000/avatar/"
28 )
29 context["max_emails"] = False
31 if request.user:
32 if not request.user.is_anonymous:
33 unconfirmed = request.user.unconfirmedemail_set.count()
34 max_unconfirmed = getattr(settings, "MAX_NUM_UNCONFIRMED_EMAILS", 5)
35 if unconfirmed >= max_unconfirmed:
36 context["max_emails"] = True
38 return context