Ejemplo n.º 1
0
    def test_goals_by_season(self):

        # 2 goals in season 1 by player 1
        goal_1 = Goal(scored_by=self.playfor_1, scored_for=self.team_1,
            game=self.game_season_1)
        goal_1.save()
        goal_2 = Goal(scored_by=self.playfor_1, scored_for=self.team_1,
            game=self.game_season_1)
        goal_2.save()
        # 1 goal by player 1 in season 2
        goal_x = Goal(scored_by=self.playfor_1, scored_for=self.team_1,
            game=self.game_season_2)
        goal_x.save()
        # 1 goal in season 2 by player 2
        goal_3 = Goal(scored_by=self.playfor_2, scored_for=self.team_1,
            game=self.game_season_2)
        goal_3.save()
        # 1 own goal in season 1 by player 3
        goal_4 = Goal(scored_by=self.playfor_3,
            scored_for=self.team_2, game=self.game_season_1)
        goal_4.save()

        self.assertIn(self.player_1, self.season_1.scorers())
        self.assertNotIn(self.player_2, self.season_1.scorers())
        self.assertNotIn(self.player_3, self.season_1.scorers())
        self.assertEqual(3, self.season_1.count_goals())
        self.assertEqual(2, self.season_1.scorers()[0].num_scored)
Ejemplo n.º 2
0
 def goal_new():
     from models import Goal
     form = NewGoalForm(request.form)
     new_status = "form"
     if request.method == "POST":
         try:
             new_goal = Goal(title=form.title.data, user=current_user.self(), description=form.description.data)
             new_goal.save()
             new_status = "success"
         except OperationError:
             new_status = "fail"
     return render_template("goal/new.html", form=form, new_status=new_status)
Ejemplo n.º 3
0
 def goal_copy(goal_id):
     from models import Goal, Milestone
     goal = Goal.objects.get_or_404(id=goal_id)
     if (goal.user.id == current_user.get_id()):
         abort(410)
     else:
         new_goal = Goal(title=goal.title, description=goal.description, user=current_user.self(), original=goal)
         new_goal.save()
         milestones = Milestone.objects(goal=goal.id)
         for milestone in milestones:
             new_milestone = Milestone(goal=new_goal, message=milestone.message)
             new_milestone.save()
         return redirect("/goal/%s" % new_goal.id)
Ejemplo n.º 4
0
def add_problem(request, patient_id):
    role = UserProfile.objects.get(user=request.user).role
    authenticated = True if (role == 'physician' or role == 'admin') else False
    if 'problem_name' in request.POST:
        problem = Problem(patient=User.objects.get(id=patient_id), problem_name=request.POST['problem_name'], concept_id=request.POST['concept_id'], authenticated=authenticated)
        problem.save()
    elif 'goal' in request.POST:
        goal = Goal(patient=User.objects.get(id=patient_id), goal=request.POST['goal'])
        goal.save()
    elif 'todo' in request.POST:
        print 'todo'
        print request.POST
        todo = ToDo(patient=User.objects.get(id=patient_id), todo=request.POST['todo'])
        todo.save()
    return HttpResponse('added')
Ejemplo n.º 5
0
Archivo: views.py Proyecto: akosel/mesh
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)
Ejemplo n.º 6
0
Archivo: views.py Proyecto: akosel/mesh
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)
Ejemplo n.º 7
0
    def save(self, current_user, goal=None):
        if goal:
            goal.updated_by = current_user

            for f in ['is_achieved', 'title']:
                if self.cleaned_data.get(f) is not None:
                    setattr(goal, f, self.cleaned_data[f])

            goal.updated_at = datetime.utcnow()
            goal.updated_by = current_user
        else:
            goal = Goal(title=self.cleaned_data.get("title", ""),
                        created_by=current_user,
                        updated_by=current_user,
                        is_achieved=self.cleaned_data.get(
                            "is_achieved", False))

        goal.save()

        return goal
