Пример #1
0
def profile(request, *args, **kws):
    """
    Shows a user-centric page chock-full of interesting tidbits.
    """
    requestor = get_requestor(request)
    requestor.checkAuthUser()
    user = User.objects.get(id = args[0]) if args else requestor
    static_info  = user.getStaticContactInfo()
    reservations = user.getReservations()

    try:
        tz = requestor.preference.timeZone
    except ObjectDoesNotExist:
        tz = "UTC"

    blackouts = \
        sorted([{'user'        : user
                 , 'id'          : b.id
                 , 'start_date'  : adjustDateTimeTz(tz, b.getStartDate())
                 , 'end_date'    : adjustDateTimeTz(tz, b.getEndDate())
                 , 'repeat'      : b.getRepeat()
                 , 'until'       : adjustDateTimeTz(tz, b.getUntil())
                 , 'description' : b.getDescription()
                 } for b in user.blackout_set.all() if b.isActive()],
               key = lambda  bl: bl['start_date'])



    upcomingPeriods = [(proj
                       , [{'session'  : pd.session
                         , 'start'    : adjustDateTimeTz(tz, pd.start)
                         , 'duration' : pd.duration
                          } for pd in pds]
                         ) for proj, pds in user.getUpcomingPeriodsByProject().items()]
    return render_to_response("users/profile.html"
                            , {'u'            : user
                             , 'blackouts'    : blackouts
                             , 'requestor'    : requestor
                             , 'authorized'   : user == requestor
                             , 'tz'           : tz
                             , 'emails'       : static_info['emailDescs']
                             , 'phones'       : static_info['phoneDescs']
                             , 'postals'      : static_info['postals']
                             , 'affiliations' : static_info['affiliations']
                             , 'username'     : static_info['username']
                             , 'reservations' : reservations
                             , 'upcomingPeriods' : upcomingPeriods
                             , 'tzs'             : pytz.common_timezones
                             , 'isOps'           : requestor.isOperator()})
Пример #2
0
def project(request, *args, **kws):
    """
    Shows a project-centric page chock-full of interesting tidbits.
    """
    requestor = get_requestor(request)
    try:
       tz = requestor.preference.timeZone
    except ObjectDoesNotExist:
        tz = "UTC"

    project   = get_object_or_404(Project, pcode = args[0])

    now          = datetime.utcnow().replace(hour = 0, minute = 0, second = 0)
    later        = now + timedelta(days = 180)
    rcvr_blkouts = []
    for s, e in project.get_receiver_blackout_ranges(now, later):
        if e is None:
            rcvr_blkouts.append((s.date(), None))
        else:
            rcvr_blkouts.append((s.date(), e.date()))

    # sort all the sessions by name
    sess = sorted(project.sesshun_set.all(), lambda x,y: cmp(x.name, y.name))

    # what are the user blackouts we need to display?
    investigators = project.investigator_set.order_by('priority').all()
    obsBlackouts      = [adjustBlackoutTZ(tz, b) for i in investigators for b in i.projectBlackouts()]
    reqFriendBlackouts = [adjustBlackoutTZ(tz, b) for f in project.friend_set.all() for b in f.projectBlackouts() if f.required ]

    # prevent duplicates when adding required friend's blackouts:
    for ob in reqFriendBlackouts:
        if ob not in obsBlackouts:
            obsBlackouts.append(ob)

    # and the project blackouts?
    projBlackouts     = [adjustBlackoutTZ(tz, b) for b in project.blackout_set.all() if b.isActive()]

    periods = [{'session'    : p.session
              , 'start'      : adjustDateTimeTz(tz, p.start)
              , 'duration'   : p.duration
              , 'accounting' : p.accounting
               } for p in project.get_observed_periods()]
    windows = [{'session'   : w.session
              , 'start_date' : w.start_date()
              , 'duration'   : w.duration()
              , 'last_date'  : w.last_date()
              , 'total_time'  : w.total_time
              , 'time_billed' : w.timeBilled()
              , 'complete'    : w.complete
              , 'contigious'  : w.isContigious()
              , 'ranges'      : [{'start' : wr.start_date
                                , 'duration' : wr.duration
                                , 'end' : wr.last_date()} \
                                for wr in w.ranges()]
              , 'periods'     : [{'start' : adjustDateTimeTz(tz, p.start)
                                , 'duration' : p.duration
                                , 'time_billed' : p.accounting.time_billed()} \
                                    for p in w.scheduledPeriods()]
               } for w in project.get_active_windows()]
    upcomingPeriods = [{'session'  : pd.session
                      , 'start'    : adjustDateTimeTz(tz, pd.start)
                      , 'duration' : pd.duration
                       } for pd in project.getUpcomingPeriods()]
    electivePeriods = [ {'elective' : e
                       , 'periods' : [{'start' : adjustDateTimeTz(tz, p.start)
                                     , 'duration' : p.duration
                                     , 'scheduled' : "Yes" if p.isScheduled() else ""
                                     , 'time_billed' : p.accounting.time_billed()} \
                                    for p in e.periodsOrderByDate()]
                        } for e in project.getActiveElectives()]
    res = project.getUpcomingReservations()
    return render_to_response(
        "users/project.html"
      , {'p'                 : project
       , 'sess'              : sess
       , 'u'                 : requestor
       , 'requestor'         : requestor
       , 'v'                 : investigators
       , 'r'                 : res
       , 'rcvr_blkouts'      : rcvr_blkouts
       , 'tz'                : tz
       , 'observerBlackouts' : obsBlackouts
       , 'projectBlackouts'  : projBlackouts
       , 'periods'           : periods
       , 'windows'           : windows
       , 'upcomingPeriods'   : upcomingPeriods
       , 'electivePeriods'   : electivePeriods
       , 'tzs'               : pytz.common_timezones
       }
    )