Example #1
0
    def test_next_weekday(self):
        '''
        Test the next weekday function
        '''
        start_date = datetime.date(2013, 12, 5)

        # Find next monday
        self.assertEqual(next_weekday(start_date, 0), datetime.date(2013, 12, 9))

        # Find next wednesday
        self.assertEqual(next_weekday(start_date, 2), datetime.date(2013, 12, 11))

        # Find next saturday
        self.assertEqual(next_weekday(start_date, 5), datetime.date(2013, 12, 7))
Example #2
0
    def test_next_weekday(self):
        '''
        Test the next weekday function
        '''
        start_date = datetime.date(2013, 12, 5)

        # Find next monday
        self.assertEqual(next_weekday(start_date, 0),
                         datetime.date(2013, 12, 9))

        # Find next wednesday
        self.assertEqual(next_weekday(start_date, 2),
                         datetime.date(2013, 12, 11))

        # Find next saturday
        self.assertEqual(next_weekday(start_date, 5),
                         datetime.date(2013, 12, 7))
Example #3
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)
Example #4
0
File: ical.py Project: httpdss/wger
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(pk=settings.SITE_ID)

    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(unicode(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)
Example #5
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)