from __future__ import unicode_literals, absolute_import
from django.db import models
from django.contrib.auth.models import User

from django.conf import settings

from apps.certificate.models import Certificate


# Create your models here.
class Domain(models.Model):

    domain_name = models.CharField(max_length=200)
    domain_url = models.CharField(max_length=200)
    domain_registerer = models.CharField(max_length=200)
    support_email = models.EmailField(max_length=200)
    tld = models.CharField(max_length=200)
    slug = models.SlugField(max_length=100)
    date_registered = models.DateField()
    expiration_date = models.DateField()
    last_updated = models.DateField(auto_now=True)
    date_entered = models.DateField(auto_now_add=True)
    verification_type = models.CharField(choices=settings.DOMAIN_VERIFICATION_OPTIONS, max_length=16)
    is_active = models.BooleanField(default=True)
    domain_certificate = models.ForeignKey(
        Certificate, related_name='certified_domain')
    admin = models.ForeignKey(User, related_name='domains')

    def get_webmaster(self):
        return self.admin

    @property
    def is_expired(self):
        return True if self.expiration_date > self.date_registered else False

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = (self.domain_name + self.tld).replace('.', '-')
        return super(Domain, self).save(*args, **kwargs)

from __future__ import unicode_literals, absolute_import
from django.db import models
from django.contrib.auth.models import User

from django.conf import settings

from apps.certificate.models import Certificate


# Create your models here.
class Domain(models.Model):

    domain_name = models.CharField(max_length=200)
    domain_url = models.CharField(max_length=200)
    domain_registerer = models.CharField(max_length=200)
    support_email = models.EmailField(max_length=200)
    tld = models.CharField(max_length=200)
    slug = models.SlugField(max_length=100)
    date_registered = models.DateField()
    expiration_date = models.DateField()
    last_updated = models.DateField(auto_now=True)
    date_entered = models.DateField(auto_now_add=True)
    verification_type = models.CharField(choices=settings.DOMAIN_VERIFICATION_OPTIONS, max_length=16)
    is_active = models.BooleanField(default=True)
    domain_certificate = models.ForeignKey(
        Certificate, related_name='certified_domain')
    admin = models.ForeignKey(User, related_name='domains')

    def get_webmaster(self):
        return self.admin

    @property
    def is_expired(self):
        return True if self.expiration_date > self.date_registered else False

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = (self.domain_name + self.tld).replace('.', '-')
        return super(Domain, self).save(*args, **kwargs)

# {
#     domain_name: data.domain_name || $localStorage.domain.host,
#     domain_url: $localStorage.domain.host,,
#     domain_registerer: data.register,
#     support_email: (lambda emails: data.emails[0] if isinstance(emails, list) else emails)(data.emails),

# }
update domain model