Coverage for sites/ptf_tools/ptf_tools/templatetags/tools_helpers.py: 97%

17 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2024-07-18 09:02 +0000

1from django import template 

2from django.conf import settings 

3from django.contrib.auth.models import AnonymousUser 

4from django.contrib.auth.models import User 

5from django.template.defaultfilters import stringfilter 

6 

7register = template.Library() 

8 

9 

10@register.filter 

11@stringfilter 

12def get_mersenne_collections(value): 

13 return settings.MERSENNE_COLLECTIONS 

14 

15 

16@register.filter 

17def get_authorized_collections(user: User | AnonymousUser) -> list[str]: 

18 ids = [] 

19 for group in user.groups.all(): 

20 if hasattr(group, "collectiongroup"): 20 ↛ 19line 20 didn't jump to line 19, because the condition on line 20 was never false

21 ids.extend([col.pid for col in group.collectiongroup.collections.all()]) 

22 return sorted(ids)