class TestOccurrencePool(TestCase):
    def setUp(self):
        rule = Rule(frequency="WEEKLY",
                    end_recurring_period=datetime.datetime(
                        2008, 5, 5, 0, 0, tzinfo=timezone.utc))
        rule.save()
        cal = Calendar(name="MyCal")
        cal.save()
        data = {
            'start': datetime.datetime(2008, 1, 5, 8, 0, tzinfo=timezone.utc),
            'end': datetime.datetime(2008, 1, 5, 9, 0, tzinfo=timezone.utc),
            '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, tzinfo=timezone.utc)
        end = datetime.datetime(2008, 1, 5, 10, 0, tzinfo=timezone.utc)
        parent_period = Period(Event.objects.all(), start, end)
        period = Period(parent_period.events,
                        start,
                        end,
                        parent_period.get_persisted_occurrences(),
                        occurrence_pool=parent_period.occurrences)
        self.assertEqual(parent_period.occurrences, period.occurrences)
class TestAwareDay(TestCase):
    def setUp(self):
        self.timezone = NewYork()

        start = self.timezone.localize(datetime.datetime(2008, 2, 7, 0, 20))
        end = self.timezone.localize(datetime.datetime(2008, 2, 7, 0, 21))
        self.event = Event(
            start=start,
            end=end,
        )
        self.event.save()

        self.day = Day(
            events=Event.objects.all(),
            date=self.timezone.localize(datetime.datetime(2008, 2, 7, 9, 0)),
            tzinfo=self.timezone,
        )

    def test_day_range(self):
        start = datetime.datetime(2008, 2, 7, 5, 0, tzinfo=timezone.utc)
        end = datetime.datetime(2008, 2, 8, 5, 0, tzinfo=timezone.utc)

        self.assertEqual(start, self.day.start)
        self.assertEqual(end, self.day.end)

    def test_occurence(self):
        self.assertTrue(self.event in self.day.occurrences)
Esempio n. 3
0
    def test_edge_case_events(self):
        cal = Calendar(name="MyCal")
        cal.save()

        data_1 = {
            'start': datetime.datetime(2013, 1, 5, 8, 0, tzinfo=timezone.utc),
            'end': datetime.datetime(2013, 1, 5, 9, 0, tzinfo=timezone.utc),
            'calendar': cal,
        }

        data_2 = {
            'start': datetime.datetime(2013, 1, 5, 9, 0, tzinfo=timezone.utc),
            'end': datetime.datetime(2013, 1, 5, 12, 0, tzinfo=timezone.utc),
            'calendar': cal
        }
        event_one = Event(**data_1)
        event_two = Event(**data_2)
        event_one.save()
        event_two.save()

        occurrences_two = event_two.get_occurrences(
            datetime.datetime(2013, 1, 5, 9, 0, tzinfo=timezone.utc),
            datetime.datetime(2013, 1, 5, 12, 0, tzinfo=timezone.utc))
        self.assertEqual(1, len(occurrences_two))

        occurrences_one = event_one.get_occurrences(
            datetime.datetime(2013, 1, 5, 9, 0, tzinfo=timezone.utc),
            datetime.datetime(2013, 1, 5, 12, 0, tzinfo=timezone.utc))

        self.assertEqual(0, len(occurrences_one))
 def setUp(self):
     rule = Rule(frequency="WEEKLY",
                 end_recurring_period=datetime.datetime(
                     2008, 5, 5, 0, 0, tzinfo=timezone.utc))
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     data = {
         'start': datetime.datetime(2008, 1, 5, 8, 0, tzinfo=timezone.utc),
         'end': datetime.datetime(2008, 1, 5, 9, 0, tzinfo=timezone.utc),
         'rule': rule,
         'calendar': cal
     }
     data2 = {
         'start': datetime.datetime(2008, 1, 5, 8, 0, tzinfo=timezone.utc),
         'end': datetime.datetime(2008, 1, 5, 9, 0, tzinfo=timezone.utc),
         'calendar': cal
     }
     recurring_event = Event(**data)
     recurring_event.save()
     singular_event = Event(**data2)
     singular_event.save()
     self.period = Period(events=Event.objects.source_events(),
                          start=datetime.datetime(2008,
                                                  1,
                                                  4,
                                                  7,
                                                  0,
                                                  tzinfo=timezone.utc),
                          end=datetime.datetime(2008,
                                                1,
                                                21,
                                                7,
                                                0,
                                                tzinfo=timezone.utc))
 def setUp(self):
     rule = Rule(frequency="WEEKLY",
                 end_recurring_period=datetime.datetime(
                     2008, 5, 5, 0, 0, tzinfo=timezone.utc))
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     data = {
         'start': datetime.datetime(2008, 1, 5, 8, 0, tzinfo=timezone.utc),
         'end': datetime.datetime(2008, 1, 5, 9, 0, tzinfo=timezone.utc),
         'rule': rule,
         'calendar': cal
     }
     self.recurring_event = Event(**data)
     self.recurring_event.save()
    def setUp(self):
        self.timezone = NewYork()

        start = self.timezone.localize(datetime.datetime(2008, 2, 7, 0, 20))
        end = self.timezone.localize(datetime.datetime(2008, 2, 7, 0, 21))
        self.event = Event(
            start=start,
            end=end,
        )
        self.event.save()

        self.day = Day(
            events=Event.objects.all(),
            date=self.timezone.localize(datetime.datetime(2008, 2, 7, 9, 0)),
            tzinfo=self.timezone,
        )
Esempio n. 7
0
def create_occurrence(foreign_event_id,
                      start_time,
                      max_volunteer=0,
                      people=[],
                      locations=[],
                      parent_event_id=None,
                      labels=[]):
    if parent_event_id:
        parent_response = get_occurrence(parent_event_id)
        if parent_response.errors:
            return parent_response

    response = OccurrenceResponse()
    response.occurrence = Event(
        eventitem=EventItem.objects.get(eventitem_id=foreign_event_id),
        starttime=start_time,
        max_volunteer=max_volunteer)
    response.occurrence.save()
    if len(locations) > 0:
        response.occurrence.set_locations(locations)

    for person in people:
        response.warnings += response.occurrence.allocate_person(
            person).warnings

    for label in labels:
        response.occurrence.add_label(label)

    if parent_event_id:
        family = EventContainer(parent_event=parent_response.occurrence,
                                child_event=response.occurrence)
        family.save()

    return response
Esempio n. 8
0
 def __create_recurring_event(self, start, end, rule, cal):
     return Event(**{
         'start': start,
         'end': end,
         'rule': rule,
         'calendar': cal
     })
Esempio n. 9
0
def create_events_ajax(request):
    if request.session.has_key('EMAIL') == False:
        return redirect('/login/')
    
    details, return_data = [], {}
    models = request.POST.get('models', None)
    tz = request.POST.get('tz', None)
    
    models = models.replace('false','False').replace('true','True')
    
    import ast
    data =  ast.literal_eval(models)
    data_dict = data[-1]
    
    try:
        category = Category.objects.get(id = int(data_dict['categoryId']))
    except Exception as e:
        raise Exception(e.args[0])
    else:
        if data_dict['isAllDay'] == True: 
            start_date = (datetime.strptime(data_dict['start'], '%Y-%m-%dT%H:%M:00.000Z') - timedelta(minutes = int(tz))).date()
            end_date = (datetime.strptime(data_dict['end'], '%Y-%m-%dT%H:%M:00.000Z') - timedelta(minutes = int(tz))).date()
            start_date_time, end_date_time = None, None
        else:
            start_date_time = datetime.strptime(data_dict['start'], '%Y-%m-%dT%H:%M:00.000Z') - timedelta(minutes = int(tz))
            end_date_time = datetime.strptime(data_dict['end'], '%Y-%m-%dT%H:%M:00.000Z') - timedelta(minutes = int(tz))
            start_date, end_date = None, None
        
        try:
            entity_login = EntityLogin.objects.get(email = request.session['EMAIL'])
        except Exception as e:
            raise Exception(e.args[0])
        else:    
            event = Event(category = category, title = data_dict['title'], start_date = start_date,
                      start_date_time = start_date_time, to_date = end_date, to_date_time = end_date_time,
                      recurrenceID = data_dict['recurrenceID'], recurrenceRule = data_dict['recurrenceRule'],
                      recurrenceException = data_dict['recurrenceException'], isAllDay = data_dict['isAllDay'],
                      description = data_dict['description'], owner = entity_login)
        
        event.save()
        
    return HttpResponse(json.dumps(return_data), content_type = 'application/json')
def new_event():
    form = EventForm()
    if form.validate_on_submit():
        event = Event(start=form.start.data,
                      end=form.end.data,
                      subject=form.subject.data,
                      description=form.description.data,
                      author=current_user)
        db.session.add(event)
        db.session.commit()
        flash('Your event has been created!', 'success')
        return redirect(url_for('home'))
    return render_template('create_event.html',
                           title='New Event',
                           form=form,
                           legend='New Event')
def create_occurrence(foreign_event_id,
                      start_time,
                      max_volunteer=0,
                      max_commitments=0,
                      people=[],
                      locations=[],
                      parent_event_id=None,
                      labels=[],
                      approval=False):
    if parent_event_id:
        parent_response = get_occurrence(parent_event_id)
        if parent_response.errors:
            return parent_response

    response = OccurrenceResponse()
    response.occurrence = Event(
        eventitem=EventItem.objects.get(eventitem_id=foreign_event_id),
        starttime=start_time,
        max_volunteer=max_volunteer,
        max_commitments=max_commitments,
        approval_needed=approval)
    response.occurrence.save()
    if len(locations) > 0:
        response.occurrence.set_locations(locations)

    for person in people:
        response.warnings += response.occurrence.allocate_person(
            person).warnings

    for label in labels:
        label = EventLabel(text=label, event=response.occurrence)
        label.save()

    if parent_event_id:
        family = EventContainer(parent_event=parent_response.occurrence,
                                child_event=response.occurrence)
        family.save()

    return response
Esempio n. 12
0
def combine_events(event1, event2):
    # get EARLIER start_time
    if event1.start_time < event2.start_time:
        start_time = event1.start_time
    else:
        start_time = event2.start_time

    # get LATER end_time
    if event1.end_time > event2.end_time:
        end_time = event1.end_time
    else:
        end_time = event2.end_time

    # The final, combined event
    return Event(
            name="Combined Event",
            location="N/A",
            description="Combined two events",
            start_time=start_time,
            end_time=end_time,
            sunday=True,monday=True,tuesday=True,wednesday=True,thursday=True,friday=True,saturday=True, # Set all to true (it won't matter, because this event set is already matched to a day.
            start_date=datetime.datetime(1970,1,1),
            end_date=datetime.datetime(3000,12,31)
            )
Esempio n. 13
0
 def __create_event(self, start, end, cal):
     return Event(**{'start': start, 'end': end, 'calendar': cal})