Exemple #1
0
    def test_tools_UIDGenerator(self):

        # Automatic semi-random uid
        g = UIDGenerator()
        uid = g.uid()
        txt = uid.to_ical()
        length = 15 + 1 + 16 + 1 + 11
        self.assertTrue(len(txt) == length)
        self.assertTrue('@example.com' in txt)

        # You should at least insert your own hostname to be more compliant
        uid = g.uid('Example.ORG')
        txt = uid.to_ical()
        self.assertTrue(len(txt) == length)
        self.assertTrue('@Example.ORG' in txt)

        # You can also insert a path or similar
        uid = g.uid('Example.ORG', '/path/to/content')
        txt = uid.to_ical()
        self.assertTrue(len(txt) == length)
        self.assertTrue('-/path/to/[email protected]' in txt)
Exemple #2
0
def get_events_workout(calendar, workout, duration, start_date=None):
    '''
    Creates all necessary events from the given workout and adds them to
    the calendar. Each event's occurrence ist set to weekly (one event for
    each training day).

    :param calendar: calendar to add events to
    :param workout: Workout
    :param duration: duration in weeks
    :param start_date: start date, default: profile default
    :return: None
    '''

    start_date = start_date if start_date else workout.creation_date
    end_date = start_date + datetime.timedelta(weeks=duration)
    generator = UIDGenerator()
    site = Site.objects.get_current()

    for day in workout.canonical_representation['day_list']:

        # Make the description of the event with the day's exercises
        description_list = []
        for set in day['set_list']:
            for exercise in set['exercise_list']:
                description_list.append(six.text_type(exercise['obj']))
        description = ', '.join(
            description_list) if description_list else day['obj'].description

        # Make an event for each weekday
        for weekday in day['days_of_week']['day_list']:
            event = Event()
            event.add('summary', day['obj'].description)
            event.add('description', description)
            event.add('dtstart', next_weekday(start_date, weekday.id - 1))
            event.add('dtend', next_weekday(start_date, weekday.id - 1))
            event.add('rrule', {'freq': 'weekly', 'until': end_date})
            event['uid'] = generator.uid(host_name=site.domain)
            event.add('priority', 5)
            calendar.add_component(event)
Exemple #3
0
#    calendar = calendars[0]
#    print "Using calendar", calendar
#
#    print "Looking for events"
#    results = calendar.date_search(datetime(2013, 12, 1))
#    for event in results:
#        print "Found", event

cal = Calendar()
cal.add('calscale', 'GREGORIAN')
cal.add('version', '2.0')
cal.add('method', 'REQUEST')
cal.add('prodid', '-//MeetingGroom//iroazh.eu//')

freebusy = FreeBusy()
freebusy.add('uid', UIDGenerator().uid(gethostname()))
freebusy.add('dtstart', datetime(2013, 12, 12))
freebusy.add('dtend', datetime(2013, 12, 13))

cal.add_component(freebusy)

request = cal.to_ical()

request = \
"""BEGIN:VCALENDAR
CALSCALE:GREGORIAN
VERSION:2.0
METHOD:REQUEST
PRODID:-//Apple Inc.//Mac OS X 10.9//EN
BEGIN:VFREEBUSY
UID:4790384D-220D-4B73-86E4-CF639975EC2B