Ejemplo n.º 1
0
    def setUp(self):
        weekly = Rule(frequency="WEEKLY")
        weekly.save()
        daily = Rule(frequency="DAILY")
        daily.save()
        cal = Calendar(name="MyCal")
        cal.save()

        self.event1 = Event(
            **{
                'title': 'Weekly Event',
                'start': datetime.datetime(2009, 4, 1, 8, 0),
                'end': datetime.datetime(2009, 4, 1, 9, 0),
                'end_recurring_period': datetime.datetime(2009, 10, 5, 0, 0),
                'rule': weekly,
                'calendar': cal
            })
        self.event1.save()
        self.event2 = Event(
            **{
                'title': 'Recent Event',
                'start': datetime.datetime(2008, 1, 5, 9, 0),
                'end': datetime.datetime(2008, 1, 5, 10, 0),
                'end_recurring_period': datetime.datetime(2009, 5, 5, 0, 0),
                'rule': daily,
                'calendar': cal
            })
        self.event2.save()
Ejemplo n.º 2
0
class TestOccurrencePool(TestCase):
    def setUp(self):
        rule = Rule(frequency="WEEKLY")
        rule.save()
        cal = Calendar(name="MyCal")
        cal.save()
        data = {
            'title': 'Recent Event',
            'start': datetime.datetime(2008, 1, 5, 8, 0),
            'end': datetime.datetime(2008, 1, 5, 9, 0),
            'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0),
            'rule': rule,
            'calendar': cal
        }
        self.recurring_event = Event(**data)
        self.recurring_event.save()

    def testPeriodFromPool(self):
        """
            Test that period initiated with occurrence_pool returns the same occurrences as "straigh" period
            in a corner case whereby a period's start date is equal to the occurrence's end date
        """
        start = datetime.datetime(2008, 1, 5, 9, 0)
        end = datetime.datetime(2008, 1, 5, 10, 0)
        parent_period = Period(Event.objects.all(), start, end)
        period = Period(parent_period.events, start, end,
                        parent_period.get_persisted_occurrences(),
                        parent_period.occurrences)
        self.assertEquals(parent_period.occurrences, period.occurrences)
Ejemplo n.º 3
0
    def setUp(self):
        weekly = Rule(frequency = "WEEKLY")
        weekly.save()
        daily = Rule(frequency = "DAILY")
        daily.save()
        cal = Calendar(name="MyCal")
        cal.save()

        self.event1 = Event(**{
                'title': 'Weekly Event',
                'start': datetime.datetime(2009, 4, 1, 8, 0),
                'end': datetime.datetime(2009, 4, 1, 9, 0),
                'end_recurring_period' : datetime.datetime(2009, 10, 5, 0, 0),
                'rule': weekly,
                'calendar': cal
               })
        self.event1.save()
        self.event2 = Event(**{
                'title': 'Recent Event',
                'start': datetime.datetime(2008, 1, 5, 9, 0),
                'end': datetime.datetime(2008, 1, 5, 10, 0),
                'end_recurring_period' : datetime.datetime(2009, 5, 5, 0, 0),
                'rule': daily,
                'calendar': cal
               })
        self.event2.save()
Ejemplo n.º 4
0
 def test_event_get_occurrences_after(self):
     recurring_event=Event(**self.recurring_data)
     recurring_event.save()
     occurrences = recurring_event.get_occurrences(start=datetime.datetime(2008, 1, 5),
         end = datetime.datetime(2008, 1, 6))
     occurrence = occurrences[0]
     occurrence2 = recurring_event.occurrences_after(datetime.datetime(2008,1,5)).next()
     self.assertEqual(occurrence, occurrence2)
Ejemplo n.º 5
0
 def test_get_occurrence(self):
     event = Event(**self.recurring_data)
     event.save()
     occurrence = event.get_occurrence(datetime.datetime(2008, 1, 5, 8, 0))
     self.assertEqual(occurrence.start, datetime.datetime(2008,1,5,8))
     occurrence.save()
     occurrence = event.get_occurrence(datetime.datetime(2008, 1, 5, 8, 0))
     self.assertTrue(occurrence.pk is not None)
