def show_existing_inputs(): """ This shows the user's current saved inputs and allows them to either move on or edit it. """ if g.logged_in is True: if g.inputs is True: user_assets = m_session.query(model.UserBanking).filter_by( user_id=g.user.id).first() total_assets = user_assets.inputted_assets + \ user_assets.checking_amt + user_assets.savings_amt + \ user_assets.IRA_amt + user_assets.comp401k_amt + \ user_assets.investment_amt risk_prof = m_session.query(model.RiskProfile).filter_by( id=g.user.risk_profile_id).first() return render_template( "profile_inputs.html", assets=utils.format_currency(total_assets), income=utils.format_currency(g.user.income), company_401k=g.user.company_401k, company_match=g.user.company_match, match_percent=utils.format_percentage(g.user.match_percent), match_salary=utils.format_percentage(g.user.match_salary), risk_profile=risk_prof.name) else: flash("Our financial data on you is incomplete. \ Please input now.") return redirect("/input/banking") else: return redirect("/login")
def t_rename_data(d=None, translation=None, p_keys=None): '''translate desired data''' target_dict = {} try: for k, v in translation.iteritems(): if (k in p_keys): d[k] = format_percentage(d[k]) target_dict[v] = d[k] except KeyError, e: log.error("Could not find required key %s in %s" % (k, d)) raise Paso2015(__name__)
cand_list = [] for row in data: # Skip special political parties try: if row["id_partido"] in SPECIAL_PARTIES: continue if (float(row["pct"]) >= PASS_THRESHOLD): party_passed = True else: party_passed = False # Get maximum number of votes for a party primary max_v = int(max(row["listas"], key=lambda x: int(x["votos"]))["votos"]) for c_d in row["listas"]: tmp_cand = {"id": c_d["id_candidato"], "p": format_percentage(c_d["pct_total"]), "g": "1" if (int(c_d["votos"]) == max_v) else "0", "pp": "1" if party_passed else "0"} cand_list.append(tmp_cand) except (KeyError, ValueError, IndexError), e: log.error("Failed to get the candidate percentage. Reason: %s" % (str(e))) raise Paso2015(__name__) # Order candidate list by descending percentage cand_list.sort(key=lambda x: float(x['p']), reverse=True) result["candidatos"] = cand_list return result # Front page ranking transformations def t_ranking(d_d=None):
for row in data: # Skip special political parties try: if row["id_partido"] in SPECIAL_PARTIES: continue if (float(row["pct"]) >= PASS_THRESHOLD): party_passed = True else: party_passed = False # Get maximum number of votes for a party primary max_v = int( max(row["listas"], key=lambda x: int(x["votos"]))["votos"]) for c_d in row["listas"]: tmp_cand = { "id": c_d["id_candidato"], "p": format_percentage(c_d["pct_total"]), "g": "1" if (int(c_d["votos"]) == max_v) else "0", "pp": "1" if party_passed else "0" } cand_list.append(tmp_cand) except (KeyError, ValueError, IndexError), e: log.error("Failed to get the candidate percentage. Reason: %s" % (str(e))) raise Paso2015(__name__) # Order candidate list by descending percentage cand_list.sort(key=lambda x: float(x['p']), reverse=True) result["candidatos"] = cand_list return result # Front page ranking transformations