/
feedback_resource.py
77 lines (60 loc) · 2.21 KB
/
feedback_resource.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from typing import Any
from django.utils.translation import gettext_lazy as _
from import_export import fields, resources
from import_export.widgets import DateWidget
from ...models import Feedback
# pylint: disable=too-few-public-methods
class FeedbackResource(resources.ModelResource):
"""
This is the Resource class that connects to the django-import-export library
"""
category = fields.Field(
column_name=_("Category"),
attribute="category",
)
referring_to = fields.Field(
column_name=_("Feedback on"),
attribute="object_name",
)
language_name = fields.Field(
column_name=_("Language"),
attribute="language__translated_name",
)
rating = fields.Field(column_name=_("Rating"), attribute="get_rating_display")
read_by_username = fields.Field(
column_name=_("Read by"), attribute="read_by__full_user_name"
)
comment = fields.Field(column_name=_("Comment"), attribute="comment")
created_date = fields.Field(
column_name=_("Date"),
attribute="created_date",
widget=DateWidget(format="%d.%m.%Y %H:%M"),
)
# pylint: disable=useless-parent-delegation
def get_instance(self, *args: Any, **kwargs: Any) -> Any:
"""
See :meth:`import_export.resources.Resource.get_instance`
"""
return super().get_instance(*args, **kwargs)
def import_data(self, *args: Any, **kwargs: Any) -> Any:
"""
See :meth:`import_export.resources.Resource.import_data`
"""
return super().import_data(*args, **kwargs)
def import_row(self, *args: Any, **kwargs: Any) -> Any:
"""
See :meth:`import_export.resources.Resource.import_row`
"""
return super().import_row(*args, **kwargs)
def save_instance(self, *args: Any, **kwargs: Any) -> Any:
"""
See :meth:`import_export.resources.Resource.save_instance`
"""
return super().save_instance(*args, **kwargs)
class Meta:
"""
Meta class of feedback resource
"""
model = Feedback
# if we don't define the empty fields all fields are created in the default way additionally to our custom way
fields = ()