Ejemplo n.º 6
0
 def test_recurring_event_get_occurrences(self):
     recurring_event = Event(**self.recurring_data)
     occurrences = recurring_event.get_occurrences(
         start=datetime.datetime(2008, 1, 12, 0, 0),
         end=datetime.datetime(2008, 1, 20, 0, 0))
     self.assertEquals(["%s to %s" % (o.start, o.end) for o in occurrences],
                       [
                           '2008-01-12 08:00:00 to 2008-01-12 09:00:00',
                           '2008-01-19 08:00:00 to 2008-01-19 09:00:00'
                       ])
Ejemplo n.º 7
0
 def setUp(self):
     rule = Rule(frequency="WEEKLY")
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     data = {
         'title': 'Recent Event',
         'start': datetime.datetime(2008, 1, 5, 8, 0),
         'end': datetime.datetime(2008, 1, 5, 9, 0),
         'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0),
         'rule': rule,
         'calendar': cal
     }
     self.recurring_event = Event(**data)
     self.recurring_event.save()
Ejemplo n.º 8
0
 def setUp(self):
     rule = Rule(frequency="WEEKLY")
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     data = {
         'title': 'Recent Event',
         'start': datetime.datetime(2008, 1, 5, 8, 0),
         'end': datetime.datetime(2008, 1, 5, 9, 0),
         'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0),
         'rule': rule,
         'calendar': cal
     }
     recurring_event = Event(**data)
     recurring_event.save()
     self.month = Month(events=Event.objects.all(),
                        date=datetime.datetime(2008, 2, 7, 9, 0))
Ejemplo n.º 9
0
class TestEventListManager(TestCase):
    def setUp(self):
        weekly = Rule(frequency="WEEKLY")
        weekly.save()
        daily = Rule(frequency="DAILY")
        daily.save()
        cal = Calendar(name="MyCal")
        cal.save()

        self.event1 = Event(
            **{
                'title': 'Weekly Event',
                'start': datetime.datetime(2009, 4, 1, 8, 0),
                'end': datetime.datetime(2009, 4, 1, 9, 0),
                'end_recurring_period': datetime.datetime(2009, 10, 5, 0, 0),
                'rule': weekly,
                'calendar': cal
            })
        self.event1.save()
        self.event2 = Event(
            **{
                'title': 'Recent Event',
                'start': datetime.datetime(2008, 1, 5, 9, 0),
                'end': datetime.datetime(2008, 1, 5, 10, 0),
                'end_recurring_period': datetime.datetime(2009, 5, 5, 0, 0),
                'rule': daily,
                'calendar': cal
            })
        self.event2.save()

    def test_occurrences_after(self):
        eml = EventListManager([self.event1, self.event2])
        occurrences = eml.occurrences_after(datetime.datetime(
            2009, 4, 1, 0, 0))
        self.assertEqual(occurrences.next().event, self.event1)
        self.assertEqual(occurrences.next().event, self.event2)
        self.assertEqual(occurrences.next().event, self.event2)
        self.assertEqual(occurrences.next().event, self.event2)
        self.assertEqual(occurrences.next().event, self.event2)
        self.assertEqual(occurrences.next().event, self.event2)
        self.assertEqual(occurrences.next().event, self.event2)
        self.assertEqual(occurrences.next().event, self.event2)
        self.assertEqual(occurrences.next().event, self.event1)
Ejemplo n.º 10
0
class TestEventListManager(TestCase):
    def setUp(self):
        weekly = Rule(frequency = "WEEKLY")
        weekly.save()
        daily = Rule(frequency = "DAILY")
        daily.save()
        cal = Calendar(name="MyCal")
        cal.save()

        self.event1 = Event(**{
                'title': 'Weekly Event',
                'start': datetime.datetime(2009, 4, 1, 8, 0),
                'end': datetime.datetime(2009, 4, 1, 9, 0),
                'end_recurring_period' : datetime.datetime(2009, 10, 5, 0, 0),
                'rule': weekly,
                'calendar': cal
               })
        self.event1.save()
        self.event2 = Event(**{
                'title': 'Recent Event',
                'start': datetime.datetime(2008, 1, 5, 9, 0),
                'end': datetime.datetime(2008, 1, 5, 10, 0),
                'end_recurring_period' : datetime.datetime(2009, 5, 5, 0, 0),
                'rule': daily,
                'calendar': cal
               })
        self.event2.save()

    def test_occurrences_after(self):
        eml = EventListManager([self.event1, self.event2])
        occurrences = eml.occurrences_after(datetime.datetime(2009,4,1,0,0))
        self.assertEqual(occurrences.next().event, self.event1)
        self.assertEqual(occurrences.next().event, self.event2)
        self.assertEqual(occurrences.next().event, self.event2)
        self.assertEqual(occurrences.next().event, self.event2)
        self.assertEqual(occurrences.next().event, self.event2)
        self.assertEqual(occurrences.next().event, self.event2)
        self.assertEqual(occurrences.next().event, self.event2)
        self.assertEqual(occurrences.next().event, self.event2)
        self.assertEqual(occurrences.next().event, self.event1)
