# 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
        self.save()

    def social(self, on=True):
        self.show_social = on
        self.save()

    def publish(self, dt=None):
        if dt is None:
            dt = now()
        self.start_date = dt
        self.save()

    def close(self, dt=None):
        if dt is None:
            dt = now()
        self.end_date = dt
        self.save()

    def set_date(self, field, dtStr, tmStr):
        if dtStr == "":
            setattr(self, field, None)
            self.save()
            return
        try:
            dt = datetime.strptime(dtStr + " " + tmStr, '%m/%d/%Y %I:%M%p').replace(tzinfo=get_current_timezone())
            if field == 'start_date' and self.start_date:
                if self.start_date != dt and self.start_date < now() and self.has_results:
                    raise self.AlreadyPublishedError

        except ValueError:

# 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

        self.save()

    def social(self, on=True):
        self.show_social = on
        self.save()

    def publish(self, dt=None):
        if dt is None:
            dt = now()
        self.start_date = dt
        self.save()

    def close(self, dt=None):
        if dt is None:
            dt = now()
        self.end_date = dt
        self.save()

    def set_date(self, field, dtStr, tmStr):
        if dtStr == "":
            setattr(self, field, None)
            self.save()
            return
        try:
            dt = datetime.strptime(dtStr + " " + tmStr, '%m/%d/%Y %I:%M%p').replace(tzinfo=get_current_timezone())
            if field == 'start_date' and self.start_date:
                if self.start_date != dt and self.start_date < now() and self.has_results:
                    raise self.AlreadyPublishedError

        except ValueError:

            dt = datetime.strptime(dtStr, '%m/%d/%Y').replace(tzinfo=get_current_timezone())