From bd918833695604a261fe56470005a849773ebb23 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Sat, 30 Sep 2017 17:55:49 +0530 Subject: [PATCH 1/8] end_date added --- hosting/models.py | 8 ++++++++ hosting/templates/hosting/order_detail.html | 2 +- hosting/views.py | 7 ++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/hosting/models.py b/hosting/models.py index 73c082bb..d901e962 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -1,5 +1,7 @@ +from datetime import datetime import os import logging +from dateutil.relativedelta import relativedelta from django.db import models from django.utils.functional import cached_property @@ -172,3 +174,9 @@ class VMDetail(models.Model): ipv6 = models.TextField(default='') created_at = models.DateTimeField(auto_now_add=True) terminated_at = models.DateTimeField(null=True) + + def end_date(self): + end_date = self.terminated_at if self.terminated_at else datetime.now() + months = relativedelta(end_date, self.created_at) + end_date = self.created_at + relativedelta(months=months) + return end_date diff --git a/hosting/templates/hosting/order_detail.html b/hosting/templates/hosting/order_detail.html index dc8de901..17502deb 100644 --- a/hosting/templates/hosting/order_detail.html +++ b/hosting/templates/hosting/order_detail.html @@ -101,7 +101,7 @@ {% if vm.created_at %}

{% trans "Period" %}: - {{ vm.created_at|date:'Y/m/d' }} - {% if vm.terminated_at %}{{ vm.terminated_at|date:'Y/m/d' }}{% else %}{% now 'Y/m/d' %}{% endif %} + {{ vm.created_at|date:'Y/m/d' }} - {{ subscription_end_date|date:'Y/m/d' }}

{% endif %}

