예제 #1
0
 def create(self):
   words = [x.text for x in self.goal_input]
   number = int(self.goal_number_input.text)
   today = date.today().isoformat()
   goal = Goal(profile=context['profile'], start_date=today, period='week', number=number)
   goal.words = words
   session = context['db_session']
   session.add(goal)
   # TODO: Move this after profiles have more than one character
   goal.characters.append(context['profile'].characters[0])
   session.commit()
   self.manager.set_screen('checkin')
예제 #2
0
def load_goals():
    """Load goals from goal.txt into database."""

    print "Seeding goals"

    # Delete all rows in table, so if we need to run this a second time,
    # we won't be trying to add duplicate users
    Goal.query.delete()

    # Read u.user file and insert data
    for row in open("seed_data/goal.txt"):
        row = row.rstrip()
        goal_id, name, start_time, end_time, goal_type, duration, \
            status, user_id = row.split("|")

        goal = Goal(goal_id=goal_id,
                    start_time=start_time,
                    end_time=end_time,
                    name=name,
                    goal_type=goal_type,
                    duration=duration,
                    status=status,
                    user_id=user_id)

        db.session.add(goal)

    db.session.commit()
예제 #3
0
def load_goals():
    """Load a fake set of users from a users.csv"""
    Goal.query.delete()
    for row in open("seed_data/goals.csv"):
        row = row.rstrip()
        items = re.split(r',', row)
        user_id = items[1]
        title = items[2]
        goal = items[3]
        numerical_value = items[4]
        description = items[5]
        created_on = items[6]
        status = items[7]
        canceled_by_user = items[8]
        if canceled_by_user == 'true':
            canceled_by_user = True
        else:
            canceled_by_user = False
        goal = Goal(user_id=user_id,
                    title=title,
                    goal=goal,
                    numerical_value=numerical_value,
                    description=description,
                    created_on=created_on,
                    status=status,
                    canceled_by_user=canceled_by_user)
        db.session.add(goal)
    db.session.commit()
예제 #4
0
def process_add_goal_dashboard():
    """Process add-goal form located in dashboard."""

    # Get data from form.
    goal_start_date = request.form["goal-start-date"]
    goal_freq_num = request.form["goal-freq-num"]
    goal_freq_time_unit = request.form["goal-freq-time-unit"]
    current_user_hobby_id = request.form["user-hobby-id"]

    new_goal = Goal(goal_start_date=goal_start_date,
                    goal_freq_num=goal_freq_num,
                    goal_freq_time_unit=goal_freq_time_unit,
                    user_hobby_id=current_user_hobby_id,
                    goal_active=True)

    active_goal = db.session.query(Goal).filter(
        Goal.user_hobby_id == current_user_hobby_id,
        Goal.goal_active.is_(True)).first()
    db.session.add(new_goal)

    if active_goal:
        active_goal.goal_active = False

    db.session.commit()

    return "Success"
예제 #5
0
def submit_goals():
    """Submit user's created goal and reroutes to user goal page"""

    user_id = session["user_id"]

    cat_name = request.form.getlist('goal_type')

    for name in cat_name:
        if Categories.query.filter(Categories.cat_name == name):
            pass
        else:
            category = Categories(cat_name=name)
            db.session.add(category)
            db.session.commit()

    description = request.form['goal_description']

    times_per_week = int(request.form['times_per_week'])

    goal = Goal(user_id=user_id,
                description=description,
                num_of_times=times_per_week)

    db.session.add(goal)
    db.session.commit()

    flash("Your goal was added!")

    return redirect("/user/%s" % user_id)
def create_goal(goal_miles, goal_number_hikes, goal_hike_difficulty, user_id):
    """Create and return a new goal."""

    goal = Goal(goal_miles=goal_miles,
                goal_number_hikes=goal_number_hikes,
                goal_hike_difficulty=goal_hike_difficulty,
                user_id=user_id)

    db.session.add(goal)
    db.session.commit()

    return goal