Ejemplo n.º 8
0
def add_problem(request, patient_id):
    role = UserProfile.objects.get(user=request.user).role
    authenticated = True if (role == 'physician' or role == 'admin') else False
    if 'problem_name' in request.POST:
        problem = Problem(patient=User.objects.get(id=patient_id),
                          problem_name=request.POST['problem_name'],
                          concept_id=request.POST['concept_id'],
                          authenticated=authenticated)
        problem.save()
    elif 'goal' in request.POST:
        goal = Goal(patient=User.objects.get(id=patient_id),
                    goal=request.POST['goal'])
        goal.save()
    elif 'todo' in request.POST:
        # print 'todo'
        # print request.POST
        todo = ToDo(patient=User.objects.get(id=patient_id),
                    todo=request.POST['todo'])
        todo.save()
    return HttpResponse('added')
Ejemplo n.º 9
0
def add_test_data():
    mipt_team = Team(name=u"Физтех", start_date=datetime.date.today())
    mipt_team.save()

    anytime_team = Team(name=u"Энитайм", start_date=datetime.date.today())
    anytime_team.save()

    den = Person(first_name=u"Денис",
                 last_name=u"Щигельский",
                 position=Person.BACK,
                 is_active=True,
                 is_captain=False,
                 start_date=datetime.date.today(),
                 cell_phone=u"+79151164158",
                 email=u"*****@*****.**",
                 team=mipt_team)
    den.save()

    stan = Person(first_name=u"Илья",
                 last_name=u"Станиславский",
                 position=Person.HALFBACK,
                 is_active=True,
                 is_captain=False,
                 start_date=datetime.date.today(),
                 cell_phone=u"+79670614948",
                 team=mipt_team)
    stan.save()

    burov = Person(first_name=u"Александр",
                 last_name=u"Буров",
                 position=Person.FORWARD,
                 is_active=True,
                 is_captain=True,
                 start_date=datetime.date.today(),
                 cell_phone=u"89197711249",
                 team=mipt_team)
    burov.save()

    ahyan = Person(first_name=u"Ара",
                   last_name=u"Ахян",
                   position=Person.FORWARD,
                   is_active=True,
                   is_captain=True,
                   start_date=datetime.date.today(),
                   cell_phone=u"89123711249",
                   team=anytime_team)
    ahyan.save()

    mipt_anytime = Match(date=datetime.date.today(),
                     time=datetime.datetime.now(),
                     home_team=mipt_team,
                     guest_team=anytime_team,
                     guest_team_score=0,
                     home_team_score=0)
    mipt_anytime.save()

    anytime_mipt = Match(date=datetime.date.today().replace(day=30),
                     time=datetime.datetime.now(),
                     home_team=anytime_team,
                     guest_team=mipt_team,
                     guest_team_score=0,
                     home_team_score=0)
    anytime_mipt.save()

    g1 = Goal(player_scored=stan,
              player_assisted=burov,
              own_goal=False,
              match=mipt_anytime,
              minute=11,
              is_penalty=False)
    g1.save()
    print mipt_anytime.home_team_score, mipt_anytime.guest_team_score


    g2 = Goal(player_scored=stan,
              player_assisted=den,
              own_goal=False,
              match=mipt_anytime,
              minute=15,
              is_penalty=False)
    g2.save()
    print mipt_anytime.home_team_score, mipt_anytime.guest_team_score

    g3 = Goal(player_scored=burov,
              own_goal=True,
              match=mipt_anytime,
              minute=58,
              is_penalty=False)
    g3.save()
    print mipt_anytime.home_team_score, mipt_anytime.guest_team_score

    g4 = Goal(player_scored=ahyan,
              own_goal=False,
              match=mipt_anytime,
              minute=59,
              is_penalty=False)
    g4.save()
    print mipt_anytime.home_team_score, mipt_anytime.guest_team_score

    card1 = Card(type='Y',
                 person=den,
                 minute=24)
    card1.save()
Ejemplo n.º 10
0
def add(request):
	name = request.POST.get('goal', None)
	if name and name != '':
		goal = Goal(name=name, user=request.user)
		goal.save()
	return HttpResponseRedirect(reverse('user_index', kwargs={'username':request.user.username}))