Coverage for ivatar/context_processors.py: 100%

22 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-10-24 23:06 +0000

1""" 

2Default: useful variables for the base page templates. 

3""" 

4 

5from ipware import get_client_ip # type: ignore 

6from ivatar.settings import IVATAR_VERSION, SITE_NAME, MAX_PHOTO_SIZE 

7from ivatar.settings import BASE_URL, SECURE_BASE_URL 

8from ivatar.settings import MAX_NUM_UNCONFIRMED_EMAILS 

9 

10 

11def basepage(request): 

12 """ 

13 Our contextprocessor adds additional context variables 

14 in order to be used in the templates 

15 """ 

16 context = {} 

17 if "openid_identifier" in request.GET: 

18 context["openid_identifier"] = request.GET[ 

19 "openid_identifier" 

20 ] # pragma: no cover 

21 client_ip = get_client_ip(request)[0] 

22 context["client_ip"] = client_ip 

23 context["ivatar_version"] = IVATAR_VERSION 

24 context["site_name"] = SITE_NAME 

25 context["site_url"] = request.build_absolute_uri("/")[:-1] 

26 context["max_file_size"] = MAX_PHOTO_SIZE 

27 context["BASE_URL"] = BASE_URL 

28 context["SECURE_BASE_URL"] = SECURE_BASE_URL 

29 context["max_emails"] = False 

30 

31 if request.user: 

32 if not request.user.is_anonymous: 

33 unconfirmed = request.user.unconfirmedemail_set.count() 

34 if unconfirmed >= MAX_NUM_UNCONFIRMED_EMAILS: 

35 context["max_emails"] = True 

36 

37 return context