2018-10-15 02:23:28 +02:00
|
|
|
from rest_framework import serializers
|
|
|
|
|
|
|
|
from .models import Ticket
|
|
|
|
|
|
|
|
from django.contrib.humanize.templatetags import humanize
|
|
|
|
|
|
|
|
"""
|
|
|
|
A serializer for the Ticket model, returns data in the format as required by
|
|
|
|
datatables for ticket_list.html. Called from staff.datatables_ticket_list.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2018-10-15 19:56:54 +02:00
|
|
|
|
2018-10-15 02:23:28 +02:00
|
|
|
class TicketSerializer(serializers.ModelSerializer):
|
|
|
|
ticket = serializers.SerializerMethodField()
|
|
|
|
assigned_to = serializers.SerializerMethodField()
|
|
|
|
created = serializers.SerializerMethodField()
|
|
|
|
due_date = serializers.SerializerMethodField()
|
|
|
|
status = serializers.SerializerMethodField()
|
|
|
|
row_class = serializers.SerializerMethodField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Ticket
|
|
|
|
# fields = '__all__'
|
|
|
|
fields = ('ticket', 'id', 'priority', 'title', 'queue', 'status', 'created', 'due_date', 'assigned_to', 'row_class')
|
|
|
|
|
|
|
|
def get_ticket(self, obj):
|
2018-10-15 19:56:54 +02:00
|
|
|
return (str(obj.id) + " " + obj.ticket)
|
2018-10-15 02:23:28 +02:00
|
|
|
|
|
|
|
def get_status(self, obj):
|
|
|
|
return (obj.get_status)
|
|
|
|
|
|
|
|
def get_created(self, obj):
|
|
|
|
return (humanize.naturaltime(obj.created))
|
|
|
|
|
|
|
|
def get_due_date(self, obj):
|
|
|
|
return (humanize.naturaltime(obj.due_date))
|
|
|
|
|
|
|
|
def get_assigned_to(self, obj):
|
|
|
|
if obj.assigned_to:
|
|
|
|
if obj.assigned_to.first_name:
|
|
|
|
return (obj.assigned_to.first_name)
|
|
|
|
else:
|
|
|
|
return (obj.assigned_to.email)
|
|
|
|
else:
|
|
|
|
return ("None")
|
|
|
|
|
|
|
|
def get_row_class(self, obj):
|
|
|
|
return (obj.get_priority_css_class)
|