예제 #7
0
파일: seed.py 프로젝트: emilycheera/nourish
def load_goals(goal_filename):
    """Load goals from u.goal into database."""

    for row in open(goal_filename):
        row = row.rstrip()
        patient_id, time_stamp, goal_body = row.split("|")

        goal = Goal(patient_id=patient_id,
                    time_stamp=time_stamp,
                    goal_body=goal_body)

        db.session.add(goal)

    db.session.commit()
예제 #8
0
def add_goal():
    """Add new goal data to db."""

    goal_title = request.form["title"]
    goal_notes = request.form["notes"]

    goal = Goal(user_id=current_user.user_id,
                goal_title=goal_title,
                notes=goal_notes)

    db.session.add(goal)
    db.session.commit()

    return f"Added: {goal_title}!"
예제 #9
0
def create_new_goal(patient_id, form_data):
    """Create a new goal in the database."""

    time_stamp = datetime.now()
    goal_body = form_data.get("goal-body")

    new_goal = Goal(patient_id=patient_id,
                    time_stamp=time_stamp,
                    goal_body=goal_body)

    db.session.add(new_goal)
    db.session.commit()

    return new_goal
예제 #10
0
파일: views.py 프로젝트: lavaniab/goals
def edit_goal():
    """Function to search the user's goals"""

    user_id = session["user_id"]
    User.user_name = request.get['goal']
    to_update = User.user_name
    updated_goal = Goal(to_update=goal, user_id=user_id)

    db.session.add(updated_goal)
    db.session.commit()
    return jsonify({
        "goal_id": updated_goal.goal_id,
        "Goal": updated_goal.goal
    })
예제 #11
0
def user_goals(user_id):
    """Display user's goals"""

    user_id = session["user_id"]

    if Goal.query_by_user_id(user_id) is False:
        flash("You have no goals! Let's create some!")
        return render_template('create_goal.html')
    else:

        user = User.query_by_user_id(user_id)

        goals = Goal.query_by_user_id(user_id)

        #FIXME!! When refactoring code, need to add % completion
        #which is already written, but needs to be added
        #as a class method.  This needs to passed through
        #so when the modal appears for text reminders
        #goals which have already been completed for the week
        #don't show up!

        goals_counts = {}

        for goal in goals:
            goal_count = Completion.query.filter_by(
                goal_id=goal.goal_id).count()
            goals_counts[goal.goal_id] = goal_count

        pacific = pytz.timezone('US/Pacific')
        now = datetime.now(tz=pacific)
        week_day = now.strftime("%A")

        return render_template('user_goals.html',
                               week_day=week_day,
                               user=user,
                               goals=goals,
                               goals_counts=goals_counts)
예제 #12
0
def load_goals():
    """Load goals from goal.txt into database."""

    print "Goal"

    Goal.query.delete()

    with open("seed-data/goal.txt") as goals_data:

        for i, goal_data in enumerate(goals_data):
            goal_data = goal_data.rstrip()

            (user_hobby_id,
             goal_start_date_str,
             goal_active,
             goal_freq_num,
             goal_freq_time_unit) = goal_data.split("|")

            # Convert date string to a datetime object.
            if goal_start_date_str:
                goal_start_date = datetime.datetime.strptime(goal_start_date_str,
                                                             "%Y-%m-%d %H:%M:%S")
            else:
                goal_start_date = None

            if goal_freq_num:
                goal_freq_num = int(goal_freq_num)
            else:
                goal_freq_num = None

            if not goal_freq_time_unit:
                goal_freq_time_unit = None

            if not goal_active:
                goal_active = None

            goal = Goal(user_hobby_id=user_hobby_id,
                        goal_start_date=goal_start_date,
                        goal_active=goal_active,
                        goal_freq_num=goal_freq_num,
                        goal_freq_time_unit=goal_freq_time_unit)

            db.session.add(goal)

            if i % 100 == 0:
                print i

        db.session.commit()
