# Path: schedule/models/calendars.py
# class Calendar(with_metaclass(ModelBase, *get_model_bases())):
#     '''
#     This is for grouping events so that batch relations can be made to all
#     events.  An example would be a project calendar.
# 
#     name: the name of the calendar
#     events: all the events contained within the calendar.
#     >>> calendar = Calendar(name = 'Test Calendar')
#     >>> calendar.save()
#     >>> data = {
#     ...         'title': 'Recent Event',
#     ...         'start': datetime.datetime(2008, 1, 5, 0, 0),
#     ...         'end': datetime.datetime(2008, 1, 10, 0, 0)
#     ...        }
#     >>> event = Event(**data)
#     >>> event.save()
#     >>> calendar.events.add(event)
#     >>> data = {
#     ...         'title': 'Upcoming Event',
#     ...         'start': datetime.datetime(2008, 1, 1, 0, 0),
#     ...         'end': datetime.datetime(2008, 1, 4, 0, 0)
#     ...        }
#     >>> event = Event(**data)
#     >>> event.save()
#     >>> calendar.events.add(event)
#     >>> data = {
#     ...         'title': 'Current Event',
#     ...         'start': datetime.datetime(2008, 1, 3),
#     ...         'end': datetime.datetime(2008, 1, 6)
#     ...        }
#     >>> event = Event(**data)
#     >>> event.save()
#     >>> calendar.events.add(event)
#     '''
# 
#     name = models.CharField(_("name"), max_length=200)
#     slug = models.SlugField(_("slug"), max_length=200)
#     objects = CalendarManager()
# 
#     class Meta(object):
#         verbose_name = _('calendar')
#         verbose_name_plural = _('calendar')
#         app_label = 'schedule'
# 
#     def __str__(self):
#         return self.name
# 
#     @property
#     def events(self):
#         return self.event_set
# 
#     def create_relation(self, obj, distinction=None, inheritable=True):
#         """
#         Creates a CalendarRelation between self and obj.
# 
#         if Inheritable is set to true this relation will cascade to all events
#         related to this calendar.
#         """
#         CalendarRelation.objects.create_relation(self, obj, distinction, inheritable)
# 
#     def get_recent(self, amount=5, in_datetime=datetime.datetime.now, tzinfo=pytz.utc):
#         """
#         This shortcut function allows you to get events that have started
#         recently.
# 
#         amount is the amount of events you want in the queryset. The default is
#         5.
# 
#         in_datetime is the datetime you want to check against.  It defaults to
#         datetime.datetime.now
#         """
#         return self.events.order_by('-start').filter(start__lt=timezone.now())[:amount]
# 
#     def occurrences_after(self, date=None):
#         return EventListManager(self.events.all()).occurrences_after(date)
# 
#     def get_absolute_url(self):
#         return reverse('calendar_home', kwargs={'calendar_slug': self.slug})
# 
#     def add_event_url(self):
#         return reverse('calendar_create_event', args=[self.slug])
# 
# Path: schedule/utils.py
# class OccurrenceReplacer(object):
#     """
#     When getting a list of occurrences, the last thing that needs to be done
#     before passing it forward is to make sure all of the occurrences that
#     have been stored in the datebase replace, in the list you are returning,
#     the generated ones that are equivalent.  This class makes this easier.
#     """
# 
#     def __init__(self, persisted_occurrences):
#         lookup = [((occ.event, occ.original_start, occ.original_end), occ) for
#                   occ in persisted_occurrences]
#         self.lookup = dict(lookup)
# 
#     def get_occurrence(self, occ):
#         """
#         Return a persisted occurrences matching the occ and remove it from lookup since it
#         has already been matched
#         """
#         return self.lookup.pop(
#             (occ.event, occ.original_start, occ.original_end),
#             occ)
# 
#     def has_occurrence(self, occ):
#         try:
#             return (occ.event, occ.original_start, occ.original_end) in self.lookup
#         except TypeError:
#             if not self.lookup:
#                 return False
#             else:
#                 raise TypeError('A problem with checking if a persisted occurence exists has occured!')
# 
#     def get_additional_occurrences(self, start, end):
#         """
#         Return persisted occurrences which are now in the period
#         """
#         return [occ for _, occ in list(self.lookup.items()) if (occ.start < end and occ.end >= start and not occ.cancelled)]
# 
# Path: schedule/utils.py
# def get_model_bases():
#     from django.db.models import Model
#     baseStrings = getattr(settings, 'SCHEDULER_BASE_CLASSES', None)
#     if baseStrings is None:
#         return [Model]
#     else:
#         return [import_string(x) for x in baseStrings]


from django.utils.six import with_metaclass
from django.conf import settings as django_settings
from dateutil import rrule
from django.contrib.contenttypes import fields
from django.db import models
from django.db.models.base import ModelBase
from django.db.models import Q
from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
from django.template.defaultfilters import date
from django.utils.translation import ugettext, ugettext_lazy as _
from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible
from schedule.conf import settings
from schedule.models.rules import Rule
from schedule.models.calendars import Calendar
from schedule.utils import OccurrenceReplacer
from schedule.utils import get_model_bases
import pytz
from __future__ import division, unicode_literals
# -*- coding: utf-8 -*-




class EventManager(models.Manager):
    def get_for_object(self, content_object, distinction=None, inherit=True):
        return EventRelation.objects.get_events_for_object(content_object, distinction, inherit)



