# Path: apps/core/utils/date_helpers.py
# def toLocalZone(dt):
#     ''' accept string or datetime and return datetime in local zone '''
#     dt = date_parse(dt)
#     if dt and dt.tzinfo:
#         return dt.astimezone(dateutil.tz.tzlocal())
#     else:
#         None


import logging
import shlex
import sys
import time
import traceback
from cStringIO import StringIO
from datetime import timedelta
from croniter import croniter
from django.conf import settings
from django.core import management
from django.db import models
from django.db.models import Max
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from apps.core.utils.date_helpers import toLocalZone

    def recount(self):
        self.counter = TaskPeriodSchedule.object.filter(
            period=self.period).count()
        self.save()

    def delete(self, *args, **kwargs):
        super(TaskPeriodSchedule, self).delete(*args, **kwargs)
        self.period.recount_all()


class TaskPeriod(models.Model):
    title = models.CharField(max_length=64)
    label = models.SlugField(max_length=64, unique=True,
                             help_text="Label must be same for command 'schedule --schedule-label [label]'")
    common = models.CharField(_("Command"), max_length=128,
                              help_text="All allowed <a href=\"https://github.com/SatelliteQE/GreenTea/wiki/Commands\">commands</a>. Example: \'beaker schedule --schedule-label daily\'")
    date_last = models.DateTimeField(
        _('Date of last run'),
        null=True,
        blank=True)
    is_enable = models.BooleanField(default=False)
    cron = models.CharField(max_length=64, default="*  *  *  *  *")
    position = models.SmallIntegerField(default=0)

    class Meta:
        ordering = ["position", "title"]

    def get_previous_run(self):
        tasks = Task.objects.filter(period=self).order_by("-date_run")

# Path: apps/core/utils/date_helpers.py
# def toLocalZone(dt):
#     ''' accept string or datetime and return datetime in local zone '''
#     dt = date_parse(dt)
#     if dt and dt.tzinfo:
#         return dt.astimezone(dateutil.tz.tzlocal())
#     else:
#         None


# Path: apps/taskomatic/models.py
import logging
import shlex
import sys
import time
import traceback
from cStringIO import StringIO
from datetime import timedelta
from croniter import croniter
from django.conf import settings
from django.core import management
from django.db import models
from django.db.models import Max
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from apps.core.utils.date_helpers import toLocalZone


    def recount(self):
        self.counter = TaskPeriodSchedule.object.filter(
            period=self.period).count()
        self.save()

    def delete(self, *args, **kwargs):
        super(TaskPeriodSchedule, self).delete(*args, **kwargs)
        self.period.recount_all()


class TaskPeriod(models.Model):
    title = models.CharField(max_length=64)
    label = models.SlugField(max_length=64, unique=True,
                             help_text="Label must be same for command 'schedule --schedule-label [label]'")
    common = models.CharField(_("Command"), max_length=128,
                              help_text="All allowed <a href=\"https://github.com/SatelliteQE/GreenTea/wiki/Commands\">commands</a>. Example: \'beaker schedule --schedule-label daily\'")
    date_last = models.DateTimeField(
        _('Date of last run'),
        null=True,
        blank=True)
    is_enable = models.BooleanField(default=False)
    cron = models.CharField(max_length=64, default="*  *  *  *  *")
    position = models.SmallIntegerField(default=0)

    class Meta:
        ordering = ["position", "title"]

    def get_previous_run(self):
        tasks = Task.objects.filter(period=self).order_by("-date_run")

        if len(tasks) > 0: