示例#1
0
def details(request, calendar_slug, periods=None):
    try:
        sched = get_object_or_404(Calendar, slug=calendar_slug)
        date = coerce_date_dict(request.GET)
        if date:
            try:
                date = datetime(**date)
            except ValueError:
                raise Http404
        else:
            date = timezone.now()
        event_list = sched.event_set.all()
        currently_oncall_users = escalation_helper.get_current_events_users(
            sched)
        if len(currently_oncall_users) >= 2:
            oncall1 = "%s, Phone Number:%s" % (
                currently_oncall_users[0].username,
                currently_oncall_users[0].profile.phone_number)
            oncall2 = "%s,  Phone Number:%s" % (
                currently_oncall_users[1].username,
                currently_oncall_users[1].profile.phone_number)
        else:
            oncall1 = "Nobody"
            oncall2 = "Nobody"

        if 'django_timezone' in request.session:
            local_timezone = pytz.timezone(request.session['django_timezone'])
        else:
            local_timezone = timezone.get_default_timezone()
        period_objects = {}
        for period in periods:
            if period.__name__.lower() == 'year':
                period_objects[period.__name__.lower()] = period(
                    event_list, date, None, local_timezone)
            else:
                period_objects[period.__name__.lower()] = period(
                    event_list, date, None, None, local_timezone)
        return render_to_response(
            'schedule/detail.html',
            {
                'date': date,
                'periods': period_objects,
                'calendar': sched,
                'weekday_names': weekday_names,
                'currently_oncall_1': oncall1,
                'currently_oncall_2': oncall2,
                'local_timezone': local_timezone,
                'current_date': timezone.now(),
                'here': quote(request.get_full_path()),
            },
            context_instance=RequestContext(request),
        )
    except Calendar.DoesNotExist:
        raise Http404
示例#2
0
文件: schedules.py 项目: 40a/openduty
def details(request, calendar_slug,  periods=None):
    try:
        sched = get_object_or_404(Calendar, slug=calendar_slug)
        date = coerce_date_dict(request.GET)
        if date:
            try:
                date = datetime(**date)
            except ValueError:
                raise Http404
        else:
            date = timezone.now()
        event_list = sched.event_set.all()
        currently_oncall_users = escalation_helper.get_current_events_users(sched)
        if len(currently_oncall_users) >= 2:
            oncall1 = "%s, Phone Number:%s" % (currently_oncall_users[0].username,
                                               currently_oncall_users[0].profile.phone_number)
            oncall2 = "%s,  Phone Number:%s" % (currently_oncall_users[1].username,
                                               currently_oncall_users[1].profile.phone_number)
        else:
            oncall1 = "Nobody"
            oncall2 = "Nobody"

        if 'django_timezone' in request.session:
            local_timezone = pytz.timezone(request.session['django_timezone'])
        else:
            local_timezone = timezone.get_default_timezone()
        period_objects = {}
        for period in periods:
            if period.__name__.lower() == 'year':
                period_objects[period.__name__.lower()] = period(event_list, date, None, local_timezone)
            else:
                period_objects[period.__name__.lower()] = period(event_list, date, None, None, local_timezone)
        return render_to_response('schedule/detail.html',
         {
            'date': date,
            'periods': period_objects,
            'calendar': sched,
            'weekday_names': weekday_names,
            'currently_oncall_1' : oncall1,
            'currently_oncall_2' : oncall2,
            'local_timezone': local_timezone,
            'current_date': timezone.now(),

            'here':quote(request.get_full_path()),
        },context_instance=RequestContext(request),
                                  )
    except Calendar.DoesNotExist:
        raise Http404
示例#3
0
def details(request, id, periods=None):
    try:
        sched = Calendar.objects.get(id=id)
        date = coerce_date_dict(request.GET)
        if date:
            try:
                date = datetime(**date)
            except ValueError:
                raise Http404
        else:
            date = timezone.now()
        event_list = sched.event_set.all()
        currently_oncall_users = escalation_helper.get_current_events_users(
            sched)
        if len(currently_oncall_users) >= 2:
            oncall1 = "%s, Phone Number:%s" % (
                currently_oncall_users[0].username,
                currently_oncall_users[0].profile.phone_number)
            oncall2 = "%s,  Phone Number:%s" % (
                currently_oncall_users[1].username,
                currently_oncall_users[1].profile.phone_number)
        else:
            oncall1 = "Nobody"
            oncall2 = "Nobody"
        period_objects = dict([(period.__name__.lower(),
                                period(event_list, date))
                               for period in periods])
        return render_to_response(
            'schedule/detail.html',
            {
                'date': date,
                'periods': period_objects,
                'calendar': sched,
                'weekday_names': weekday_names,
                'currently_oncall_1': oncall1,
                'currently_oncall_2': oncall2,
                'here': quote(request.get_full_path()),
            },
            context_instance=RequestContext(request),
        )
    except Calendar.DoesNotExist:
        raise Http404
示例#4
0
def details(request, id,  periods=None):
    try:
        sched = Calendar.objects.get(id = id)
        date = coerce_date_dict(request.GET)
        if date:
            try:
                date = datetime(**date)
            except ValueError:
                raise Http404
        else:
            date = timezone.now()
        event_list = sched.event_set.all()
        currently_oncall_users = escalation_helper.get_current_events_users(sched)
        if len(currently_oncall_users) >= 2:
            oncall1 = "%s, Phone Number:%s" % (currently_oncall_users[0].username,
                                               currently_oncall_users[0].profile.phone_number)
            oncall2 = "%s,  Phone Number:%s" % (currently_oncall_users[1].username,
                                               currently_oncall_users[1].profile.phone_number)
        else:
            oncall1 = "Nobody"
            oncall2 = "Nobody"
        period_objects = dict([(period.__name__.lower(), period(event_list, date)) for period in periods])
        return render_to_response('schedule/detail.html',
         {
            'date': date,
            'periods': period_objects,
            'calendar': sched,
            'weekday_names': weekday_names,
            'currently_oncall_1' : oncall1,
            'currently_oncall_2' : oncall2,

            'here':quote(request.get_full_path()),
        },context_instance=RequestContext(request),
                                  )
    except Calendar.DoesNotExist:
        raise Http404