def goals(): requests = User.objects(id = g.user.id).first().goalrequest myGoals = Goal.objects(people=g.user.id) completedGoals = Goal.objects(completed=g.user.id) missedGoals = Goal.objects(missed=g.user.id) return render_template('goals.html', goals = myGoals, completedGoals = completedGoals, missedGoals = missedGoals, requests = requests)
def add_goal(): username = session['username'] if request.form["button"] == u"新規作成": goal_text = request.form['goal_text'] if goal_text != "": Goal(username=username, content=goal_text).save() elif request.form["button"] == u"削除": rmgoal = request.form['rmgoal'] Goal.objects(username=username, content=rmgoal).delete() return redirect('/goal')
def add_goal(): username = session['username'] if request.form["button"] == u"新規作成": goal_text = request.form['goal_text'] if goal_text != "": Goal(username=username, content=goal_text).save() elif request.form["button"] == u"削除": rmgoal = request.form['rmgoal'] Goal.objects(username=username, content=rmgoal).delete() return redirect('/goal')
def goals(): requests = User.objects(id=g.user.id).first().goalrequest myGoals = Goal.objects(people=g.user.id) completedGoals = Goal.objects(completed=g.user.id) missedGoals = Goal.objects(missed=g.user.id) return render_template('goals.html', goals=myGoals, completedGoals=completedGoals, missedGoals=missedGoals, requests=requests)
def joingoal(goalid): goal = Goal.objects(id=goalid).first() me = User.objects(id=g.user.id).first() feeditem = GoalRequest(message=g.user.name + " just joined a goal you are working on", user=me, goal=goal) for person in goal.people: if person != me: person.feed.append(feeditem) person.save() friend = person goal.people.append(me) goal.save() feeditem = GoalRequest(message="Check out the goal you just joined with " + friend.name, user=friend, goal=goal) User.objects(id=g.user.id).update_one(pull__feed__goal=ObjectId(goalid)) User.objects(id=g.user.id).update_one(push__feed=feeditem) User.objects(id=g.user.id).update_one(pull__goalrequest=ObjectId(goalid)) return redirect(url_for('index'))
def friends(): goals = Goal.objects(people = g.user.id) me = User.objects(id = g.user.id).first() friends = Set() for goal in goals: friends.update(goal.people) friends.update(goal.completed) if friends: friends.remove(me) return render_template('friends.html', friends = friends)
def friends(): goals = Goal.objects(people=g.user.id) me = User.objects(id=g.user.id).first() friends = Set() for goal in goals: friends.update(goal.people) friends.update(goal.completed) if friends: friends.remove(me) return render_template('friends.html', friends=friends)
def goaltree(goalid): me = User.objects(id=g.user.id).first() goal = Goal.objects(id=goalid).first() tasks = Task.objects(goal=goalid).order_by('-end') form = TaskForm() if form.validate_on_submit(): task = Task(goal=goal, name=form.name.data, description=form.description.data, end=form.end.data, people=[me]) task.save() feeditem = TaskRequest( message='A task was added to a goal you are working on', user=me, task=task, goal=goal) for person in goal.people: if person != me: person.feed.append(feeditem) person.save() return redirect(url_for('goaltree', goalid=goalid)) megacounts = {} for person in goal.people: counts = {'active': [], 'completed': [], 'missed': []} for task in tasks: if person in task.people: counts['active'].append(task) if person in task.completed: counts['completed'].append(task) if person in task.missed: counts['missed'].append(task) megacounts[person.id] = counts return render_template('goaltreelite.html', me=me, goal=goal, tasks=tasks, today=datetime.datetime.now(), form=form, allCounts=megacounts)
def newgoal(): goals = Goal.objects(people=g.user.id) me = User.objects(id=g.user.id).first() friends = Set() if goals: for goal in goals: friends.update(goal.people) friends.update(goal.completed) if friends: friends.remove(me) else: friends.add(User.objects(username='******').first()) form = GoalForm() if form.validate_on_submit(): me = User.objects(id=g.user.id).first() if form.description.data: goal = Goal(name=form.name.data, description=form.description.data, end=form.end.data, people=[me]) else: goal = Goal(name=form.name.data, end=form.end.data, people=[me]) goal.save() feeditem = GoalRequest( user=me, goal=goal, message='Your friend invited you to join their goal') people = [] for email in form.people.data: friend = User.objects(username=email).first() friend.feed.append(feeditem) friend.goalrequest.append(goal) friend.save() flash('Goal added!') return redirect(url_for('goals')) else: print "Nope" return render_template('newgoal.html', users=friends, form=form)
def addincentives(goalid): goal = Goal.objects(id=goalid).first() form = AddIncentivesForm() if form.validate_on_submit(): #TODO will want to prepopulate fields if incentives already exist if form.first.data: first = Incentive(penalties=[form.first.data], number=1) Goal.objects(id=goalid).update_one(add_to_set__incentives=first) if form.second.data: second = Incentive(penalties=[form.second.data], number=2) Goal.objects(id=goalid).update_one(add_to_set__incentives=second) if form.third.data: third = Incentive(penalties=[form.third.data], number=3) Goal.objects(id=goalid).update_one(add_to_set__incentives=third) if form.beyond.data: beyond = Incentive(penalties=[form.beyond.data], number=4) Goal.objects(id=goalid).update_one(add_to_set__incentives=beyond) return redirect(url_for('goaltree', goalid=goalid)) return render_template('addincentives.html', form=form)
def addincentives(goalid): goal = Goal.objects(id = goalid).first() form = AddIncentivesForm() if form.validate_on_submit(): #TODO will want to prepopulate fields if incentives already exist if form.first.data: first = Incentive(penalties = [ form.first.data ], number = 1) Goal.objects(id = goalid).update_one(add_to_set__incentives=first) if form.second.data: second = Incentive(penalties = [ form.second.data ], number = 2) Goal.objects(id = goalid).update_one(add_to_set__incentives=second) if form.third.data: third = Incentive(penalties = [ form.third.data ], number = 3) Goal.objects(id = goalid).update_one(add_to_set__incentives=third) if form.beyond.data: beyond = Incentive(penalties = [ form.beyond.data ], number = 4) Goal.objects(id = goalid).update_one(add_to_set__incentives=beyond) return redirect(url_for('goaltree', goalid=goalid)) return render_template('addincentives.html',form = form)
def newgoal(): goals = Goal.objects(people = g.user.id) me = User.objects(id = g.user.id).first() friends = Set() if goals: for goal in goals: friends.update(goal.people) friends.update(goal.completed) if friends: friends.remove(me) else: friends.add(User.objects(username = '******').first()) form = GoalForm() if form.validate_on_submit(): me = User.objects(id = g.user.id).first() if form.description.data: goal = Goal(name = form.name.data, description = form.description.data, end = form.end.data, people = [me] ) else: goal = Goal(name = form.name.data, end = form.end.data, people = [me] ) goal.save() feeditem = GoalRequest(user=me,goal=goal,message='Your friend invited you to join their goal') people = [] for email in form.people.data: friend = User.objects(username = email).first() friend.feed.append(feeditem) friend.goalrequest.append(goal) friend.save() flash ('Goal added!') return redirect(url_for('goals')) else: print "Nope" return render_template('newgoal.html',users = friends, form = form)
def joingoal(goalid): goal = Goal.objects(id = goalid).first() me = User.objects(id = g.user.id).first() feeditem = GoalRequest(message=g.user.name+" just joined a goal you are working on",user = me, goal = goal) for person in goal.people: if person != me: person.feed.append(feeditem) person.save() friend = person goal.people.append(me) goal.save() feeditem = GoalRequest(message="Check out the goal you just joined with " + friend.name, user = friend, goal = goal) User.objects(id = g.user.id).update_one(pull__feed__goal=ObjectId(goalid)) User.objects(id = g.user.id).update_one(push__feed=feeditem) User.objects(id = g.user.id).update_one(pull__goalrequest=ObjectId(goalid)) return redirect(url_for('index'))
def goaltree(goalid): me = User.objects(id = g.user.id).first() goal = Goal.objects(id = goalid).first() tasks = Task.objects(goal = goalid).order_by('-end') form = TaskForm() if form.validate_on_submit(): task = Task(goal=goal,name = form.name.data, description = form.description.data, end = form.end.data, people = [me]) task.save() feeditem = TaskRequest(message='A task was added to a goal you are working on',user=me,task=task,goal=goal) for person in goal.people: if person != me: person.feed.append(feeditem) person.save() return redirect(url_for('goaltree',goalid=goalid)) megacounts = {} for person in goal.people: counts = {'active':[],'completed':[],'missed':[]} for task in tasks: if person in task.people: counts['active'].append(task) if person in task.completed: counts['completed'].append(task) if person in task.missed: counts['missed'].append(task) megacounts[person.id] = counts return render_template('goaltreelite.html',me = me, goal = goal, tasks = tasks, today = datetime.datetime.now(), form = form, allCounts=megacounts)
def show_goals(): username = session['username'] goals = Goal.objects(username=username) return render_template_with_username("goal.html", goals=goals)
def completegoal(goalid): Goal.objects(id = goalid).update_one(pull__people = ObjectId(g.user.id)) Goal.objects(id = goalid).update_one(push__completed = ObjectId(g.user.id)) return redirect(url_for('goaltree',goalid=goalid))
def completegoal(goalid): Goal.objects(id=goalid).update_one(pull__people=ObjectId(g.user.id)) Goal.objects(id=goalid).update_one(push__completed=ObjectId(g.user.id)) return redirect(url_for('goaltree', goalid=goalid))
def removegoal(goalid): Goal.objects(id=goalid).delete() print goalid # User.objects().update_one(pull__goalrequest=ObjectId(goalid)) print User.objects(id=g.user.id).first().goalrequest return redirect(url_for('goals'))
def removegoal(goalid): Goal.objects(id=goalid).delete() print goalid # User.objects().update_one(pull__goalrequest=ObjectId(goalid)) print User.objects(id = g.user.id).first().goalrequest return redirect(url_for('goals'))
def approveincentives(goalid): goal = Goal.objects(id=goalid).first() return render_template('approveincentives.html', goal=goal)
def approveincentives(goalid): goal = Goal.objects(id = goalid).first() return render_template('approveincentives.html', goal = goal)
def user(user_id): from models import User, Goal user = User.objects.get_or_404(id=user_id) goals = Goal.objects(user=user) return render_template("user/profile.html", user=user, goals=goals)
def show_goals(): username = session['username'] goals = Goal.objects(username=username) return render_template_with_username("goal.html", goals=goals)