示例#1
0
def index(req):
    user = utility.getUser(req)

    httpvar = httpvars(req)
    first = utility.getDate(httpvar)
    next = utility.getNextMonth(first)
    
    util.redirect(req, "./")
    
    dbconn = dataconnect()
    userInfo = dbconn.getUser(user)
    if userInfo == None or not userInfo.isadmin:
        del dbconn
        util.redirect(req, "./")
        return
    available = dbconn.getAvailable(first, next)
    index = _buildIndex(available)
    hosts = dbconn.getHosts(first, next)
    counts = {} #TODO: need to update counts with already assigned from month - this information is in available
    assign = {}
    
    for numHosts in index:
        days = index[numHosts]
        for i in days:
            d = date.fromordinal(i)
            hostsNeeded = utility.getNumHostsNeeded(d, hosts)
            if hostsNeeded == 0: #don't assign people for days not needed
                continue
            least = []
            for status, users in available[i].iteritems():
                scalar = 0
                if status == 2:
                    scalar = 2
                for user in users:
                    numDinners = 0
                    if counts.has_key(user.id):
                        numDinners = counts[user.id]
                    numDinners += scalar #add fudge factor to balance things out
                    least.append((numDinners, user.id))
            least.sort()
            #for user in least[:hostsNeeded]:
            userCounter = 0
            while (hostsNeeded > 0 and userCounter < len(least)):
                userTuple = least[userCounter]
                userCounter += 1
                #counts = _assignHost(counts, i, userTuple[1]
                if dbconn.assignHost(userTuple[1], d):
                    hostsNeeded -= 1
                    if not counts.has_key(userTuple[1]):
                        counts[userTuple[1]] = 0
                    counts[userTuple[1]] += 1
                    if not assign.has_key(i):
                        assign[i] = []
                    assign[i].append(userTuple[1])
    
    del dbconn
    page = './summary?month=%(month)s&year=%(year)s' % {'month': first.month, 'year': first.year }
    util.redirect(req, page)
示例#2
0
def index(req):
    user = utility.getUser(req)
    httpvar = httpvars(req)
    first = utility.getDate(httpvar)
    next = utility.getNextMonth(first)
    
    util.redirect(req, "./")
    
    dbconn = dataconnect()
    userInfo = dbconn.getUser(user)
    if userInfo == None or not userInfo.isadmin:
        del dbconn
        util.redirect(req, "./")
        return
    hosts = dbconn.getHosts(first, next)
    #TODO: find the number of hosts required per date
    del dbconn
    
    s = utility.buildTemplate() #%(title)s %(htmlbody)s are the bits to be filled in
    title = "%(monthName)s %(year)s Host Requirements Per Day" % {'monthName': month_name[first.month], 'year': first.year }
    body = """\
<h2>%(title)s</h2>
%(navigation)s
<table border=1>
%(rows)s
</table>
""" 
    rows = """\
    <tr>
        <th>Date</th>
        <th>Number of Hosts Required</th>
"""    

    for i in range(first.toordinal(), next.toordinal()):
        d = date.fromordinal(i)
        hostsNeeded = utility.getNumHostsNeeded(d, hosts)
        row = """\
    <tr>
        <td>%(date)s</td>
        <td>%(hosts)s</td>
    </tr>
""" % {'date': d.strftime("%A, %B %d"), 'hosts': hostsNeeded }

        rows += row         
        
        

    body = body % {'title': title, 'navigation': utility.getNavigation(first, './admin'), 'month': first.month, 'year': first.year, 'rows': rows }
    s = s % {'title': title, 'htmlbody': body }
    
    return s