Coverage for apis_core/history/tables.py: 96%

25 statements  

« prev     ^ index     » next       coverage.py v7.6.8, created at 2024-12-20 09:24 +0000

1import django_tables2 as tables 

2 

3from apis_core.generic.tables import CustomTemplateColumn, ViewColumn 

4 

5 

6class DescriptionColumnHistory(CustomTemplateColumn): 

7 """ 

8 A column showing a model description 

9 """ 

10 

11 template_name = "history/columns/description.html" 

12 orderable = False 

13 

14 

15class OriginalIDColumn(CustomTemplateColumn): 

16 """ 

17 A column showing the original id of a model instance 

18 """ 

19 

20 template_name = "history/columns/original_id.html" 

21 orderable = False 

22 verbose_name = "Original ID" 

23 

24 

25class APISHistoryTableBaseTable(tables.Table): 

26 history_id = tables.Column(verbose_name="ID") 

27 original_id = OriginalIDColumn() 

28 desc = DescriptionColumnHistory() 

29 view = ViewColumn() 

30 

31 class Meta: 

32 fields = ["history_id", "desc", "most_recent", "view"] 

33 

34 

35class HistoryGenericTable(tables.Table): 

36 model = tables.Column(empty_values=()) 

37 fields_changed = tables.Column(empty_values=()) 

38 instance = tables.Column(linkify=lambda record: record.get_absolute_url()) 

39 fields_changed = tables.TemplateColumn( 

40 template_name="history/columns/fields_changed.html" 

41 ) 

42 

43 class Meta: 

44 fields = [ 

45 "model", 

46 "instance", 

47 "tag", 

48 "fields_changed", 

49 "history_type", 

50 "history_date", 

51 "history_user", 

52 ] 

53 

54 def render_model(self, record): 

55 return record.instance.__class__.__name__