Beispiel #1
0
def user_loader(user_id):
    if db_session.query(User).get(user_id):
        user = db_session.query(User).get(user_id)
        app.logger.info("Loading user %s", user.get_id())
        return user
    else:
        app.logger.info("No user with matching id.")
Beispiel #2
0
def post(user_id):
    """
    Handle put, post and delete requests. HTML forms only provide get and post methods.
    Therefore all forms that are used to modify objects must send a POST and manually
    provide the appropriate method.

    Example:
        <input type="hidden" name="method" value="PUT">

    ...where 'value' is the method to be used for the request.

    :param user_id:
    :return:
    """
    user = db_session.query(User).get(user_id)
    method = request.form['method']
    app.logger.info("Request method: %s", method)
    if method == 'PUT':
        app.logger.info("Process PUT")
        if request.form['password']:
            user.update_password(request.form['password'])
        if request.form['email']:
            user.email = request.form['email']
        db_session.add(user)
        db_session.commit()
    if method == 'POST':
        # create user
        app.logger.info("Create a user ...")
    if method == 'DELETE':
        delete(user_id)
    return render_template("user/show.html",
                           user=db_session.query(User).get(user_id))
Beispiel #3
0
def get(user_id):
    """
    Display user profile

    :param user_id:
    :return:
    """
    return render_template('user/show.html',
                           user=db_session.query(User).get(user_id))
Beispiel #4
0
def edit(user_id):
    """
    Route user to a page where they can edit their profile.

    :param user_id:
    :return:
    """
    return render_template("user/edit.html",
                           user=db_session.query(User).get(user_id))
Beispiel #5
0
def edit(cleanup_id):
    """
    Render clean-up editing template. PUTs to cleanups/:id.

    :return: edit template.
    """
    # TODO: Update form to include current values for current cleanup
    cleanups = db_session.query(Cleanup).get(cleanup_id)
    return render_template('cleanup/edit.html',
                           cleanup=cleanups,
                           section='Create Cleanup')
Beispiel #6
0
def join():
    """
    Users can join currently listed clean-up event.

    :return:
    """
    cleanup_id = request.form['cleanup_id']
    cleanups = db_session.query(Cleanup).get(cleanup_id)
    cleanups.participants.append(current_user)
    cleanups.save()
    return redirect(url_for('cleanups.get', cleanup_id=cleanups.id))
Beispiel #7
0
def login():
    """Website login."""
    username = request.form['username']
    # Check Username exists
    if db_session.query(User).filter(User.username == username).count():
        # Get user account
        user = db_session.query(User).filter(User.username == username).first()
        # Check password against database
        if user.check_password(request.form['password']):
            user.authenticated = True
            db_session.add(user)
            db_session.commit()
            login_user(user, remember=True)  # Reflect user authorization in Flask
            return redirect(url_for('users.get', user_id=user.id))
        else:
            # Next step: require user feedback password or username incorrect
            return redirect(url_for("welcome"), code=200)
    else:
        # Next Step: require user feedback password or username incorrect
        return redirect(url_for("welcome"), code=400)
Beispiel #8
0
def get(cleanup_id):
    """
    Render current clean-up template.

    :param cleanup_id:
    :return: show template
    """
    cleanups = db_session.query(Cleanup).get(cleanup_id)
    return render_template("cleanup/show.html",
                           section="Cleanup",
                           cleanup=cleanups,
                           gmap=current_app.config['GOOGLE_MAPS_ENDPOINT'])
Beispiel #9
0
def my_cleanups(user_id):
    """
    Display clean-ups created by current user and clean-ups they're participating in.

    :param user_id:
    :return:
    """
    user = db_session.query(User).get(user_id)
    return render_template(
        'user/cleanups.html',
        # cleanups=user.particpation,
        my_cleanups=user.cleanups)
Beispiel #10
0
def send_to_pw(id):
    """
    send clean-up data to Public Works google sheet
    :param id:
    :return:
    """
    cleanup = db_session.query(Cleanup).filter(Cleanup.id == id).first()
    host = db_session.query(User).filter(User.id == cleanup.host_id).first()
    location = db_session.query(Location).filter(
        Location.id == cleanup.location_id).first()

    num_participants = len(cleanup.participants) + 1  #Add, Addition of Host
    start_end_times = '%s - %s' % (cleanup.start_time, cleanup.end_time)
    data = [
        host.username, "User Address", host.email, "phone number",
        location.address, "Illegal Dumping", num_participants, cleanup.date,
        start_end_times, "Debris Plan", "Tool pickup date and time",
        "Tool drop off date and time", "Staff Contact"
    ]

    send_to_sheet(data)  #Very slow function

    return render_template("cleanup/send_to_pw.html",
                           section='Send to Public Works')
