# Path: survey/helpers.py
# def total_seconds(td):


from django.db import models
from datetime import datetime
from django.contrib.auth.models import User
from collections import defaultdict
from survey.helpers import now, get_current_timezone


class Survey(models.Model):
    """
    Survey model has a set of questions.
    """
    title = models.CharField(max_length=1024)
    slug = models.SlugField(max_length=1024, unique=True)
    start_date = models.DateTimeField(null=True, blank=True)
    end_date = models.DateTimeField(null=True, blank=True)
    description = models.CharField(max_length=1024, null=False, blank=True)
    use_cookies = models.BooleanField(default=True)
    creator = models.ForeignKey(User, related_name="+")
    show_social = models.BooleanField(default=True)

    @models.permalink
    def get_absolute_url(self):
        return ('survey', (), {'slug': self.slug})

    class AlreadyPublishedError(Exception):
        pass

    @property
    def is_active(self):
        end_date = self.end_date
        if self.start_date:

# Path: survey/helpers.py
# def total_seconds(td):


# Path: survey/models.py
from django.db import models
from datetime import datetime
from django.contrib.auth.models import User
from collections import defaultdict
from survey.helpers import now, get_current_timezone



class Survey(models.Model):
    """
    Survey model has a set of questions.
    """
    title = models.CharField(max_length=1024)
    slug = models.SlugField(max_length=1024, unique=True)
    start_date = models.DateTimeField(null=True, blank=True)
    end_date = models.DateTimeField(null=True, blank=True)
    description = models.CharField(max_length=1024, null=False, blank=True)
    use_cookies = models.BooleanField(default=True)
    creator = models.ForeignKey(User, related_name="+")
    show_social = models.BooleanField(default=True)

    @models.permalink
    def get_absolute_url(self):
        return ('survey', (), {'slug': self.slug})

    class AlreadyPublishedError(Exception):
        pass

    @property
    def is_active(self):
        end_date = self.end_date
        if self.start_date:

            return self.start_date <= now() and (not end_date or now() <= end_date)