Пример #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
Пример #3
0
def index(req):
    #user = utility.getUser(req)
    httpvar = httpvars(req)
    classType = utility.getClass(httpvar)
    first = utility.getDate(httpvar)
    next = utility.getNextMonth(first)
    
    dbconn = dataconnect()
    className = dbconn.getClassName(classType)
    available = dbconn.getAvailable(first, next, classType)
    status = dbconn.getReportable(classType)
    del dbconn
    
    s = utility.buildTemplate() #%(title)s %(htmlbody)s are the bits to be filled in
    title = "%(monthName)s %(year)s %(className)s Availability Summary" % {'monthName': month_name[first.month], 'year': first.year, 'className': className }
    body = """\
<h2>%(title)s</h2>
<h4><a href="./?class=%(class)s&month=%(month)s&year=%(year)s">Fill Out Personal Availability For The Month</a></h4>
%(navigation)s
<table border=1>
%(rows)s
</table>
""" 
    rows = """\
    <tr>
        <th>Date</th>
"""
    for k, v in status.iteritems():
        rows += """\
        <th>%(v)s</th>
""" % {'v': v }
    rows += """\
    </tr>
"""     

    for i in range(first.toordinal(), next.toordinal()):
        d = date.fromordinal(i)
        row = """\
    <tr>
        <td>%(date)s</td>
""" % {'date': d.strftime("%A, %B %d") }
        for k, v in status.iteritems():
            row += """\
        <td>%(val)s</td>
"""
            val = '&nbsp;'
            if available.has_key(i):
                if available[i].has_key(k):
                    val = utility.expandUsernames(available[i][k], d.strftime("%A, %B %d"))
            row = row % {'val': val }
        row += """\
    </tr>
"""
        rows += row         
        
        

    body = body % {'title': title, 'navigation': utility.getNavigation(first, './summary', classType), 'month': first.month, 'year': first.year, 'class': classType, 'rows': rows }
    s = s % {'title': title, 'htmlbody': body }
    
    return s
Пример #4
0
def index(req):
    user = utility.getUser(req)
    
    httpvar = httpvars(req)
    classType = utility.getClass(httpvar)
    first = utility.getDate(httpvar)
    next = utility.getNextMonth(first)
    
    
    dbconn = dataconnect()
    className = dbconn.getClassName(classType)
    status = dbconn.getSelectable(classType)
    userInfo = dbconn.getUser(user)
    if userInfo != None:
        availability = dbconn.getAvailability(userInfo.id, first, next, classType)
    hosts = dbconn.getHosts(first, next)
    unavailable = dbconn.getUnavailableStatus(classType)
    del dbconn
    
    s = utility.buildTemplate() #%(title)s %(htmlbody)s are the bits to be filled in
    title = "%(monthName)s %(year)s %(className)s Availability" % {'monthName': month_name[first.month], 'year': first.year, 'className': className }
    body = """\
<h2>%(title)s</h2>
"""
    if classType == 1:
        body = body + """\
<h4><font color="#800000">Please consider signing up for Sunday.  This is the nicest day for candidates since they are able to fly in on Sunday, interview on Monday morning, and fly back Monday evening while only missing one day of the work week.  It's not ideal for hosts, but please help if you can to distribute the load.</font></h4>"""
    body = body + """\
<h4><a href="./summary?class=%(class)s&month=%(month)s&year=%(year)s">All Host Summary Report For The Month</a></h4>
%(navigation)s
%(form)s
"""
    form = ""
    if userInfo == None:
        form = "<h3>User not in approved user database. Contact administrator for assistance.</h3>"
    else:
        form = """\
<form action="./update" method="post">
    <table border=1>
        <tr>
            <th>Date</th>
            <th colspan=%(numChoices)s>Availability</th>
        </tr>
%(tableData)s
    </table>
    <br />
    <input type="hidden" name="month" value="%(month)s" />
    <input type="hidden" name="year" value="%(year)s" />
    <input type="hidden" name="class" value="%(class)s" />
    <input type="submit" value="Update Availability" />
</form>
"""
        tableData = ''
        for i in range(first.toordinal(), next.toordinal()):
            d = date.fromordinal(i)
            readOnly = utility.isDateReadOnly(d, hosts, classType)
            disabled = ''
            if readOnly:
                disabled = 'disabled="disabled" '
            choice = unavailable #set default to be unavailable
            if availability.has_key(i):
                choice = availability[i]
            
            tableData = tableData + """\
        <tr>
            <td>%(date)s</td>
%(choices)s
        </tr>
"""
            choices = ''
            for k, v in status.iteritems():
                checked=''
                if k == choice:
                    checked='checked="checked" '
                choices = choices + """\
                <td><input type="radio" name="availability[%(index)s]" value="%(value)s" %(checked)s%(readOnly)s/>%(title)s</td>
    """ % {'index': i, 'readOnly': disabled, 'value': k, 'title': v, 'checked': checked }
            
            tableData = tableData % {'date': d.strftime("%A, %B %d"), 'choices': choices }
        form = form % {'month': first.month, 'year': first.year, 'class': classType, 'numChoices': len(status), 'tableData': tableData }
    
    body = body % {'form': form, 'title': title, 'month': first.month, 'year': first.year, 'class': classType, 'navigation': utility.getNavigation(first, './', classType) }
    s = s % {'title': title, 'htmlbody': body }
    
    return s