Beispiel #11
0
def update(cleanup_id):
    """
    Create, update or delete a `Cleanup`

    :param cleanup_id:
    :return: redirects user to cleanups/ or cleanups/:id
    """
    method = request.form['method']
    cleanups = db_session.query(Cleanup).get(cleanup_id)
    if method == 'PUT':
        current_app.logger.debug("REQUEST FORM: %s", request.form)
        cleanups.update(
            **request.form.to_dict())  # Exceptions handled by models.py
        return redirect(url_for('cleanups.get', cleanup_id=cleanups.id))
    elif method == 'DELETE':
        cleanups.delete()
        return redirect(url_for('cleanups.get_all'))
Beispiel #12
0
def get_all():
    """
    Display full list of cleanups.

    :return: list template
    :except: home template
    """
    try:
        cleanups = db_session.query(
            Cleanup).all()  # Look at all of the cleanups
    except AttributeError:
        current_app.logger.error("NullSession, redirecting to homepage")
        return render_template('index.html')
    else:
        return render_template('cleanup/list.html',
                               section="Cleanup",
                               cleanups=cleanups)
Beispiel #13
0
def send_to_scf(id):
    """
    Send clean-up to SeeClickFix.com
    :param id:
    :return:
    """
    cleanup = db_session.query(Cleanup).filter(Cleanup.id == id).first()
    print("Lat: %f, Address: %s" %
          (cleanup.lat, cleanup.address))  # Sanity Check
    api_request = postSCFix(
        cleanup
    )  # Function in SeeClickFix Module,interacts with SeeClickFix API
    response = api_request.json()  # Contains Response from SeeClickFix
    issue_url = response[
        'html_url']  # Important to distinguish site from api urls
    cleanup.html_url = issue_url  # Add to SQL database
    db_session.add(cleanup)
    db_session.commit()
    return redirect(url_for('cleanup', id=id))
Beispiel #14
0
def delete(cleanup_id):
    """
    Remove a clean-up. This requires:
        - Remove the relation from the User (`User.cleanups`)
        - Remove all participants from the Cleanup (`Cleanup.participants`)
        - Remove the `Cleanup`

    :param cleanup_id:
    :return:
    """
    # TODO: Notify participants that clean-up was cancelled!
    cleanups = db_session.query(Cleanup).get(cleanup_id)
    # First delete the cleanup from the user's hosting roster
    current_user.cleanups.remove(cleanups)
    # Then, remove all participants from cleanup
    cleanups.participants = []
    # Finally remove the cleanup from SQL
    db_session.delete(cleanups)
    db_session.commit()
    return redirect(url_for('cleanups'))
