2015-05-27 10:21:30 +00:00
|
|
|
from django.contrib import admin
|
2016-05-27 05:51:10 +00:00
|
|
|
|
|
|
|
from utils.mailer import BaseEmail
|
2016-05-25 06:23:32 +00:00
|
|
|
from .models import VirtualMachineType, VirtualMachinePlan
|
2015-05-27 10:21:30 +00:00
|
|
|
|
2016-04-18 01:05:39 +00:00
|
|
|
|
2016-05-27 05:51:10 +00:00
|
|
|
class VirtualMachinePlanAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('name', 'id', 'email')
|
|
|
|
|
|
|
|
def email(self, obj):
|
|
|
|
return obj.hosting_orders.latest('id').customer.user.email
|
|
|
|
|
|
|
|
def save_model(self, request, obj, form, change):
|
|
|
|
email = self.email(obj)
|
|
|
|
if 'status' in form.changed_data and obj.status == VirtualMachinePlan.ONLINE_STATUS:
|
|
|
|
context = {
|
|
|
|
'vm': obj
|
|
|
|
}
|
|
|
|
email_data = {
|
|
|
|
'subject': 'Your VM has been activated',
|
|
|
|
'to': email,
|
|
|
|
'context': context,
|
|
|
|
'template_name': 'vm_activated',
|
|
|
|
'template_path': 'emails/'
|
|
|
|
}
|
|
|
|
email = BaseEmail(**email_data)
|
|
|
|
email.send()
|
|
|
|
obj.save()
|
|
|
|
|
|
|
|
|
2016-04-18 01:05:39 +00:00
|
|
|
admin.site.register(VirtualMachineType)
|
2016-05-27 05:51:10 +00:00
|
|
|
admin.site.register(VirtualMachinePlan, VirtualMachinePlanAdmin)
|