コード例 #1
0
def getMemberVotesAssemble(icpsr=0, qtext="", skip=0):
    icpsr = defaultValue(bottle.request.params.icpsr, 0)
    qtext = defaultValue(bottle.request.params.qtext, "")
    skip = defaultValue(bottle.request.params.skip, 0)

    if not icpsr:
        output = bottle.template("views/error",
                                 errorMessage="No member specified.")
        bottle.response.headers["nextId"] = 0
        return (output)

    person = memberLookup({"icpsr": icpsr})
    if not "error" in person:
        person = person["results"][0]
    else:
        output = bottle.template("views/error",
                                 errorMessage=person["errormessage"])
        bottle.response.headers["nextId"] = 0
        return (output)

    votes = []

    if qtext:
        qtext = qtext + " AND (voter: " + str(person["icpsr"]) + ")"
    else:
        qtext = "voter: " + str(person["icpsr"])

    if skip:
        voteQuery = query(qtext,
                          rowLimit=25,
                          jsapi=1,
                          sortSkip=skip,
                          request=bottle.request)
    else:
        voteQuery = query(qtext, rowLimit=25, jsapi=1, request=bottle.request)

    # Outsourced the vote assembly to a model for future API buildout.
    votes = prepVotes(voteQuery, person)
    output = bottle.template("views/member_votes",
                             person=person,
                             votes=votes,
                             skip=skip,
                             nextId=voteQuery["nextId"])

    bottle.response.headers["nextId"] = voteQuery["nextId"]
    return (output)
コード例 #2
0
ファイル: app.py プロジェクト: JeffreyBLewis/WebVoteView
def getMemberVotesAssemble(icpsr=0, qtext="", skip=0):
    icpsr = defaultValue(bottle.request.params.icpsr, 0)
    qtext = defaultValue(bottle.request.params.qtext, "")
    skip = defaultValue(bottle.request.params.skip, 0)

    if not icpsr:
        output = bottle.template(
            "views/error", errorMessage="No member specified.")
        bottle.response.headers["nextId"] = 0
        return(output)

    person = memberLookup({"icpsr": icpsr})
    if not "error" in person:
        person = person["results"][0]
    else:
        output = bottle.template(
            "views/error", errorMessage=person["errormessage"])
        bottle.response.headers["nextId"] = 0
        return(output)

    votes = []

    if qtext:
        qtext = qtext + " AND (voter: " + str(person["icpsr"]) + ")"
    else:
        qtext = "voter: " + str(person["icpsr"])

    if skip:
        voteQuery = query(qtext, rowLimit=25, jsapi=1,
                          sortSkip=skip, request=bottle.request)
    else:
        voteQuery = query(qtext, rowLimit=25, jsapi=1, request=bottle.request)

    # Outsourced the vote assembly to a model for future API buildout.
    votes = prepVotes(voteQuery, person)
    output = bottle.template("views/member_votes", person=person,
                             votes=votes, skip=skip, nextId=voteQuery["nextId"])

    bottle.response.headers["nextId"] = voteQuery["nextId"]
    return(output)
コード例 #3
0
def person(icpsr=0):
    clearTime()
    timeIt("begin")
    if not icpsr:
        icpsr = defaultValue(bottle.request.params.icpsr,0)

    skip = 0

    # Easter Egg
    keith = defaultValue(bottle.request.params.keith, 0)

    # Pull by ICPSR
    person = memberLookup({"icpsr": icpsr}, 1)
    timeIt("memberLookup")

    # If we have no error, follow through
    if not "errormessage" in person:
        person = person["results"][0]
	if not "bioname" in person:
		person["bioname"] = "ERROR NO NAME IN DATABASE PLEASE FIX."
        votes = []
        # Look up votes

        timeIt("nameFunc")

        # Check if bio image exists
        bioFound = 0
        if not os.path.isfile("static/img/bios/"+str(person["icpsr"]).zfill(6)+".jpg"):
            # If not, use the default silhouette
            if not keith:
                person["bioImg"] = "silhouette.png"
            else:
                person["bioImg"] = "keith.png"
        else:
            person["bioImg"] = str(person["icpsr"]).zfill(6)+".jpg"
            bioFound = 1

        timeIt("bioImg")

        # Get years of service
        person["yearsOfService"] = yearsOfService(person["icpsr"],"")
	person["yearsOfServiceSenate"] = yearsOfService(person["icpsr"],"Senate")
	person["yearsOfServiceHouse"] = yearsOfService(person["icpsr"],"House")
        person["congressesOfService"] = congressesOfService(person["icpsr"],"")
        person["congressLabels"] = {}
        for congressChunk in person["congressesOfService"]:
            for cong in range(congressChunk[0], congressChunk[1]+1):
                person["congressLabels"][cong] = str(cong)+"th Congress ("+str(congressToYear(cong,0))+"-"+str(congressToYear(cong,1))+")"

        timeIt("congressLabels")

        # Find out if we have any other ICPSRs that are this person for another party
        altICPSRs = checkForPartySwitch(person)
        if "results" in altICPSRs:
            person["altPeople"] = []
            # Iterate through them
            for alt in altICPSRs["results"]:
                # Look up this one
                altPerson = memberLookup({"icpsr": alt}, 1)["results"][0]
                if not "errormessage" in altPerson:
                    # Get their years of service
                    altPerson["yearsOfService"] = yearsOfService(altPerson["icpsr"])
                    # If we don't have a bio image for main guy, borrow from his previous/subsequent incarnations
                    if not bioFound and os.path.isfile("static/img/bios/"+str(altPerson["icpsr"]).zfill(6)+".jpg"):
                        person["bioImg"] = str(altPerson["icpsr"]).zfill(6)+".jpg"
                        bioFound = 1
                    person["altPeople"].append(altPerson)


        timeIt("partySwitches")
        voteQuery = query(qtext="voter: "+str(person["icpsr"]), rowLimit=25, jsapi=1)
        timeIt("gotVotes")

	votes = prepVotes(voteQuery, person) # Outsourced the vote assembly to a model for future API buildout.

        if "biography" in person:
            person["biography"] = person["biography"].replace("a Representative","Representative")

        timeIt("readyOut")
        # Go to the template.
        output = bottle.template("views/person",person=person, votes=votes, timeSet=zipTimes(), skip=0, nextId=voteQuery["nextId"], voteQuery=voteQuery)
        return(output)

    # If we have an error, return an error page
    else:
        output = bottle.template("views/error", errorMessage=person["errormessage"])
        return(output)