예제 #13
0
파일: views.py 프로젝트: lavaniab/goals
def add_goal():
    """User can add short notes to their homepage."""

    user_id = session["user_id"]

    if request.method == "POST":
        goal = request.form["goal"]
        new_goal = Goal(goal=goal, user_id=user_id)

        db.session.add(new_goal)
        db.session.commit()

        # goal_id = new_goal.goal_id
        return jsonify({"goal_id": new_goal.goal_id, "Goal": new_goal.goal})
    else:
        return redirect(f"/")
예제 #14
0
def add_goal():
    """Display/process add-goal form."""

    if request.method == 'GET':

        # Get current user from session.
        current_user_id = session["user_id"]

        current_user = User.query.get(current_user_id)

        # Render add goal template and pass list of hobbies to Jinja template.
        return render_template("add-goal.html",
                               current_user_hobbies=current_user.hobbies,
                               current_user=current_user)

    else:
        # Get current user from session.
        current_user_id = session["user_id"]

        # Get data from form.
        goal_start_date = request.form["goal-start-date"]
        goal_freq_num = request.form["goal-freq-num"]
        goal_freq_time_unit = request.form["goal-freq-time-unit"]
        hobby_id = request.form["hobby-id"]

        user_hobby_id = db.session.query(UserHobby).filter(
            UserHobby.user_id == current_user_id,
            UserHobby.hobby_id == hobby_id).one().user_hobby_id

        new_goal = Goal(goal_start_date=goal_start_date,
                        goal_freq_num=goal_freq_num,
                        goal_freq_time_unit=goal_freq_time_unit,
                        user_hobby_id=user_hobby_id,
                        goal_active=True)

        db.session.add(new_goal)

        active_goal = db.session.query(Goal).filter(
            Goal.user_hobby_id == user_hobby_id,
            Goal.goal_active.is_(True)).first()

        if active_goal:
            active_goal.goal_active = False

        db.session.commit()

        return "Success"  # Javascript is redirecting to /dashboard.
예제 #15
0
파일: server.py 프로젝트: fabrgu/goal-app
def add_goal():
    """Add new goal """
    description = request.form.get('description')
    name = request.form.get('name')
    user_id = session.get('user_id')

    new_goal = Goal(description=description,
                    name=name,
                    user_id=user_id,
                    created_on=datetime.today(),
                    modified_on=datetime.today())
    db.session.add(new_goal)
    db.session.commit()

    flash('Your goal has been added!')

    return redirect(f'/goal_list/{user_id}')
예제 #16
0
def add_sample_goals():

    # Defines the group_id: admin's user_id
    group_admin = {
        1: 3,
        2: 1,
        3: 2,
    }

    # Defines the [Day component of datetime obj, goal in terms of number of
    # workouts].
    # The first two are set for mondays, and the third is a wednesday. I will be
    # implementing logic to have the wednesday goal declaration apply from the
    # most recent monday. In this case that will be 1/16/2017. I will also want
    # this goal to apply for all subsequent weeks until it is updated again.
    days_and_goals = {
        1: [2, 4],
        2: [9, 8],
        3: [18, 4],
    }

    for day_and_goal in days_and_goals.values():
        for group in group_admin:
            group_id = group
            user_id = group_admin[group]
            date_iniciated = datetime(2017, 1, day_and_goal[0])
            goal = day_and_goal[1]

            new_goal = Goal(
                group_id=group_id,
                user_id=user_id,
                date_iniciated=date_iniciated,
                goal=goal,
            )

            print new_goal
            db.session.add(new_goal)
            db.session.commit()
예제 #17
0
def load_goals():
    print("GOALS")

    # Delete all rows in table, so if we need to run this a second time,
    # we won't be trying to add duplicate goals
    Goal.query.delete()

    # Read u.user file and insert data
    for row in open("seed_data/goals"):

        row = row.rstrip()

        goal_id, user_id, goal_title, notes = row.split("|")

        goal = Goal(
            goal_id=goal_id, user_id=user_id, goal_title=goal_title, notes=notes
        )

        # add to the session
        db.session.add(goal)

    # commit data
    db.session.commit()