Ejemplo n.º 11
0
 def test_get_occurrence(self):
     event = Event(**self.recurring_data)
     event.save()
     occurrence = event.get_occurrence(datetime.datetime(2008, 1, 5, 8, 0))
     self.assertEqual(occurrence.start, datetime.datetime(2008, 1, 5, 8))
     occurrence.save()
     occurrence = event.get_occurrence(datetime.datetime(2008, 1, 5, 8, 0))
     self.assertTrue(occurrence.pk is not None)
Ejemplo n.º 12
0
 def test_event_get_occurrences_after(self):
     recurring_event = Event(**self.recurring_data)
     recurring_event.save()
     occurrences = recurring_event.get_occurrences(
         start=datetime.datetime(2008, 1, 5),
         end=datetime.datetime(2008, 1, 6))
     occurrence = occurrences[0]
     occurrence2 = recurring_event.occurrences_after(
         datetime.datetime(2008, 1, 5)).next()
     self.assertEqual(occurrence, occurrence2)
Ejemplo n.º 13
0
 def setUp(self):
     rule = Rule(frequency = "WEEKLY")
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     self.recurring_data = {
             'title': 'Recent Event',
             'start': datetime.datetime(2008, 1, 5, 8, 0),
             'end': datetime.datetime(2008, 1, 5, 9, 0),
             'end_recurring_period' : datetime.datetime(2008, 5, 5, 0, 0),
             'rule': rule,
             'calendar': cal
            }
     self.data = {
             'title': 'Recent Event',
             'start': datetime.datetime(2008, 1, 5, 8, 0),
             'end': datetime.datetime(2008, 1, 5, 9, 0),
             'end_recurring_period' : datetime.datetime(2008, 5, 5, 0, 0),
             'calendar': cal
            }
     self.recurring_event = Event(**self.recurring_data)
     self.recurring_event.save()
     self.start = datetime.datetime(2008, 1, 12, 0, 0)
     self.end = datetime.datetime(2008, 1, 27, 0, 0)
Ejemplo n.º 14
0
class TestOccurrence(TestCase):
    def setUp(self):
        rule = Rule(frequency = "WEEKLY")
        rule.save()
        cal = Calendar(name="MyCal")
        cal.save()
        self.recurring_data = {
                'title': 'Recent Event',
                'start': datetime.datetime(2008, 1, 5, 8, 0),
                'end': datetime.datetime(2008, 1, 5, 9, 0),
                'end_recurring_period' : datetime.datetime(2008, 5, 5, 0, 0),
                'rule': rule,
                'calendar': cal
               }
        self.data = {
                'title': 'Recent Event',
                'start': datetime.datetime(2008, 1, 5, 8, 0),
                'end': datetime.datetime(2008, 1, 5, 9, 0),
                'end_recurring_period' : datetime.datetime(2008, 5, 5, 0, 0),
                'calendar': cal
               }
        self.recurring_event = Event(**self.recurring_data)
        self.recurring_event.save()
        self.start = datetime.datetime(2008, 1, 12, 0, 0)
        self.end = datetime.datetime(2008, 1, 27, 0, 0)

    def test_presisted_occurrences(self):
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        persisted_occurrence = occurrences[0]
        persisted_occurrence.save()
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertTrue(occurrences[0].pk)
        self.assertFalse(occurrences[1].pk)

    def test_moved_occurrences(self):
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        moved_occurrence = occurrences[1]
        span_pre = (moved_occurrence.start, moved_occurrence.end)
        span_post = [x + datetime.timedelta(hours=2) for x in span_pre]
        # check has_occurrence on both periods
        period_pre = Period([self.recurring_event], span_pre[0], span_pre[1])
        period_post = Period([self.recurring_event], span_post[0], span_post[1])
        self.assertTrue(period_pre.has_occurrences())
        self.assertFalse(period_post.has_occurrences())
        # move occurrence
        moved_occurrence.move(moved_occurrence.start+datetime.timedelta(hours=2),
                              moved_occurrence.end+datetime.timedelta(hours=2))
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertTrue(occurrences[1].moved)
        # check has_occurrence on both periods (the result should be reversed)
        period_pre = Period([self.recurring_event], span_pre[0], span_pre[1])
        period_post = Period([self.recurring_event], span_post[0], span_post[1])
        self.assertFalse(period_pre.has_occurrences())
        self.assertTrue(period_post.has_occurrences())

    def test_cancelled_occurrences(self):
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        cancelled_occurrence = occurrences[2]
        cancelled_occurrence.cancel()
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertTrue(occurrences[2].cancelled)
        cancelled_occurrence.uncancel()
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertFalse(occurrences[2].cancelled)
    def handle_noargs(self, **options):
        import datetime
        from appointments.models import Calendar
        from appointments.models import Event
        from appointments.models import Rule

        print "checking for existing data ..."
        try:
            cal = Calendar.objects.get(name="yml_cal")
            print "It looks like you already have loaded the sample data, quitting."
            import sys
            sys.exit(1)
        except Calendar.DoesNotExist:
            print "Sample data not found in db."
            print "Install it..."


        print "Create 2 calendars : tony_cal, yml_cal"
        yml_cal = Calendar(name="yml_cal",slug="yml")
        yml_cal.save()
        print "First calendar is created"
        tony_cal = Calendar(name="tony_cal",slug="tony")
        tony_cal.save()
        print "Second calendar is created"
        print "Do we need to create the most common rules?"
        try:
            rule = Rule.objects.get(name="Daily")
        except Rule.DoesNotExist:
            rule = Rule(frequency = "YEARLY", name = "Yearly", description = "will recur once every Year")
            rule.save()
            print "YEARLY recurrence created"
            rule = Rule(frequency = "MONTHLY", name = "Monthly", description = "will recur once every Month")
            rule.save()
            print "Monthly recurrence created"
            rule = Rule(frequency = "WEEKLY", name = "Weekly", description = "will recur once every Week")
            rule.save()
            print "Weekly recurrence created"
            rule = Rule(frequency = "DAILY", name = "Daily", description = "will recur once every Day")
            rule.save()
            print "Daily recurrence created"
        print "The common rules are installed."

        print "Create some events"
        rule = Rule.objects.get(frequency="WEEKLY")
        data = {
                'title': 'Ping pong',
                'start': datetime.datetime(2008, 11, 1, 8, 0),
                'end': datetime.datetime(2008, 11, 1, 9, 0),
                'end_recurring_period' : datetime.datetime(2010, 5, 5, 0, 0),
                'rule': rule,
                'calendar': tony_cal
               }
        event = Event(**data)
        event.save()
        rule = Rule.objects.get(frequency="DAILY")
        data = {
                'title': 'Home work',
                'start': datetime.datetime(2008, 11, 1, 18, 0),
                'end': datetime.datetime(2008, 11, 1, 19, 0),
                'end_recurring_period' : datetime.datetime(2010, 5, 5, 0, 0),
                'rule': rule,
                'calendar': tony_cal
               }
        event = Event(**data)
        event.save()
Ejemplo n.º 16
0
 def test_recurring_event_get_occurrences(self):
     recurring_event = Event(**self.recurring_data)
     occurrences = recurring_event.get_occurrences(start=datetime.datetime(2008, 1, 12, 0, 0),
                                 end=datetime.datetime(2008, 1, 20, 0, 0))
     self.assertEquals(["%s to %s" %(o.start, o.end) for o in occurrences],
         ['2008-01-12 08:00:00 to 2008-01-12 09:00:00', '2008-01-19 08:00:00 to 2008-01-19 09:00:00'])
Ejemplo n.º 17
0
    def handle_noargs(self, **options):
        import datetime
        from appointments.models import Calendar
        from appointments.models import Event
        from appointments.models import Rule

        print "checking for existing data ..."
        try:
            cal = Calendar.objects.get(name="yml_cal")
            print "It looks like you already have loaded the sample data, quitting."
            import sys
            sys.exit(1)
        except Calendar.DoesNotExist:
            print "Sample data not found in db."
            print "Install it..."

        print "Create 2 calendars : tony_cal, yml_cal"
        yml_cal = Calendar(name="yml_cal", slug="yml")
        yml_cal.save()
        print "First calendar is created"
        tony_cal = Calendar(name="tony_cal", slug="tony")
        tony_cal.save()
        print "Second calendar is created"
        print "Do we need to create the most common rules?"
        try:
            rule = Rule.objects.get(name="Daily")
        except Rule.DoesNotExist:
            rule = Rule(frequency="YEARLY",
                        name="Yearly",
                        description="will recur once every Year")
            rule.save()
            print "YEARLY recurrence created"
            rule = Rule(frequency="MONTHLY",
                        name="Monthly",
                        description="will recur once every Month")
            rule.save()
            print "Monthly recurrence created"
            rule = Rule(frequency="WEEKLY",
                        name="Weekly",
                        description="will recur once every Week")
            rule.save()
            print "Weekly recurrence created"
            rule = Rule(frequency="DAILY",
                        name="Daily",
                        description="will recur once every Day")
            rule.save()
            print "Daily recurrence created"
        print "The common rules are installed."

        print "Create some events"
        rule = Rule.objects.get(frequency="WEEKLY")
        data = {
            'title': 'Ping pong',
            'start': datetime.datetime(2008, 11, 1, 8, 0),
            'end': datetime.datetime(2008, 11, 1, 9, 0),
            'end_recurring_period': datetime.datetime(2010, 5, 5, 0, 0),
            'rule': rule,
            'calendar': tony_cal
        }
        event = Event(**data)
        event.save()
        rule = Rule.objects.get(frequency="DAILY")
        data = {
            'title': 'Home work',
            'start': datetime.datetime(2008, 11, 1, 18, 0),
            'end': datetime.datetime(2008, 11, 1, 19, 0),
            'end_recurring_period': datetime.datetime(2010, 5, 5, 0, 0),
            'rule': rule,
            'calendar': tony_cal
        }
        event = Event(**data)
        event.save()
