78 lines
2.5 KiB
Python
78 lines
2.5 KiB
Python
TICKET_STATE_LABELS = {
|
|
1: "INIT",
|
|
10: "CLOSED",
|
|
}
|
|
|
|
USERS_COLUMNS = [
|
|
{"key": "user_uuid", "label": "accounts_user_uuid"},
|
|
{"key": "username", "label": "accounts_username"},
|
|
{"key": "first_name", "label": "accounts_first_name"},
|
|
{"key": "last_name", "label": "accounts_last_name"},
|
|
{"key": "email", "label": "accounts_email"},
|
|
{"key": "phone_number", "label": "accounts_phone_number"},
|
|
{"key": "address", "label": "accounts_address"},
|
|
]
|
|
|
|
TICKETS_COLUMNS = [
|
|
{"key": "ticket_uuid", "label": "advertising_ticket_uuid"},
|
|
{"key": "user_uuid", "label": "advertising_user_uuid"},
|
|
{"key": "title", "label": "advertising_title"},
|
|
{"key": "description", "label": "advertising_description"},
|
|
{"key": "state", "label": "advertising_state"},
|
|
{"key": "created_at", "label": "advertising_created_at"},
|
|
{"key": "updated_at", "label": "advertising_updated_at"},
|
|
]
|
|
|
|
|
|
def _format_value(value):
|
|
if value is None:
|
|
return ""
|
|
if type(value).__name__ == "Unset":
|
|
return ""
|
|
if hasattr(value, "value") and not isinstance(value, (str, bytes)):
|
|
value = value.value
|
|
if value is None:
|
|
return ""
|
|
return value
|
|
|
|
|
|
def _format_ticket_state(state):
|
|
if not state:
|
|
return ""
|
|
return TICKET_STATE_LABELS.get(state.value, str(state.value))
|
|
|
|
|
|
def build_user_rows(users):
|
|
rows = []
|
|
for user in users:
|
|
if user is None:
|
|
continue
|
|
rows.append(
|
|
{
|
|
"user_uuid": str(user.uuid),
|
|
"username": _format_value(user.username),
|
|
"first_name": _format_value(user.first_name),
|
|
"last_name": _format_value(user.last_name),
|
|
"email": _format_value(user.email),
|
|
"phone_number": _format_value(user.phone_number),
|
|
"address": _format_value(user.address),
|
|
}
|
|
)
|
|
return rows
|
|
|
|
|
|
def build_ticket_rows(tickets):
|
|
rows = []
|
|
for ticket in tickets:
|
|
rows.append(
|
|
{
|
|
"ticket_uuid": str(ticket.uuid),
|
|
"user_uuid": str(ticket.user),
|
|
"title": _format_value(ticket.title),
|
|
"description": _format_value(ticket.description),
|
|
"state": _format_ticket_state(ticket.state),
|
|
"created_at": str(ticket.created_at) if ticket.created_at else "",
|
|
"updated_at": str(ticket.updated_at) if ticket.updated_at else "",
|
|
}
|
|
)
|
|
return rows
|