# Path: web/siteup_api/validators.py
# class ValidateAnyOf(object):
#     def __init__(self, validators, message=None):
#     def __call__(self, value):
# def validate_hostname(hostname):
# 
# Path: web/siteup_api/utils.py
# def timedelta_to_string(td):
#     total_seconds = int(td.total_seconds())
#     days, remainder = divmod(total_seconds, 24 * 60 * 60)
#     hours, remainder = divmod(remainder, 60 * 60)
#     minutes, seconds = divmod(remainder, 60)
# 
#     if days:
#         return (_("{} days, {} hours and {} minutes").format(days, hours, minutes))
#     elif hours:
#         return (_("{} hours and {} minutes").format(hours, minutes))
#     else:
#         return (_("{} minutes").format(minutes))


import logging
import managers
from itertools import chain
from datetime import datetime, timedelta
from django.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.core import validators
from siteup_checker import monitoring
from siteup_checker.tasks_notification import enqueue_notification
from .validators import ValidateAnyOf, validate_ip_or_hostname, validate_hostname
from .utils import timedelta_to_string
from django.db.models.signals import pre_delete
from django.dispatch import receiver
        # If check's just been created, force check
        if self.last_log_datetime is None:
            return True

        # Subtract some seconds from the difference to handle timing deviations
        elapsed_seconds = (datetime.now() - self.last_log_datetime).seconds
        if elapsed_seconds < self.check_interval * 60 - 6:
            logger.info(u"Check %s should not run (elapsed time: %i seconds)" % (self.title, elapsed_seconds))
            return False

        logger.info(u"Check %s will run (elapsed time: %i seconds)" % (self.title, elapsed_seconds))
        return True

    def generic_url(self, action):
        kwargs = {'pk': self.id, 'type': self.type_name()}
        return reverse(action, kwargs=kwargs)

    def detail_url(self):
        return self.generic_url('view_check')

    def edit_url(self):
        return self.generic_url('edit_check')

    def delete_url(self):
        return self.generic_url('delete_check')

    def enable_url(self):
        return self.generic_url('enable_check')

    def disable_url(self):

# Path: web/siteup_api/validators.py
# class ValidateAnyOf(object):
#     def __init__(self, validators, message=None):
#     def __call__(self, value):
# def validate_hostname(hostname):
# 
# Path: web/siteup_api/utils.py
# def timedelta_to_string(td):
#     total_seconds = int(td.total_seconds())
#     days, remainder = divmod(total_seconds, 24 * 60 * 60)
#     hours, remainder = divmod(remainder, 60 * 60)
#     minutes, seconds = divmod(remainder, 60)
# 
#     if days:
#         return (_("{} days, {} hours and {} minutes").format(days, hours, minutes))
#     elif hours:
#         return (_("{} hours and {} minutes").format(hours, minutes))
#     else:
#         return (_("{} minutes").format(minutes))


# Path: web/siteup_api/models.py
import logging
import managers
from itertools import chain
from datetime import datetime, timedelta
from django.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.core import validators
from siteup_checker import monitoring
from siteup_checker.tasks_notification import enqueue_notification
from .validators import ValidateAnyOf, validate_ip_or_hostname, validate_hostname
from .utils import timedelta_to_string
from django.db.models.signals import pre_delete
from django.dispatch import receiver

        # If check's just been created, force check
        if self.last_log_datetime is None:
            return True

        # Subtract some seconds from the difference to handle timing deviations
        elapsed_seconds = (datetime.now() - self.last_log_datetime).seconds
        if elapsed_seconds < self.check_interval * 60 - 6:
            logger.info(u"Check %s should not run (elapsed time: %i seconds)" % (self.title, elapsed_seconds))
            return False

        logger.info(u"Check %s will run (elapsed time: %i seconds)" % (self.title, elapsed_seconds))
        return True

    def generic_url(self, action):
        kwargs = {'pk': self.id, 'type': self.type_name()}
        return reverse(action, kwargs=kwargs)

    def detail_url(self):
        return self.generic_url('view_check')

    def edit_url(self):
        return self.generic_url('edit_check')

    def delete_url(self):
        return self.generic_url('delete_check')

    def enable_url(self):
        return self.generic_url('enable_check')

    def disable_url(self):

        return self.generic_url('disable_check')