Beispiel #1
0
    def post(self):
        parser = RequestParser()
        parser.add_argument('user', type=str, required=True)
        parser.add_argument('name', type=str, required=True)
        parser.add_argument('parent_name', type=str)
        parser.add_argument('description', type=str, required=False)
        args = parser.parse_args()

        # Get a SQL Alchemy query object
        q = db.session.query

        # Create a new goal
        user = q(m.User).filter_by(name=args.user).one()

        # Find parent goal by name
        if args.parent_name:
            parent = q(m.Goal).filter_by(name=args.parent_name).one()
        else:
            parent = None

        goal = m.Goal(user=user,
                      parent=parent,
                      name=args.name,
                      description=args.description)

        db.session.add(goal)
        db.session.commit()
def create_goal(db: Session, goal: goal_schema.GoalCreate):
    db_goal = models.Goal()
    [setattr(db_goal, i[0], i[1]) for i in goal]

    db.add(db_goal)
    db.commit()
    db.refresh(db_goal)
    return db_goal
Beispiel #3
0
def create_goal(goal: schema.Goal):

    db_goal = models.Goal(
        goal=goal.goal,
        has_amount=goal.has_amount,
        date_created=goal.date_created,
    )
    db.session.add(db_goal)
    db.session.commit()
    return db_goal
Beispiel #4
0
def add_goal():
    data = request.form.get("goal")

    try:
        goal = models.Goal(description=data)

        db.session.add(goal)
        db.session.commit()
        return "Successfully added goal"
    except Exception as e:
        return "bad request bruh", 400
Beispiel #5
0
 def add_goal(self, request):
     users = models.User.query().fetch()
     user = users[0]
     user.all_goals.append(
         models.Goal(name=request.name,
                     value=request.value,
                     percent_completed=request.percent_completed,
                     is_default=request.is_default,
                     is_achieved=request.is_achieved))
     user.put()
     return message_types.VoidMessage()
Beispiel #6
0
def add_goals():
    goals = {
        "College": 50000,
        "Marriage": 20000,
        "House": 1000000,
        "Car": 50000,
        "Child": 1000000,
        "Vacation": 5000
    }
    users = models.User.query().fetch()
    user = users[0]
    for k, v in goals.items():
        user.all_goals.append(models.Goal(name=k, value=v))
    user.put()
    def post(self):
        user = _get_user()
        parser = RequestParser()
        parser.add_argument('name', type=str, required=True)
        parser.add_argument('parent_name', type=str)
        parser.add_argument('description', type=str, required=False)
        args = parser.parse_args()

        # Get a SQL Alchemy query object
        q = _get_query()

        # Create a new goal

        # Find parent goal by name
        parent = q(m.Goal).filter_by(name=args.parent_name).scalar()

        goal = m.Goal(user=user,
                      parent=parent,
                      name=args.name,
                      description=args.description)

        s = _get_session()
        s.add(goal)
        s.commit()