Ejemplo n.º 18
0
class TestOccurrence(TestCase):
    def setUp(self):
        rule = Rule(frequency="WEEKLY")
        rule.save()
        cal = Calendar(name="MyCal")
        cal.save()
        self.recurring_data = {
            'title': 'Recent Event',
            'start': datetime.datetime(2008, 1, 5, 8, 0),
            'end': datetime.datetime(2008, 1, 5, 9, 0),
            'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0),
            'rule': rule,
            'calendar': cal
        }
        self.data = {
            'title': 'Recent Event',
            'start': datetime.datetime(2008, 1, 5, 8, 0),
            'end': datetime.datetime(2008, 1, 5, 9, 0),
            'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0),
            'calendar': cal
        }
        self.recurring_event = Event(**self.recurring_data)
        self.recurring_event.save()
        self.start = datetime.datetime(2008, 1, 12, 0, 0)
        self.end = datetime.datetime(2008, 1, 27, 0, 0)

    def test_presisted_occurrences(self):
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                                           end=self.end)
        persisted_occurrence = occurrences[0]
        persisted_occurrence.save()
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                                           end=self.end)
        self.assertTrue(occurrences[0].pk)
        self.assertFalse(occurrences[1].pk)

    def test_moved_occurrences(self):
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                                           end=self.end)
        moved_occurrence = occurrences[1]
        span_pre = (moved_occurrence.start, moved_occurrence.end)
        span_post = [x + datetime.timedelta(hours=2) for x in span_pre]
        # check has_occurrence on both periods
        period_pre = Period([self.recurring_event], span_pre[0], span_pre[1])
        period_post = Period([self.recurring_event], span_post[0],
                             span_post[1])
        self.assertTrue(period_pre.has_occurrences())
        self.assertFalse(period_post.has_occurrences())
        # move occurrence
        moved_occurrence.move(
            moved_occurrence.start + datetime.timedelta(hours=2),
            moved_occurrence.end + datetime.timedelta(hours=2))
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                                           end=self.end)
        self.assertTrue(occurrences[1].moved)
        # check has_occurrence on both periods (the result should be reversed)
        period_pre = Period([self.recurring_event], span_pre[0], span_pre[1])
        period_post = Period([self.recurring_event], span_post[0],
                             span_post[1])
        self.assertFalse(period_pre.has_occurrences())
        self.assertTrue(period_post.has_occurrences())

    def test_cancelled_occurrences(self):
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                                           end=self.end)
        cancelled_occurrence = occurrences[2]
        cancelled_occurrence.cancel()
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                                           end=self.end)
        self.assertTrue(occurrences[2].cancelled)
        cancelled_occurrence.uncancel()
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                                           end=self.end)
        self.assertFalse(occurrences[2].cancelled)
    def handle_noargs(self, **options):
        import datetime
        from appointments.models import Calendar
        from appointments.models import Event
        from appointments.models import Rule

        print "checking for existing data ..."
        try:
            cal = Calendar.objects.get(name="Example Calendar")
            print "It looks like you already have loaded this sample data, quitting."
            import sys
            sys.exit(1)
        except Calendar.DoesNotExist:
            print "Sample data not found in db."
            print "Install it..."


        print "Create Example Calendar ..."
        cal = Calendar(name="Example Calendar",slug="example")
        cal.save()
        print "The Example Calendar is created."
        print "Do we need to install the most common rules?"
        try:
            rule = Rule.objects.get(name="Daily")
        except Rule.DoesNotExist:
            print "Need to install the basic rules"
            rule = Rule(frequency = "YEARLY", name = "Yearly", description = "will recur once every Year")
            rule.save()
            print "YEARLY recurrence created"
            rule = Rule(frequency = "MONTHLY", name = "Monthly", description = "will recur once every Month")
            rule.save()
            print "Monthly recurrence created"
            rule = Rule(frequency = "WEEKLY", name = "Weekly", description = "will recur once every Week")
            rule.save()
            print "Weekly recurrence created"
            rule = Rule(frequency = "DAILY", name = "Daily", description = "will recur once every Day")
            rule.save()
            print "Daily recurrence created"
        print "Rules installed."

        print "Create some events"
        rule = Rule.objects.get(frequency="WEEKLY")
        data = {
                'title': 'Exercise',
                'start': datetime.datetime(2008, 11, 3, 8, 0),
                'end': datetime.datetime(2008, 11, 3, 9, 0),
                'end_recurring_period' : datetime.datetime(2009, 6, 1, 0, 0),
                'rule': rule,
                'calendar': cal
               }
        event = Event(**data)
        event.save()

        data = {
                'title': 'Exercise',
                'start': datetime.datetime(2008, 11, 5, 15, 0),
                'end': datetime.datetime(2008, 11, 5, 16, 30),
                'end_recurring_period' : datetime.datetime(2009, 6, 1, 0, 0),
                'rule': rule,
                'calendar': cal
               }
        event = Event(**data)
        event.save()

        data = {
                'title': 'Exercise',
                'start': datetime.datetime(2008, 11, 7, 8, 0),
                'end': datetime.datetime(2008, 11, 7, 9, 30),
                'end_recurring_period' : datetime.datetime(2009, 6, 1, 0, 0),
                'rule': rule,
                'calendar': cal
               }
        event = Event(**data)
        event.save()

        rule = Rule.objects.get(frequency="MONTHLY")
        data = {
                'title': 'Pay Mortgage',
                'start': datetime.datetime(2008, 11, 1, 14, 0),
                'end': datetime.datetime(2008, 11, 1, 14, 30),
                'end_recurring_period' : datetime.datetime(2009, 10, 2, 0, 0),
                'rule': rule,
                'calendar': cal
               }
        event = Event(**data)
        event.save()

        rule = Rule.objects.get(frequency="YEARLY")
        data = {
                'title': "Rock's Birthday Party",
                'start': datetime.datetime(2008, 12, 11, 19, 0),
                'end': datetime.datetime(2008, 12, 11, 23, 59),
                'end_recurring_period' : datetime.datetime(2009, 12, 22, 0, 0),
                'rule': rule,
                'calendar': cal
               }
        event = Event(**data)
        event.save()

        data = {
                'title': 'Christmas Party',
                'start': datetime.datetime(2008, 12, 25, 19, 30),
                'end': datetime.datetime(2008, 12, 25, 23, 59),
                'end_recurring_period' : datetime.datetime(2010, 12, 31, 0, 0),
                'rule': rule,
                'calendar': cal
               }
        event = Event(**data)
        event.save()

        data = {
                'title': 'New Pinax site goes live',
                'start': datetime.datetime(2009, 1, 6, 11, 0),
                'end': datetime.datetime(2009, 1, 6, 12, 00),
                'end_recurring_period' : datetime.datetime(2009, 1, 7, 0, 0),
                'calendar': cal
               }
        event = Event(**data)
        event.save()