예제 #18
0
def add_new_goal():
    """Adds a new goal to the database"""

    user_id = session.get('current_user', None)
    if user_id:
        title = request.form.get('title')
        goal_type = request.form.get('type')
        numerical_value = float(request.form.get('numericalValue'))
        created_on = datetime.today()
        description = request.form.get('description')
        status = 'NOT_STARTED'
        canceled_by_user = False
        goal = Goal(user_id=user_id,
                    title=title,
                    goal=goal_type,
                    numerical_value=numerical_value,
                    description=description,
                    created_on=created_on,
                    status=status,
                    canceled_by_user=canceled_by_user)
        db.session.add(goal)
        db.session.commit()
        return 'Success; goal added!'
    return 'Failed; Please login and try again'
예제 #19
0
def add_goal():
    """Adds a goal to the goals table."""

    goal_name = str(request.form.get('goalName'))
    time_range = request.form.get('timeRange').split(" - ")
    start_time = datetime.strptime(time_range[0], "%Y-%m-%d %I:%M %p")
    end_time = datetime.strptime(time_range[1], "%Y-%m-%d %I:%M %p")
    goal_type = request.form.get('goalType')
    hours = int(request.form.get('hours'))
    minutes = int(request.form.get('minutes'))
    target = timedelta(hours=hours, minutes=minutes)
    user_id = session['user_id']

    # Create the new goal
    new_goal = Goal(name=goal_name,
                    start_time=start_time,
                    end_time=end_time,
                    goal_type=goal_type,
                    duration=target,
                    status="active",
                    user_id=user_id)

    db.session.add(new_goal)
    db.session.commit()

    # Add goal categories
    goal = Goal.query.filter_by(name=goal_name,
                                end_time=end_time,
                                user_id=user_id).one()
    goal_id = goal.goal_id

    goal_categories = request.form.get('goalCategories').split("|")[:-1]

    # Clear the goal's current categories and add the new ones
    goal.categories = []

    for category in goal_categories:
        new_category = Category.query.filter_by(user_id=user_id,
                                                name=category).one()
        new_goal_category = GoalCategory(goal_id=goal_id,
                                         category_id=new_category.category_id)
        db.session.add(new_goal_category)

    db.session.commit()

    # Prep arguments for goal_generate_html()
    goal_id = str(goal.goal_id)
    goal_categories = goal.category
    categories = Category.query.filter_by(user_id=user_id).all()
    start_time = start_time.strftime('%m/%d at %I:%M %p'),
    end_time = end_time.strftime('%m/%d at %I:%M %p'),
    days = target.days
    hours = target.seconds // 3600
    minutes = target.seconds // 60 % 60
    total_time = goal.total_time_str("goal_time")
    time_left = goal.time_left()
    goal_status = goal.goal_status()

    new_goal_html = goal_generate_html(goal_id, goal_name, categories,
                                       goal_categories, goal_type, start_time,
                                       end_time, days, hours, minutes, target,
                                       total_time, time_left, goal_status)

    return new_goal_html
예제 #20
0
파일: app.py 프로젝트: vyepifanov/flask_w4

if __name__ == '__main__':
    if FIRST_LAUNCH:
        with app.app_context():

            for k, v in data.hours.items():
                hour = Hour(code=k, name=v)
                db.session.add(hour)

            for k, v in data.week.items():
                day = Day(code=k, name=v)
                db.session.add(day)

            for k, v in data.goals.items():
                goal = Goal(code=k, name=v)
                db.session.add(goal)

            for k, v in data.times.items():
                time = Time(code=k, name=v)
                db.session.add(time)

            for t in data.teachers:
                teacher = Teacher(id=t['id'],
                                  name=t['name'],
                                  about=t['about'],
                                  rating=t['rating'],
                                  picture=t['picture'],
                                  price=t['price'],
                                  free=t['free'])
                db.session.add(teacher)