Beispiel #15
0
def send_to_sheet(id, tool_data):
    cleanup = db_session.query(Cleanup).filter(Cleanup.id == id).first()
    #TODO: Match data format of Public Works
    timestamp = '{:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now())
    legal_name = tool_data.get('legal_name')
    home_address = tool_data.get('home_address')
    email = tool_data.get('email')
    phone_number = tool_data.get("phone_number")

    cleanup_address = cleanup.location.address
    num_participants = len(cleanup.participants) + 1
    cleanup_date = cleanup.date
    start_end_times = '%s - %s' % (cleanup.start_time, cleanup.end_time)

    staff_contact = tool_data.get("staff_contact")
    tool_pickup_date = tool_data.get("tool_pickup_date")
    tool_pickup_time = tool_data.get("tool_pickup_time")
    pickup_time_of_day = tool_data.get("pickup_time_of_day")
    tool_pickup = "%s, %s %s" % (tool_pickup_date, tool_pickup_time,
                                 pickup_time_of_day)

    tool_drop_off_date = tool_data.get("tool_drop_off_date")
    tool_drop_off_time = tool_data.get("tool_drop_off_time")
    drop_off_time_of_day = tool_data.get("drop_off_time_of_day")
    tool_drop_off = "%s, %s %s" % (tool_drop_off_date, tool_drop_off_time,
                                   drop_off_time_of_day)

    # tools
    empty = 0
    rubber_dipped = tool_data.get("rubber_dipped")
    small_nitrile = tool_data.get("small_nitrile")
    medium_nitrile = tool_data.get("medium_nitrile")
    large_nitrile = tool_data.get("large_nitrile")
    cotton_glove = tool_data.get("cotton_glove")
    vest = tool_data.get("vest")
    regular_pick_stick = tool_data.get("regular_pickup_stick")
    small_pick_stick = tool_data.get("small_pickup_stick")
    push_broom = tool_data.get("push_broom")
    reg_house_broom = tool_data.get("reg_house_broom")
    small_house_broom = tool_data.get('small_house_broom')
    reg_dust_pan = tool_data.get("reg_dust_pan")
    long_handle_dust_pan = tool_data.get("long_handle_dust_pan")
    paint = empty
    hand_clippers = tool_data.get("hand_clippers")
    loppers = tool_data.get("loppers")
    pruning_saw = tool_data.get("pruning_saw")
    shears = tool_data.get("shears")
    held_bulb_planter = tool_data.get("held_bulb_planter")
    long_bulb_planter = tool_data.get("long_bulb_planter")
    hand_hoe = tool_data.get("hand_hoe")
    hand_trowel = tool_data.get("hand_trowel")
    hand_weeder = tool_data.get("hand_weeder")
    hori_hori = tool_data.get("hori_hori")
    mattock_tiller = tool_data.get("mattock_tiller")
    fifteen_mattock = tool_data.get("fifteen_mattock")
    twenty_three_mattock = tool_data.get("twenty_three_mattock")
    thirty_two_mattock = tool_data.get("thirty_two_mattock")
    pick_ax = tool_data.get("pick_ax")
    fire_ax = tool_data.get("fire_ax")
    standard_hoe = tool_data.get("standard_hoe")
    hula_hoe = tool_data.get("hula_hoe")
    standard_leaf_rake = tool_data.get("standard_leaf_rake")
    narrow_leaf_rake = tool_data.get("narrow_leaf_rake")
    bow_rake = tool_data.get("bow_rake")
    pitch_fork = tool_data.get("pitch_fork")
    mcleod = tool_data.get("mcleod")
    pointed_shovel = tool_data.get("pointed_shovel")
    flat_shovel = tool_data.get("flat_shovel")
    scoop_shovel = tool_data.get("scoop_shovel")
    grass_trimmers = tool_data.get("grass_trimmers")
    standard_weed_wrench = tool_data.get("standard_weed_wrench")
    large_weed_wrench = tool_data.get("large_weed_wrench")
    plastic_bag = tool_data.get("plastic_bag")
    green_waste = tool_data.get("green_waste")
    reusable_bag = tool_data.get("reusable_bag")
    first_aid = tool_data.get("first_aid")
    cooler = tool_data.get("cooler")
    five_gal_buck = tool_data.get("five_gal_buck")
    two_gal_buck = tool_data.get("two_gal_buck")
    skimmer = tool_data.get("skimmer")
    ed_poster = empty
    other = empty

    formatted_data = [
        timestamp, legal_name, home_address, email, phone_number,
        cleanup_address, "Illegal Dumping", num_participants, cleanup_date,
        start_end_times, "Debris Plan", tool_pickup, tool_drop_off,
        staff_contact, rubber_dipped, small_nitrile, medium_nitrile,
        large_nitrile, cotton_glove, vest, regular_pick_stick,
        small_pick_stick, push_broom, reg_house_broom, small_house_broom,
        reg_dust_pan, long_handle_dust_pan, paint, paint, paint, paint, paint,
        paint, paint, paint, paint, paint, paint, paint, paint, hand_clippers,
        loppers, pruning_saw, shears, held_bulb_planter, long_bulb_planter,
        hand_hoe, hand_trowel, hand_weeder, hori_hori, mattock_tiller,
        fifteen_mattock, twenty_three_mattock, thirty_two_mattock, pick_ax,
        fire_ax, standard_hoe, hula_hoe, standard_leaf_rake, narrow_leaf_rake,
        bow_rake, pitch_fork, mcleod, pointed_shovel, flat_shovel,
        scoop_shovel, grass_trimmers, standard_weed_wrench, large_weed_wrench,
        plastic_bag, green_waste, reusable_bag, first_aid, cooler,
        five_gal_buck, two_gal_buck, skimmer, ed_poster, other
    ]

    print("Formatted Data:", formatted_data)

    wks.insert_row(formatted_data, index=top_row)
Beispiel #16
0
def delete(user_id):
    """Delete account."""
    user = db_session.query(User).get(user_id)
    db_session.remove(user)
    db_session.commit()
    return render_template("login.html")