Ejemplo n.º 20
0
    def handle_noargs(self, **options):
        import datetime
        from appointments.models import Calendar
        from appointments.models import Event
        from appointments.models import Rule

        print "checking for existing data ..."
        try:
            cal = Calendar.objects.get(name="Example Calendar")
            print "It looks like you already have loaded this sample data, quitting."
            import sys
            sys.exit(1)
        except Calendar.DoesNotExist:
            print "Sample data not found in db."
            print "Install it..."

        print "Create Example Calendar ..."
        cal = Calendar(name="Example Calendar", slug="example")
        cal.save()
        print "The Example Calendar is created."
        print "Do we need to install the most common rules?"
        try:
            rule = Rule.objects.get(name="Daily")
        except Rule.DoesNotExist:
            print "Need to install the basic rules"
            rule = Rule(frequency="YEARLY",
                        name="Yearly",
                        description="will recur once every Year")
            rule.save()
            print "YEARLY recurrence created"
            rule = Rule(frequency="MONTHLY",
                        name="Monthly",
                        description="will recur once every Month")
            rule.save()
            print "Monthly recurrence created"
            rule = Rule(frequency="WEEKLY",
                        name="Weekly",
                        description="will recur once every Week")
            rule.save()
            print "Weekly recurrence created"
            rule = Rule(frequency="DAILY",
                        name="Daily",
                        description="will recur once every Day")
            rule.save()
            print "Daily recurrence created"
        print "Rules installed."

        print "Create some events"
        rule = Rule.objects.get(frequency="WEEKLY")
        data = {
            'title': 'Exercise',
            'start': datetime.datetime(2008, 11, 3, 8, 0),
            'end': datetime.datetime(2008, 11, 3, 9, 0),
            'end_recurring_period': datetime.datetime(2009, 6, 1, 0, 0),
            'rule': rule,
            'calendar': cal
        }
        event = Event(**data)
        event.save()

        data = {
            'title': 'Exercise',
            'start': datetime.datetime(2008, 11, 5, 15, 0),
            'end': datetime.datetime(2008, 11, 5, 16, 30),
            'end_recurring_period': datetime.datetime(2009, 6, 1, 0, 0),
            'rule': rule,
            'calendar': cal
        }
        event = Event(**data)
        event.save()

        data = {
            'title': 'Exercise',
            'start': datetime.datetime(2008, 11, 7, 8, 0),
            'end': datetime.datetime(2008, 11, 7, 9, 30),
            'end_recurring_period': datetime.datetime(2009, 6, 1, 0, 0),
            'rule': rule,
            'calendar': cal
        }
        event = Event(**data)
        event.save()

        rule = Rule.objects.get(frequency="MONTHLY")
        data = {
            'title': 'Pay Mortgage',
            'start': datetime.datetime(2008, 11, 1, 14, 0),
            'end': datetime.datetime(2008, 11, 1, 14, 30),
            'end_recurring_period': datetime.datetime(2009, 10, 2, 0, 0),
            'rule': rule,
            'calendar': cal
        }
        event = Event(**data)
        event.save()

        rule = Rule.objects.get(frequency="YEARLY")
        data = {
            'title': "Rock's Birthday Party",
            'start': datetime.datetime(2008, 12, 11, 19, 0),
            'end': datetime.datetime(2008, 12, 11, 23, 59),
            'end_recurring_period': datetime.datetime(2009, 12, 22, 0, 0),
            'rule': rule,
            'calendar': cal
        }
        event = Event(**data)
        event.save()

        data = {
            'title': 'Christmas Party',
            'start': datetime.datetime(2008, 12, 25, 19, 30),
            'end': datetime.datetime(2008, 12, 25, 23, 59),
            'end_recurring_period': datetime.datetime(2010, 12, 31, 0, 0),
            'rule': rule,
            'calendar': cal
        }
        event = Event(**data)
        event.save()

        data = {
            'title': 'New Pinax site goes live',
            'start': datetime.datetime(2009, 1, 6, 11, 0),
            'end': datetime.datetime(2009, 1, 6, 12, 00),
            'end_recurring_period': datetime.datetime(2009, 1, 7, 0, 0),
            'calendar': cal
        }
        event = Event(**data)
        event.save()