Example #1
0
def return_county_data(request,county_code,countyname,state,lat,lng,address):
    ranking_info = datamodel.get_ranking_info_by_county(county_code)
    pws_info = datamodel.get_pws_details_by_county(lat, lng, county_code)
    repId = datamodel.get_rep_details(lat, lng)
    map_data = datamodel.get_pws_details_for_map(county_code)
    scorecard_data = datamodel.get_county_scorecard_data(county_code)
    top_contaminants = datamodel.get_county_top_contaminants(county_code)
    #print top_contaminants 
    repeat_contaminants = datamodel.get_county_repeat_contaminants(county_code)
    #print repeat_contaminants
    # Google api for URL shortener
    post_url = 'https://www.googleapis.com/urlshortener/v1/url'
    if(address != ''):
        url = "http://www.h2osafe.us/results?address="+address
    else:
        url = "http://www.h2osafe.us/"+countyname+"/"+state+"/violations"
    postdata = {'longUrl':url}
    headers = {'Content-Type':'application/json'}
    req = urllib2.Request(post_url,json.dumps(postdata),headers)
    ret = urllib2.urlopen(req).read()
    short_url=json.loads(ret)['id']
    
    #   #Get Template
    #   emailTemplate     = get_template('email.html')
    #   data = Context({ 'pws_info': pws_info })
    #   emailContent = emailTemplate.render(data)
    twtButton = "Contact Rep"
    twtMessage = "Water safety violations for address"
    rating_button = "green-button"
    if ranking_info['bucket'] == "G":
        rating_type = "green-rating"
        twtButton = "Thank Your Rep"
        twtMessage = "Thank You for water safety @"
    elif ranking_info['bucket'] == "Y":
        rating_type = "yellow-rating"
    else: 
        rating_type = "red-rating"
    
    return render_to_response('results.html', {
        'county_id': county_code, 
        'county_name' :countyname,
        'state' : state,
        'address': address,
        'incident_count': ranking_info['incident_count'],
        'bucket': ranking_info['bucket'],
        'rank': ranking_info['rank'],
        'rating_type': rating_type,
        'rating_button': rating_button,
        'pws_info': pws_info,
        'req_address':address,
        'rep_twitter_id':repId,
        'twtButton':twtButton,
        'twtMessage':twtMessage,
        'short_url':short_url,
        'map_data':map_data,
        'scorecard_data':scorecard_data[0],
        'top_contaminant':top_contaminants,
        'repeat_contaminant':repeat_contaminants
    }, context_instance=RequestContext(request))
    
Example #2
0
def return_county_data(request,county_code,countyname,state,lat,lng,address):
    ranking_info = datamodel.get_ranking_info_by_county(county_code)
    pws_info = datamodel.get_pws_details_by_county(lat, lng, county_code)
    repId = datamodel.get_rep_details(lat, lng)
    map_data = datamodel.get_pws_details_for_map(county_code)
    scorecard_data = datamodel.get_county_scorecard_data(county_code)
    top_contaminants = datamodel.get_county_top_contaminants(county_code)
    #print top_contaminants 
    repeat_contaminants = datamodel.get_county_repeat_contaminants(county_code)
    #print repeat_contaminants
    # Google api for URL shortener
    post_url = 'https://www.googleapis.com/urlshortener/v1/url'
    if(address != ''):
        url = "http://www.h2osafe.us/results?address="+address
    else:
        url = "http://www.h2osafe.us/"+countyname+"/"+state+"/violations"
    postdata = {'longUrl':url}
    headers = {'Content-Type':'application/json'}
    req = urllib2.Request(post_url,json.dumps(postdata),headers)
    ret = urllib2.urlopen(req).read()
    short_url=json.loads(ret)['id']
    
    #   #Get Template
    #   emailTemplate     = get_template('email.html')
    #   data = Context({ 'pws_info': pws_info })
    #   emailContent = emailTemplate.render(data)
    twtButton = "Contact Rep"
    twtMessage = "Water safety violations for address"
    rating_button = "green-button"
    if ranking_info['bucket'] == "G":
        rating_type = "green-rating"
        twtButton = "Thank Your Rep"
        twtMessage = "Thank You for water safety @"
    elif ranking_info['bucket'] == "Y":
        rating_type = "yellow-rating"
    else: 
        rating_type = "red-rating"
    
    return render_to_response('results.html', {
        'county_id': county_code, 
        'county_name' :countyname,
        'state' : state,
        'address': address,
        'incident_count': ranking_info['incident_count'],
        'bucket': ranking_info['bucket'],
        'rank': ranking_info['rank'],
        'rating_type': rating_type,
        'rating_button': rating_button,
        'pws_info': pws_info,
        'req_address':address,
        'rep_twitter_id':repId,
        'twtButton':twtButton,
        'twtMessage':twtMessage,
        'short_url':short_url,
        'map_data':map_data,
        'scorecard_data':scorecard_data[0],
        'top_contaminant':top_contaminants,
        'repeat_contaminant':repeat_contaminants
    }, context_instance=RequestContext(request))
    
Example #3
0
def SendEmail(request):
    subject, from_email = 'Violation Message', '*****@*****.**'
    to = ['*****@*****.**']
    address = ''
    
    if 'reqAddress' in request.POST:
        address = request.POST['reqAddress']
    if 'emailText' in request.POST:
        userEmail = request.POST['emailText']
        to.append(userEmail)
        
    county_code = datamodel.get_county_code_by_address(address)
    pws_info = datamodel.get_pws_details_by_county(county_code)
  
    #Get Template
    emailTemplate     = get_template('email.html')
    data = Context({ 'pws_info': pws_info })
    emailContent = emailTemplate.render(data)
    
    msg = EmailMultiAlternatives(subject, 'Sample', from_email, to)
    msg.attach_alternative(emailContent, "text/html")
    msg.send()
    return HttpResponse(str(0), content_type="text/plain")
Example #4
0
def SendEmail(request):
    subject, from_email = 'Violation Message', '*****@*****.**'
    to = ['*****@*****.**']
    address = ''
    
    if 'reqAddress' in request.POST:
        address = request.POST['reqAddress']
    if 'emailText' in request.POST:
        userEmail = request.POST['emailText']
        to.append(userEmail)
        
    county_code = datamodel.get_county_code_by_address(address)
    pws_info = datamodel.get_pws_details_by_county(county_code)
  
    #Get Template
    emailTemplate     = get_template('email.html')
    data = Context({ 'pws_info': pws_info })
    emailContent = emailTemplate.render(data)
    
    msg = EmailMultiAlternatives(subject, 'Sample', from_email, to)
    msg.attach_alternative(emailContent, "text/html")
    msg.send()
    return HttpResponse(str(0), content_type="text/plain")