# Path: schedule/models/calendars.py
# class Calendar(with_metaclass(ModelBase, *get_model_bases())):
#     '''
#     This is for grouping events so that batch relations can be made to all
#     events.  An example would be a project calendar.
# 
#     name: the name of the calendar
#     events: all the events contained within the calendar.
#     >>> calendar = Calendar(name = 'Test Calendar')
#     >>> calendar.save()
#     >>> data = {
#     ...         'title': 'Recent Event',
#     ...         'start': datetime.datetime(2008, 1, 5, 0, 0),
#     ...         'end': datetime.datetime(2008, 1, 10, 0, 0)
#     ...        }
#     >>> event = Event(**data)
#     >>> event.save()
#     >>> calendar.events.add(event)
#     >>> data = {
#     ...         'title': 'Upcoming Event',
#     ...         'start': datetime.datetime(2008, 1, 1, 0, 0),
#     ...         'end': datetime.datetime(2008, 1, 4, 0, 0)
#     ...        }
#     >>> event = Event(**data)
#     >>> event.save()
#     >>> calendar.events.add(event)
#     >>> data = {
#     ...         'title': 'Current Event',
#     ...         'start': datetime.datetime(2008, 1, 3),
#     ...         'end': datetime.datetime(2008, 1, 6)
#     ...        }
#     >>> event = Event(**data)
#     >>> event.save()
#     >>> calendar.events.add(event)
#     '''
# 
#     name = models.CharField(_("name"), max_length=200)
#     slug = models.SlugField(_("slug"), max_length=200)
#     objects = CalendarManager()
# 
#     class Meta(object):
#         verbose_name = _('calendar')
#         verbose_name_plural = _('calendar')
#         app_label = 'schedule'
# 
#     def __str__(self):
#         return self.name
# 
#     @property
#     def events(self):
#         return self.event_set
# 
#     def create_relation(self, obj, distinction=None, inheritable=True):
#         """
#         Creates a CalendarRelation between self and obj.
# 
#         if Inheritable is set to true this relation will cascade to all events
#         related to this calendar.
#         """
#         CalendarRelation.objects.create_relation(self, obj, distinction, inheritable)
# 
#     def get_recent(self, amount=5, in_datetime=datetime.datetime.now, tzinfo=pytz.utc):
#         """
#         This shortcut function allows you to get events that have started
#         recently.
# 
#         amount is the amount of events you want in the queryset. The default is
#         5.
# 
#         in_datetime is the datetime you want to check against.  It defaults to
#         datetime.datetime.now
#         """
#         return self.events.order_by('-start').filter(start__lt=timezone.now())[:amount]
# 
#     def occurrences_after(self, date=None):
#         return EventListManager(self.events.all()).occurrences_after(date)
# 
#     def get_absolute_url(self):
#         return reverse('calendar_home', kwargs={'calendar_slug': self.slug})
# 
#     def add_event_url(self):
#         return reverse('calendar_create_event', args=[self.slug])
# 
# Path: schedule/utils.py
# class OccurrenceReplacer(object):
#     """
#     When getting a list of occurrences, the last thing that needs to be done
#     before passing it forward is to make sure all of the occurrences that
#     have been stored in the datebase replace, in the list you are returning,
#     the generated ones that are equivalent.  This class makes this easier.
#     """
# 
#     def __init__(self, persisted_occurrences):
#         lookup = [((occ.event, occ.original_start, occ.original_end), occ) for
#                   occ in persisted_occurrences]
#         self.lookup = dict(lookup)
# 
#     def get_occurrence(self, occ):
#         """
#         Return a persisted occurrences matching the occ and remove it from lookup since it
#         has already been matched
#         """
#         return self.lookup.pop(
#             (occ.event, occ.original_start, occ.original_end),
#             occ)
# 
#     def has_occurrence(self, occ):
#         try:
#             return (occ.event, occ.original_start, occ.original_end) in self.lookup
#         except TypeError:
#             if not self.lookup:
#                 return False
#             else:
#                 raise TypeError('A problem with checking if a persisted occurence exists has occured!')
# 
#     def get_additional_occurrences(self, start, end):
#         """
#         Return persisted occurrences which are now in the period
#         """
#         return [occ for _, occ in list(self.lookup.items()) if (occ.start < end and occ.end >= start and not occ.cancelled)]
# 
# Path: schedule/utils.py
# def get_model_bases():
#     from django.db.models import Model
#     baseStrings = getattr(settings, 'SCHEDULER_BASE_CLASSES', None)
#     if baseStrings is None:
#         return [Model]
#     else:
#         return [import_string(x) for x in baseStrings]


# Path: schedule/models/events.py
from django.utils.six import with_metaclass
from django.conf import settings as django_settings
from dateutil import rrule
from django.contrib.contenttypes import fields
from django.db import models
from django.db.models.base import ModelBase
from django.db.models import Q
from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
from django.template.defaultfilters import date
from django.utils.translation import ugettext, ugettext_lazy as _
from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible
from schedule.conf import settings
from schedule.models.rules import Rule
from schedule.models.calendars import Calendar
from schedule.utils import OccurrenceReplacer
from schedule.utils import get_model_bases
import pytz

from __future__ import division, unicode_literals
# -*- coding: utf-8 -*-




class EventManager(models.Manager):
    def get_for_object(self, content_object, distinction=None, inherit=True):
        return EventRelation.objects.get_events_for_object(content_object, distinction, inherit)



@python_2_unicode_compatible