Example #1
0
def signup():

    form = RegistrationForm()

    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        email = form.email.data
        first_name = form.first_name.data
        last_name = form.last_name.data
        address = form.address.data

        user = User.register(
            username=username,
            password=password,
            email=email,
            first_name=first_name,
            last_name=last_name,
            address=address,
        )
        # latLng = Representative.find_latlng(address)
        # lat = latLng['lat']
        # lng = latLng['lng']

        reps = Representative.find_reps(address)

        for rep in reps:

            r = Representative.add_rep(rep)

            user.representatives.append(r)
            db.session.commit()

            login_user(user)
        flash("Signup successful")
        flash("Welcome")
        return redirect("/")

    if request.args:
        address = request.args["address"]
        form.address.data = address
        form.address.id = "search-input"
        form.address.type = "search"

        return render_template("signup.html", form=form, address=address)

    form.address.id = "search-input"
    form.address.type = "search"

    return render_template("signup.html", form=form)
Example #2
0
def your_reps():

    if not request.args["search-input"]:
        flash("Please enter an address")
        return redirect("/")

    address = request.args["search-input"]

    reps = Representative.find_reps(address=address)

    if not reps:
        flash(
            "No representatives found for the address. Please recheck your address"
        )
        flash("*NOTE: This is designed to find US state representatives only.")
        return redirect("/")
    return render_template("reps.html", reps=reps, address=address)
Example #3
0
 def test_find_reps(self, mock_find_latlng, mock_find_reps):
     reps = Representative.find_reps('testaddress')
     self.assertEqual(reps, all_info)