From 706dc41267346c06542c2808e2f09be7b5b70f73 Mon Sep 17 00:00:00 2001 From: Dmitry Novikov Date: Sat, 30 Dec 2017 11:28:11 +0300 Subject: [PATCH] fix timedelta display in task view --- mydefs.py | 16 ++++++++-------- taskapp/locale/ru/LC_MESSAGES/django.po | 3 +++ taskapp/templates/taskapp/view.html | 2 +- taskapp/views.py | 12 ++++++++---- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/mydefs.py b/mydefs.py index 1e57b99..62b1fc0 100644 --- a/mydefs.py +++ b/mydefs.py @@ -173,20 +173,20 @@ class RuTimedelta(timedelta): ) def __str__(self): - hours, remainder = divmod(self.seconds, 3600) - minutes, seconds = divmod(remainder, 60) - text_date = "%d:%d:%d" % ( - hours, - minutes, - seconds - ) + #hours, remainder = divmod(self.seconds, 3600) + #minutes, seconds = divmod(remainder, 60) + #text_date = "%d:%d" % ( + # hours, + # minutes + #) if self.days > 1: ru_days = 'дней' if 5 > self.days > 1: ru_days = 'дня' elif self.days == 1: ru_days = 'день' - text_date = '%d %s %s' % (self.days, ru_days, text_date) + #text_date = '%d %s %s' % (self.days, ru_days, text_date) + text_date = '%d %s' % (self.days, ru_days) return text_date diff --git a/taskapp/locale/ru/LC_MESSAGES/django.po b/taskapp/locale/ru/LC_MESSAGES/django.po index 368161e..54014a5 100644 --- a/taskapp/locale/ru/LC_MESSAGES/django.po +++ b/taskapp/locale/ru/LC_MESSAGES/django.po @@ -384,3 +384,6 @@ msgstr "Ip конфликт" msgid "Internet crash" msgstr "Нет интернета" + +msgid "Expired timeout -%(time_left)s" +msgstr "Время ожидания истекло -%(time_left)s" diff --git a/taskapp/templates/taskapp/view.html b/taskapp/templates/taskapp/view.html index 0c0a927..dfefefb 100644 --- a/taskapp/templates/taskapp/view.html +++ b/taskapp/templates/taskapp/view.html @@ -29,7 +29,7 @@ {% trans 'A priority' %}: {{ task.get_priority_display }}
{% trans 'The task is valid until' %} {{ task.out_date|date:'d E Y' }}
{% trans 'Date of create' %} {{ task.time_of_create|date:'d E Y H:i:s' }}
- {% trans 'time left' %} {{ time_diff }}
+ {{ time_diff }}
{% trans 'Task type' %}: {{ task.get_mode_display }}
{% trans 'Condition' %}: {{ task.get_state_display }}
{% trans 'Subscriber' %} diff --git a/taskapp/views.py b/taskapp/views.py index 6f908dc..139f4f8 100644 --- a/taskapp/views.py +++ b/taskapp/views.py @@ -7,7 +7,7 @@ from django.shortcuts import render, redirect, get_object_or_404 from django.contrib import messages from abonapp.models import Abon from django.utils.translation import ugettext as _ -from datetime import date +from datetime import date, datetime from guardian.decorators import permission_required_or_403 as permission_required from chatbot.models import MessageQueue @@ -93,11 +93,15 @@ def task_delete(request, task_id): @only_admins def view(request, task_id): tsk = get_object_or_404(Task, id=task_id) - toc = date(tsk.time_of_create.year, tsk.time_of_create.month, tsk.time_of_create.day) - time_diff = tsk.out_date - toc + #toc = date(tsk.time_of_create.year, tsk.time_of_create.month, tsk.time_of_create.day) + now_date = datetime.now().date() + if tsk.out_date > now_date: + time_diff = "%s: %s" % (_('time left'), RuTimedelta(tsk.out_date - now_date)) + else: + time_diff = _("Expired timeout -%(time_left)s") % {'time_left': RuTimedelta(now_date - tsk.out_date)} return render(request, 'taskapp/view.html', { 'task': tsk, - 'time_diff': RuTimedelta(time_diff) + 'time_diff': time_diff })