Coverage for ivatar/context_processors.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v7.5.1, created at 2024-05-18 23:09 +0000

1# -*- coding: utf-8 -*- 

2""" 

3Default: useful variables for the base page templates. 

4""" 

5 

6from ipware import get_client_ip 

7from ivatar.settings import IVATAR_VERSION, SITE_NAME, MAX_PHOTO_SIZE 

8from ivatar.settings import BASE_URL, SECURE_BASE_URL 

9from ivatar.settings import MAX_NUM_UNCONFIRMED_EMAILS 

10 

11 

12def basepage(request): 

13 """ 

14 Our contextprocessor adds additional context variables 

15 in order to be used in the templates 

16 """ 

17 context = {} 

18 if "openid_identifier" in request.GET: 

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

20 "openid_identifier" 

21 ] # pragma: no cover 

22 client_ip = get_client_ip(request)[0] 

23 context["client_ip"] = client_ip 

24 context["ivatar_version"] = IVATAR_VERSION 

25 context["site_name"] = SITE_NAME 

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

27 context["max_file_size"] = MAX_PHOTO_SIZE 

28 context["BASE_URL"] = BASE_URL 

29 context["SECURE_BASE_URL"] = SECURE_BASE_URL 

30 context["max_emails"] = False 

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