def get_calendar(self, appointment_id):
        try:
            appointmet = self.get_appointment(appointment_id)
            if appointmet:
                cal = Calendar()

                cal.add(
                    'prodid', '-//{0} Events Calendar//{1}//'.format(
                        "BMW service Appointment", "BMW service Appointment"))
                cal.add('version', '2.0')

                ical_event = Event()
                ical_event.add('summary',
                               "Appointment Scheduled with BMW Services")
                ical_event.add('dtstart', appointmet.start_time)
                ical_event.add(
                    'dtend',
                    appointmet.start_time + datetime.timedelta(minutes=20))
                ical_event.add('dtstamp', appointmet.start_time)
                ical_event['uid'] = str(appointmet.confirmation_code)
                cal.add_component(ical_event)
                return cal
            else:
                return False

        except Exception, e:
            print e

            return False
Exemplo n.º 2
0
def ics(request):
    team_id_list = request.GET.getlist('team_id')
    league_id_list = request.GET.getlist('league_id')
    org_id_list = request.GET.getlist('org_id')

    teams = get_teams(team_id_list)
    leagues = get_leagues(league_id_list)
    orgs = get_orgs(org_id_list)

    if len(teams) == 1:
        cal_name = teams[0].name
    elif len(leagues) == 1:
        cal_name = leagues[0].name
    elif len(orgs) == 1:
        cal_name = orgs[0].name
    else:
        cal_name = "Soccer Games"

    cal = Calendar()
    cal.add('prodid', '-//Soccer Game Schedules//Soccer Calendars//EN')
    cal.add('version', '2.0')
    cal.add('X-WR-CALNAME', cal_name)
    cal.add('X-WR-TIMEZONE', 'CST6CDT')
    cal.add('X-WR-CALDESC', 'Soccer Team Schedule')

    for team in teams:
        for game in team.games().order_by("time", "field"):
            add_game(cal, game)

    for league in leagues:
        for game in Game.objects.filter(league=league).order_by("time", "field"):
            add_game(cal, game)

    for org in orgs:
        for league in League.objects.filter(org=org):
            for game in Game.objects.filter(league=league).order_by("time", "field"):
                add_game(cal, game)

    return HttpResponse(cal.to_ical(), content_type='text/calendar')