end_date added

This commit is contained in:
Arvind Tiwari 2017-09-30 17:55:49 +05:30
parent 9c69c4cb25
commit bd91883369
3 changed files with 15 additions and 2 deletions

View file

@ -1,5 +1,7 @@
from datetime import datetime
import os import os
import logging import logging
from dateutil.relativedelta import relativedelta
from django.db import models from django.db import models
from django.utils.functional import cached_property from django.utils.functional import cached_property
@ -172,3 +174,9 @@ class VMDetail(models.Model):
ipv6 = models.TextField(default='') ipv6 = models.TextField(default='')
created_at = models.DateTimeField(auto_now_add=True) created_at = models.DateTimeField(auto_now_add=True)
terminated_at = models.DateTimeField(null=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

View file

@ -101,7 +101,7 @@
{% if vm.created_at %} {% if vm.created_at %}
<p> <p>
<span>{% trans "Period" %}: </span> <span>{% trans "Period" %}: </span>
<span>{{ vm.created_at|date:'Y/m/d' }} - {% if vm.terminated_at %}{{ vm.terminated_at|date:'Y/m/d' }}{% else %}{% now 'Y/m/d' %}{% endif %}</span> <span>{{ vm.created_at|date:'Y/m/d' }} - {{ subscription_end_date|date:'Y/m/d' }}</span>
</p> </p>
{% endif %} {% endif %}
<p> <p>

View file

@ -687,7 +687,12 @@ class OrdersHostingDetailView(LoginRequiredMixin,
try: try:
vm_detail = VMDetail.objects.get(vm_id=obj.vm_id) vm_detail = VMDetail.objects.get(vm_id=obj.vm_id)
context['vm'] = vm_detail.__dict__ 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: except VMDetail.DoesNotExist:
try: try:
manager = OpenNebulaManager( manager = OpenNebulaManager(