示例#1
0
文件: views.py 项目: jjcoggin/CoUS
def pre_populate(request):
    if request.method == 'POST':
        IP_ADDR = request.META['REMOTE_ADDR']
        d = xml_parser(IP_ADDR)
        if d is None:
            return HttpResponseNotFound()
        else:
            for key, val in d.iteritems():
                print key, " : ", val

        pop_race = [["American Indian", d["IndianPopulation"]],
                    ["Asian or Pacific Islander", d["AsianPopulation"]],
                    ["Black", d["BlackPopulation"]],
                    ["Hispanic (of any race)", d["HispanicPopulation"]],
                    ["Non-Hispanic White", d["WhitePopulation"]]]
        pop_race = sorted(pop_race, cmp_by_last)
        print pop_race
        pop_gender = [["Male", d["MalePopulation"]],
                      ["Female", d["FemalePopulation"]]]
        pop_gender = sorted(pop_gender, cmp_by_last)
        pop_edu = [["Less than High School", 0],
                   [
                       "High School Graduate/Some College/Associate's Degree",
                       d["EducationHighSchoolGraduate"]
                   ],
                   [
                       "Bachelor's Degree or More",
                       d["EducationBachelorOrGreater"]
                   ]]
        pop_edu = sorted(pop_edu, cmp_by_last)

        state = d["State"]
        yourrace = pop_race[0][0]
        itsrace = pop_race[1][0]
        yourstate = state
        itsstate = state
        youredu = pop_edu[0][0]
        itsedu = pop_edu[1][0]
        yourgender = pop_gender[0][0]
        itsgender = pop_gender[1][0]
        yourfocus = "1-1 Persons with health insurance"

        bars = retrieve_bars(yourstate, yourrace, yourgender, youredu,
                             itsstate, itsrace, itsgender, itsedu)
        subfocuses = retrieve_subfocuses(yourrace, yourfocus)
        yourtopic = bars[0][0]
        postopics, negtopics = retrieve_corrtable(yourtopic, '')

        youform_data = [
            yourstate, yourrace, yourgender, youredu, itsstate, itsrace,
            itsgender, itsedu, yourtopic, yourfocus
        ]
        print "form", youform_data

        jsonSerializer = JSONSerializer()
        data = jsonSerializer.serialize(
            [bars, subfocuses, postopics, negtopics, youform_data])
        return HttpResponse(data, mimetype="application/json")
        #return HttpResponse('T')
    return HttpResponse('Incorrect Http Method.')
示例#2
0
文件: views.py 项目: jjcoggin/CoUS
def ajax_handler(request):
    if request.method == 'POST':
        subfocuslist = Item.objects.values('subtopic').distinct()
        statelist = Item.objects.values('state').distinct()
        racelist = Item.objects.values('attr').distinct()

        print request.POST

        yourgender = request.POST['yourgender']
        youredu = request.POST['youredu']
        itsgender = request.POST['itsgender']
        itsedu = request.POST['itsedu']
        yourstate = request.POST['yourstate']
        yourrace = request.POST['yourrace']
        itsstate = request.POST['itsstate']
        itsrace = request.POST['itsrace']
        yourfocus = request.POST['yourfocus']
        yourtopic = request.POST['yourtopic']

        bars = retrieve_bars(yourstate, yourrace, yourgender, youredu,
                             itsstate, itsrace, itsgender, itsedu)
        subfocuses = retrieve_subfocuses(yourrace, yourfocus)
        print "posp"
        postopics, negtopics = retrieve_corrtable(yourtopic, '')
        logos = retrieve_company(yourtopic)

        print "pos", postopics

        jsonSerializer = JSONSerializer()
        data = jsonSerializer.serialize(
            [bars, subfocuses, postopics, negtopics, logos])
        return HttpResponse(data, mimetype="application/json")
    return HttpResponse('Incorrect Http Method.')
示例#3
0
文件: views.py 项目: jjcoggin/CoUS
def ajax_handler(request):
    if request.method == 'POST':
        subfocuslist = Item.objects.values('subtopic').distinct() 
        statelist = Item.objects.values('state').distinct() 
        racelist = Item.objects.values('attr').distinct()

        print request.POST

        yourgender = request.POST['yourgender']
        youredu = request.POST['youredu']
        itsgender = request.POST['itsgender']
        itsedu = request.POST['itsedu']
        yourstate = request.POST['yourstate']
        yourrace = request.POST['yourrace']
        itsstate = request.POST['itsstate']
        itsrace = request.POST['itsrace']
        yourfocus = request.POST['yourfocus']
        yourtopic = request.POST['yourtopic']


        bars = retrieve_bars(yourstate,yourrace,yourgender,youredu,itsstate,itsrace,itsgender,itsedu)
        subfocuses = retrieve_subfocuses(yourrace,yourfocus)
        print "posp"
        postopics,negtopics = retrieve_corrtable(yourtopic,'')
        logos = retrieve_company(yourtopic)

        print "pos", postopics

        jsonSerializer = JSONSerializer()
        data = jsonSerializer.serialize([bars, subfocuses, postopics, negtopics,logos])
        return HttpResponse(data, mimetype="application/json")
    return HttpResponse('Incorrect Http Method.')
示例#4
0
文件: views.py 项目: jjcoggin/CoUS
def pre_populate(request):
    if request.method == 'POST':
        IP_ADDR = request.META['REMOTE_ADDR']
        d = xml_parser(IP_ADDR)
        if d is None:
            return HttpResponseNotFound()
        else:
            for key, val in d.iteritems():
                print key, " : ", val


        pop_race = [["American Indian",d["IndianPopulation"]],["Asian or Pacific Islander",d["AsianPopulation"]],["Black",d["BlackPopulation"]],["Hispanic (of any race)",d["HispanicPopulation"]],["Non-Hispanic White",d["WhitePopulation"]]]
        pop_race = sorted(pop_race,cmp_by_last)
        print pop_race
        pop_gender = [["Male",d["MalePopulation"]],["Female",d["FemalePopulation"]]]
        pop_gender = sorted(pop_gender,cmp_by_last)
        pop_edu = [["Less than High School",0],["High School Graduate/Some College/Associate's Degree",d["EducationHighSchoolGraduate"]],["Bachelor's Degree or More",d["EducationBachelorOrGreater"]]]
        pop_edu = sorted(pop_edu,cmp_by_last)

        state = d["State"] 
        yourrace = pop_race[0][0]
        itsrace = pop_race[1][0]
        yourstate = state
        itsstate = state
        youredu = pop_edu[0][0]
        itsedu = pop_edu[1][0]
        yourgender = pop_gender[0][0]
        itsgender = pop_gender[1][0]
        yourfocus = "1-1 Persons with health insurance"
        

        bars = retrieve_bars(yourstate,yourrace,yourgender,youredu,itsstate,itsrace,itsgender,itsedu)
        subfocuses = retrieve_subfocuses(yourrace,yourfocus)
        yourtopic = bars[0][0]
        postopics,negtopics = retrieve_corrtable(yourtopic,'')

        youform_data = [yourstate,yourrace,yourgender,youredu,itsstate,itsrace,itsgender,itsedu,yourtopic,yourfocus]
        print "form",youform_data

        jsonSerializer = JSONSerializer()
        data = jsonSerializer.serialize([bars, subfocuses, postopics, negtopics,youform_data])
        return HttpResponse(data, mimetype="application/json")
        #return HttpResponse('T')
    return HttpResponse('Incorrect Http Method.')