cleaning time_spent formating

This commit is contained in:
Jachym Cepicky 2019-06-16 10:25:29 +02:00
parent 0de263280f
commit 37c6905d46
7 changed files with 49 additions and 8 deletions

View File

@ -291,3 +291,18 @@ def query_tickets_by_args(objects, order_by, **kwargs):
'total': total,
'draw': draw
}
def format_time_spent(time_spent):
"""Format time_spent attribute to "[H]HHh:MMm" text string to be allign in
all graphical outputs
"""
if time_spent:
time_spent = "{0:02d}h:{0:02d}m".format(
int(time_spent.total_seconds() // 3600),
int((time_spent.total_seconds() % 3600) / 60)
)
else:
time_spent = ""
return time_spent

View File

@ -31,6 +31,17 @@ import uuid
from .templated_email import send_templated_mail
def format_time_spent(time_spent):
if time_spent:
time_spent = "{0:02d}h:{0:02d}m".format(
int(time_spent.total_seconds() // (3600)),
int((time_spent.total_seconds() % 3600) / 60)
)
else:
time_spent = ""
return time_spent
class EscapeHtml(Extension):
def extendMarkdown(self, md, md_globals):
del md.preprocessors['html_block']
@ -346,6 +357,10 @@ class Queue(models.Model):
total = total + val.time_spent
return total
@property
def time_spent_formated(self):
return format_time_spent(self.time_spent)
def prepare_permission_name(self):
"""Prepare internally the codename for the permission and store it in permission_name.
:return: The codename that can be used to create a new Permission object.
@ -553,6 +568,10 @@ class Ticket(models.Model):
total = total + val.time_spent
return total
@property
def time_spent_formated(self):
return format_time_spent(self.time_spent)
def send(self, roles, dont_send_to=None, **kwargs):
"""
Send notifications to everyone interested in this ticket.
@ -861,6 +880,10 @@ class FollowUp(models.Model):
def get_markdown(self):
return get_markdown(self.comment)
@property
def time_spent_formated(self):
return format_time_spent(self.time_spent)
class TicketChange(models.Model):
"""

View File

@ -1,6 +1,7 @@
from rest_framework import serializers
from .models import Ticket
from .lib import format_time_spent
from django.contrib.humanize.templatetags import humanize
@ -53,7 +54,7 @@ class TicketSerializer(serializers.ModelSerializer):
return ("None")
def get_time_spent(self, obj):
return str(obj.time_spent)
return format_time_spent(obj.time_spent)
def get_row_class(self, obj):
return (obj.get_priority_css_class)

View File

@ -49,7 +49,7 @@
<p>{{ followup.get_markdown|urlizetrunc:50|num_to_link|linebreaksbr }}</p>
{% endif %}
{% if followup.time_spent %}
<small>{% trans "Time spent" %}: {{ followup.time_spent }}</small></p>
<small>{% trans "Time spent" %}: {{ followup.time_spent_formated }}</small></p>
{% endif %}
{% for change in followup.ticketchange_set.all %}
{% if forloop.first %}<div class='changes'><ul>{% endif %}

View File

@ -91,7 +91,7 @@
</tr>
<tr>
<th>{% trans "Total time spent" %}</th>
<td>{{ ticket.time_spent }}</td>
<td>{{ ticket.time_spent_formated }}</td>
</tr>
<tr>
<th>{% trans "Attachments" %}</th>

View File

@ -12,7 +12,7 @@
<td data-order='{{ ticket.created|date:"U" }}'><span title='{{ ticket.created|date:"r" }}'>{{ ticket.created|naturaltime }}</span></td>
<td data-order='{{ ticket.due_date|date:"U" }}'><span title='{{ ticket.due_date|date:"r" }}'>{{ ticket.due_date|naturaltime }}</span></td>
<td>{{ ticket.get_assigned_to }}</td>
<td>{{ ticket.time_spent }}</td>
<td>{{ ticket.time_spent_formated }}</td>
</tr>
{% endfor %}
</tbody>

View File

@ -39,7 +39,7 @@ from helpdesk.forms import (
from helpdesk.decorators import staff_member_required, superuser_required
from helpdesk.lib import (
query_to_dict, apply_query, safe_template_context,
process_attachments, queue_template_context,
process_attachments, queue_template_context, format_time_spent
)
from helpdesk.models import (
Ticket, Queue, FollowUp, TicketChange, PreSetReply, FollowUpAttachment, SavedSearch,
@ -47,6 +47,7 @@ from helpdesk.models import (
)
from helpdesk import settings as helpdesk_settings
from helpdesk.views.permissions import MustBeStaffMixin
from ..lib import format_time_spent
from rest_framework import viewsets, status
from rest_framework.response import Response
@ -236,7 +237,7 @@ def followup_edit(request, ticket_id, followup_id):
'comment': escape(followup.comment),
'public': followup.public,
'new_status': followup.new_status,
'time_spent': followup.time_spent,
'time_spent': format_time_spent(followup.time_spent),
})
ticketcc_string, show_subscribe = \
@ -908,6 +909,7 @@ def ticket_list(request):
# show open/reopened/resolved (not closed) cases sorted by creation
# date.
all_queues = Queue.objects.all()
query_params = {
'filtering': {'status__in': [1, 2, 3]},
'sorting': 'created',
@ -1186,8 +1188,8 @@ def report_index(request):
'open': queue.ticket_set.filter(status__in=[1, 2]).count(),
'resolved': queue.ticket_set.filter(status=3).count(),
'closed': queue.ticket_set.filter(status=4).count(),
'time_spent': queue.time_spent,
'dedicated_time': queue.dedicated_time
'time_spent': format_time_spent(queue.time_spent),
'dedicated_time': format_time_spent(queue.dedicated_time)
}
dash_tickets.append(dash_ticket)