From bd918833695604a261fe56470005a849773ebb23 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Sat, 30 Sep 2017 17:55:49 +0530 Subject: [PATCH] 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(