Coverage for apis_core/history/templatetags/history.py: 70%

20 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-22 07:51 +0000

1from django import template 

2from django.utils.safestring import mark_safe 

3 

4from apis_core.history.serializers import HistoryLogSerializer 

5from apis_core.history.utils import triple_sidebar_history 

6from apis_core.utils.helpers import get_html_diff 

7 

8register = template.Library() 

9 

10 

11@register.simple_tag(takes_context=True) 

12def object_relations_history(context, detail=True): 

13 obj = context["object"] 

14 return triple_sidebar_history(obj, context["request"], detail) 

15 

16 

17@register.filter 

18def get_history_data(obj): 

19 data = HistoryLogSerializer(obj.get_history_data(), many=True).data 

20 return data 

21 

22 

23@register.filter 

24def get_diff_old(change, shorten=0): 

25 return mark_safe(get_html_diff(a=change.old, b=change.new, show_b=False)) 

26 

27 

28@register.filter 

29def get_diff_new(change, shorten=0): 

30 return mark_safe(get_html_diff(a=change.old, b=change.new, show_a=False))