Example #1
0
def dashboard():
    """return user homepage with their goals listed"""
    uin = helper_methods.logged_in(current_user)
    try:
        if session['cookie']:
            goal_id = session['cookie']
            goal_obj = storage.get_goal_by_id(goal_id)
            setattr(goal_obj, 'user_id', current_user.id)
            storage.save(goal_obj)
            session['cookie'] = None
            helper_methods.email_goal_logged(current_user, goal_obj)
    except KeyError:
        pass
    user = storage.get_user_by_id(current_user.id)
    goal_objs_and_editability = list()
    for rec in user.goals:
        goal_objs_and_editability.append(
            (rec, helper_methods.is_goal_editable(rec),
             helper_methods.days_passed(rec),
             helper_methods.progress_percentage(rec)))
    return render_template('user_dashboard.html',
                           uin=uin,
                           user=user,
                           title_page='Dashboard',
                           goal_objs_and_editability=goal_objs_and_editability)
Example #2
0
def completion_submit(goal_id):
    """store the completion status in database's goal object"""
    is_completed = request.args.get('complete', None)
    goal_obj = storage.get_goal_by_id(goal_id)
    if goal_obj:
        setattr(goal_obj, 'completed', bool(is_completed))
        storage.save(goal_obj)
    flash("You've successfully evaluated your friend's goal", 'success')
    return redirect(url_for("index"))
Example #3
0
def register():
    """return landing page in response to registration"""
    uin = helper_methods.logged_in(current_user)
    form = RegistrationForm()
    if form.validate_on_submit():
        new_user = User(email=form.email.data,
                        password=form.password.data,
                        first_name=form.first_name.data)

        storage.save(new_user)
        flash('A warm welcome from Melissa and Amy!', 'success')
        login_user(new_user)
        return redirect(url_for('dashboard'))
    return render_template("register.html", uin=uin, form=form)
Example #4
0
def update():
    """return user homepage with updated goals listed"""
    # codes for editting goals
    req = request.form
    if request.method == 'POST':
        updated_line = req.get('updated_goal').split('</span>')[1]
        updated_goal = updated_line.split(',id=')[0]
        goal_id = updated_line.split(',id=')[1]
        for rec in storage.all().values():
            if str(rec.id) == goal_id:
                setattr(rec, 'goal', updated_goal)
                storage.save(rec)
                helper_methods.email_goal_updated(rec)
    else:
        goal_to_delete = req.get('goal_to_delete')
        for rec in storage.all().values():
            if str(rec.id) == goal_to_delete:
                helper_methods.email_goal_deleted(rec)
                storage.delete(rec)
    return ("just updated/deleted")
Example #5
0
def create_goal():
    """POST goal to database if logged in
        else save goal obj in cookie and update it's user_id once logged in
    """
    form = GoalForm()
    if form.validate_on_submit():
        obj = Goal(goal=form.goal.data,
                   deadline=form.deadline.data,
                   accountability_partner=form.accountability_partner.data,
                   partner_email=form.partner_email.data,
                   pledge=form.pledge.data)
        storage.save(obj)
        if current_user.is_authenticated:
            setattr(obj, 'user_id', current_user.id)
            storage.save(obj)
            flash('Successfully made a commitment!', 'success')
            helper_methods.email_goal_logged(current_user, obj)
            return redirect(url_for('dashboard'))
        else:
            session['cookie'] = obj.id
            flash("Please login first!")
            return redirect(url_for("login"))
    return redirect(url_for("dashboard"))