Coverage for apis_core/history/tables.py: 96%
25 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-22 07:51 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-22 07:51 +0000
1import django_tables2 as tables
3from apis_core.generic.tables import CustomTemplateColumn, ViewColumn
6class DescriptionColumnHistory(CustomTemplateColumn):
7 """
8 A column showing a model description
9 """
11 template_name = "history/columns/description.html"
12 orderable = False
15class OriginalIDColumn(CustomTemplateColumn):
16 """
17 A column showing the original id of a model instance
18 """
20 template_name = "history/columns/original_id.html"
21 orderable = False
22 verbose_name = "Original ID"
25class APISHistoryTableBaseTable(tables.Table):
26 history_id = tables.Column(verbose_name="ID")
27 original_id = OriginalIDColumn()
28 desc = DescriptionColumnHistory()
29 view = ViewColumn()
31 class Meta:
32 fields = ["history_id", "desc", "most_recent", "view"]
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 )
43 class Meta:
44 fields = [
45 "model",
46 "instance",
47 "tag",
48 "fields_changed",
49 "history_type",
50 "history_date",
51 "history_user",
52 ]
54 def render_model(self, record):
55 return record.instance.__class__.__name__