diff --git a/hosting/views.py b/hosting/views.py index facc8c01..4d66f2b8 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -687,7 +687,12 @@ class OrdersHostingDetailView(LoginRequiredMixin, try: vm_detail = VMDetail.objects.get(vm_id=obj.vm_id) context['vm'] = vm_detail.__dict__ - context['vm']['name'] = '{}-{}'.format(context['vm']['configuration'], context['vm']['vm_id']) + context['vm']['name'] = ( + '{}-{}'.format( + context['vm']['configuration'], context['vm']['vm_id'] + ) + ) + context['subscription_end_date'] = vm_detail.end_date() except VMDetail.DoesNotExist: try: manager = OpenNebulaManager( From f1790445cd5b9ea7f179c06730fa868e382eb7a0 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Sat, 30 Sep 2017 18:05:02 +0530 Subject: [PATCH 2/8] timezone aware --- hosting/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hosting/models.py b/hosting/models.py index d901e962..db68f522 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -1,9 +1,9 @@ -from datetime import datetime import os import logging from dateutil.relativedelta import relativedelta from django.db import models +from django.utils import timezone from django.utils.functional import cached_property from Crypto.PublicKey import RSA from membership.models import StripeCustomer, CustomUser @@ -176,7 +176,7 @@ class VMDetail(models.Model): terminated_at = models.DateTimeField(null=True) def end_date(self): - end_date = self.terminated_at if self.terminated_at else datetime.now() + end_date = self.terminated_at if self.terminated_at else timezone.now() months = relativedelta(end_date, self.created_at) end_date = self.created_at + relativedelta(months=months) return end_date From 3701899304149cbc6bd5a4b05c5d38269e8508ca Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Sat, 30 Sep 2017 18:06:50 +0530 Subject: [PATCH 3/8] timezone aware --- hosting/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hosting/models.py b/hosting/models.py index db68f522..5b9645af 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -177,6 +177,6 @@ class VMDetail(models.Model): def end_date(self): end_date = self.terminated_at if self.terminated_at else timezone.now() - months = relativedelta(end_date, self.created_at) + months = relativedelta(end_date, self.created_at).months end_date = self.created_at + relativedelta(months=months) return end_date From 1f09bab3e4c226a6df39efebc6f4f37c6e6cf3bb Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Sat, 30 Sep 2017 18:08:02 +0530 Subject: [PATCH 4/8] minimum month diff set to 1 --- hosting/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hosting/models.py b/hosting/models.py index 5b9645af..e1714094 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -177,6 +177,6 @@ class VMDetail(models.Model): def end_date(self): end_date = self.terminated_at if self.terminated_at else timezone.now() - months = relativedelta(end_date, self.created_at).months + months = relativedelta(end_date, self.created_at).months or 1 end_date = self.created_at + relativedelta(months=months) return end_date From df93dfe047f03af1588b4f92d0b37694856fd0c3 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Sat, 30 Sep 2017 18:10:34 +0530 Subject: [PATCH 5/8] day set to one before --- hosting/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hosting/models.py b/hosting/models.py index e1714094..40a9da03 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -178,5 +178,5 @@ class VMDetail(models.Model): def end_date(self): end_date = self.terminated_at if self.terminated_at else timezone.now() months = relativedelta(end_date, self.created_at).months or 1 - end_date = self.created_at + relativedelta(months=months) + end_date = self.created_at + relativedelta(months=months, days=-1) return end_date From 8e5654bdb586863c81f58492e5622fb209b90949 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Fri, 6 Oct 2017 04:11:40 +0530 Subject: [PATCH 6/8] date time converted to locale --- hosting/static/hosting/css/commons.css | 8 +++++++ hosting/templates/hosting/order_detail.html | 24 +++++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/hosting/static/hosting/css/commons.css b/hosting/static/hosting/css/commons.css index 317caabc..cdf078a0 100644 --- a/hosting/static/hosting/css/commons.css +++ b/hosting/static/hosting/css/commons.css @@ -375,4 +375,12 @@ outline: none; color: #999; fill: #999; +} + +.locale_date { + opacity: 0; +} + +.locale_date.done{ + opacity: 1; } \ No newline at end of file diff --git a/hosting/templates/hosting/order_detail.html b/hosting/templates/hosting/order_detail.html index 60e50513..79dd1e82 100644 --- a/hosting/templates/hosting/order_detail.html +++ b/hosting/templates/hosting/order_detail.html @@ -32,11 +32,11 @@ {% endif %}

{% trans "Date" %}: - + {% if order %} - {{order.created_at|date:'Y-m-d H:i'}} + {{order.created_at|date:'Y-m-d h:i a'}} {% else %} - {% now "Y-m-d H:i" %} + {% now "Y-m-d h:i a" %} {% endif %}

@@ -107,7 +107,9 @@ {% if vm.created_at %}

{% trans "Period" %}: - {{ vm.created_at|date:'Y/m/d' }} - {{ subscription_end_date|date:'Y/m/d' }} + + {{ vm.created_at }} - {{ subscription_end_date }} +

{% endif %}

@@ -194,12 +196,16 @@ {%endblock%} From d3d57ade372f0517bb9569873a71992e013199b9 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Fri, 6 Oct 2017 04:16:58 +0530 Subject: [PATCH 7/8] formats fixed --- hosting/templates/hosting/order_detail.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hosting/templates/hosting/order_detail.html b/hosting/templates/hosting/order_detail.html index 79dd1e82..d11e915a 100644 --- a/hosting/templates/hosting/order_detail.html +++ b/hosting/templates/hosting/order_detail.html @@ -108,7 +108,7 @@

{% trans "Period" %}: - {{ vm.created_at }} - {{ subscription_end_date }} + {{ vm.created_at|date:'Y-m-d H:i' }} - {{ subscription_end_date|date:'Y-m-d H:i' }}

{% endif %} @@ -198,7 +198,7 @@ var create_vm_error_message = '{{err_msg|safe}}'; window.onload = function () { var locale_dates = document.getElementsByClassName("locale_date"); - var formats = ['YYYY-MM-DD hh:mm a', 'YYYY/MM/DD'] + var formats = ['YYYY-MM-DD hh:mm a', 'YYYY-MM-DD HH:mm'] var i; for (i = 0; i < locale_dates.length; i++) { var oldDate = moment.utc(locale_dates[i].textContent, formats); From 88781e992c9e3faad02f8392ac268a09a9630764 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Fri, 6 Oct 2017 04:20:38 +0530 Subject: [PATCH 8/8] 24 hr fix --- hosting/templates/hosting/order_detail.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hosting/templates/hosting/order_detail.html b/hosting/templates/hosting/order_detail.html index d11e915a..fe200f6e 100644 --- a/hosting/templates/hosting/order_detail.html +++ b/hosting/templates/hosting/order_detail.html @@ -108,7 +108,7 @@

{% trans "Period" %}: - {{ vm.created_at|date:'Y-m-d H:i' }} - {{ subscription_end_date|date:'Y-m-d H:i' }} + {{ vm.created_at|date:'Y-m-d h:i a' }} - {{ subscription_end_date|date:'Y-m-d h:i a' }}

{% endif %} @@ -198,7 +198,7 @@ var create_vm_error_message = '{{err_msg|safe}}'; window.onload = function () { var locale_dates = document.getElementsByClassName("locale_date"); - var formats = ['YYYY-MM-DD hh:mm a', 'YYYY-MM-DD HH:mm'] + var formats = ['YYYY-MM-DD hh:mm a'] var i; for (i = 0; i < locale_dates.length; i++) { var oldDate = moment.utc(locale_dates[i].textContent, formats);