Beispiel #1
0
def index():
    """Homepage."""
    #if there's a user_id in our Flask session, use that to open the app to the user. Otherwise, send the user to a signup page

    if session.get('user_id', False):
        #show the user their upcoming chores
        #get the current user (email)
        user = dbwrangler.get_current_user()
        user_id = user.user_id
        #return a dictionary of one user's chores for a month, grouped by day
        chores = helpers.chores_by_date(user_id)
        print len(chores)
        #mark the current datetime, assign to now
        now = datetime.utcnow()
        #define a delta of 4 weeks
        until = now + timedelta(weeks=4)
        #generate a list of datetimes for each day in the next month
        month_of_days_dt = rrule(freq=DAILY, dtstart=now, until=until)
        #cast list of datetimes into human-friendly string format
        month_of_days = [
            day.strftime("%A, %B %d, %Y") for day in month_of_days_dt
        ]
        #feed the template a month of days, and all chores for the logged in user. Jinja will display chores by day.
        return render_template("dashboard.html",
                               user=user,
                               chores=chores,
                               month=month_of_days)
    else:
        return render_template("homepage.html")
Beispiel #2
0
def claimchore():
    """Display a list of available chores and the days on which they occur, for 
    the user to select and claim"""
    user = dbwrangler.get_current_user()
    userchores = Userchore.query.filter_by(address_id=user.address,
                                           commitment='INIT').all()
    #Below: chores that this belong to this user's address
    address_chores = [
        Chore.query.filter_by(chore_id=userchore.chore_id).first()
        for userchore in userchores
    ]
    chores = []
    for chore in address_chores:
        #gather userchore entries for this chore
        userchores = Userchore.query.filter_by(chore_id=chore.chore_id).all()
        #isolate the item from ^ that is the clean (first) member of that chore inside userchores(table)
        base_userchore = [
            userchore for userchore in userchores
            if userchore.commitment == 'INIT'
        ]
        #get the rest of the chore data associated with that chore
        days_left = chore.days_weekly.split("|")
        days_left = helpers.find_days_left(chore, userchores, days_left)
        if len(days_left) != 0:
            chores.append(chore)
    for chore in chores:
        #recast the occurance dates for these as lists
        chore.days_weekly = chore.days_weekly.split("|")
        if chore.date_monthly:
            chore.date_monthly = inflect.engine().ordinal(chore.date_monthly)

    return render_template("takeachore.html",
                           chores=chores,
                           userchores=userchores,
                           user=user)
Beispiel #3
0
def new_address():
    """Present new address form"""
    user = dbwrangler.get_current_user()
    if user:
        return render_template("new_user_more.html")
    else:
        return redirect("/")
Beispiel #4
0
def user_profile():
    """Show user profile"""
    #get info for logged in user
    user = dbwrangler.get_current_user()
    #get housemates who live with this user
    all_housemates = User.query.filter_by(address=user.address).all()
    #get address info from DB
    address = Address.query.filter_by(address_id=user.address).first()
    #feed this data to the user page template for the user to review
    return render_template("user.html",
                           user=user,
                           address=address,
                           all_housemates=all_housemates)
Beispiel #5
0
def claimchore():
    """Display a list of available chores and the days on which they occur, for 
    the user to select and claim"""
    user = dbwrangler.get_current_user()
    userchores = Userchore.query.filter_by(address_id=user.address, 
                                            commitment='INIT').all()
    chores = [Chore.query.filter_by(chore_id=userchore.chore_id).first()
                                     for userchore in userchores]
    for chore in chores:
        chore.days_weekly = chore.days_weekly.split("|")

    return render_template("takeachore.html", chores=chores, 
                            userchores=userchores, user=user)
Beispiel #6
0
def index():
    """Homepage."""
    if session.get('user_id', False):
        user = dbwrangler.get_current_user()
        user_id = user.user_id
        #return all chores at this address
        chores = helpers.chores_by_date(user_id)
        now = datetime.utcnow()
        until = now + relativedelta(months=+1)
        month_of_days_dt = rrule(DAILY,dtstart=now,until=until)
        month_of_days = [day.strftime("%A, %B %d, %Y") for day in month_of_days_dt]
        print month_of_days
        pprint.pprint(chores)
        return render_template("dashboard.html", user=user, chores=chores, month=month_of_days)
    else:
        return render_template("homepage.html")
Beispiel #7
0
def user_contributions_chart():
    """Return a chart of data about household contributions."""

    #get current user according to Flask session
    user = dbwrangler.get_current_user()

    #get all users from the user table sharing their address (so, their housemates)
    all_housemates = User.query.filter_by(address=user.address).all()

    #calculate total minutes of labor wach month for the user and their housemates
    total_household_labor = dbwrangler.total_houehold_labor(user)

    #build a data dictionary to feed jsonify. First entry in the labels list is unclaied labor... total household labor from which we will subtract housemate contributions
    dd_labels = ["Unclaimed"]

    #dd_data will be the minutes per user. Instantiate as an empty list.
    dd_data = []

    #each user gets a unique color
    dd_bgcolors = helpers.color_picker(len(all_housemates) + 1)

    #Chart.js lets you select bgcolor for each wedge as one hovers over the chart
    dd_hoverbg = ["#a6a6a6", "#a6a6a6", "#a6a6a6", "#a6a6a6"]

    leftover_labor = total_household_labor

    #build lists in each field of our data dictionary, with each member of the household at their own index
    for housemate in all_housemates:
        dd_labels.append(housemate.name)
        individual_labor = dbwrangler.individual_labor(housemate.user_id)
        dd_data.append(individual_labor)
        leftover_labor -= individual_labor

    #zeroth index is the unclaimed labor (this from 21 lines above)
    dd_data = [leftover_labor] + dd_data

    data_dict = {
        "labels":
        dd_labels,
        "datasets": [{
            "data": dd_data,
            "backgroundColor": dd_bgcolors,
            "hoverBackgroundColor": dd_hoverbg
        }]
    }

    return jsonify(data_dict)
Beispiel #8
0
def user_profile():
    """Show user profile"""
    user = dbwrangler.get_current_user()
    address = Address.query.filter_by(address_id=user.address).first()
    return render_template("user.html", user=user, address=address)