Esempio n. 1
0
def new(request):
    if request.POST:
        new_goal_form = AddGoalForm(request.POST)
        if new_goal_form.is_valid():
            goal = Goal()
            goal.created_by = request.user
            goal.modified_by = request.user
            goal.user = request.user
            goal.name = new_goal_form.cleaned_data['name']
            if new_goal_form.cleaned_data['specific_target'] is True:
                goal.target_amount = new_goal_form.cleaned_data['target_amount']
                goal.target_date = new_goal_form.cleaned_data['target_date']
            if new_goal_form.cleaned_data['regular_payins'] is True:
                goal.period = new_goal_form.cleaned_data['period']
                goal.period_step = new_goal_form.cleaned_data['step']
                goal.period_increment = new_goal_form.cleaned_data['increment']
            goal.status = 2 if new_goal_form.cleaned_data['regular_payins'] is True else 0
            goal.save()
            return redirect('goals_home')
    else:
        new_goal_form = AddGoalForm()
    template_variables = {
        'form': new_goal_form
    }
    return render_response(request, "goals/new.html", template_variables)
Esempio n. 2
0
def create_goal(name, group, created_by):
    goal = Goal()
    goal.name = name
    goal.short_description = "Test goal %s" % name
    goal.group_profile = group
    goal.created_by = created_by
    goal.save()
    return goal
Esempio n. 3
0
def test_create_goal(django_user_model):
    user = django_user_model.objects.create(
        username='******', password='******'
        )
    name = 'Creative Writing'
    description = 'Write creatively 3x a week for the next 3 months.'
    end_date = datetime.datetime.now() + datetime.timedelta(days=90)

    goal = Goal(user=user,
                name=name,
                description=description,
                end_date=end_date)
    goal.save()
    assert len(Goal.objects.all()) == 1
Esempio n. 4
0
def test_archive_goal(django_user_model):
    user = django_user_model.objects.create(
        username='******', password='******'
        )
    name = 'Creative Writing'
    description = 'Write creatively 3x a week for the next 3 months.'
    end_date = datetime.datetime.now() + datetime.timedelta(days=90)

    goal = Goal(user=user,
                name=name,
                description=description,
                end_date=end_date,
                active=False)
    goal.save()
    goal.archive
    assert Goal.objects.first().archived == True
def test_create_goallog(django_user_model):
    user = django_user_model.objects.create(username='******',
                                            password='******')
    name = 'Creative Writing'
    description = 'Write creatively 3x a week for the next 3 months.'
    end_date = datetime.datetime.now() + datetime.timedelta(days=90)
    goal = Goal(user=user,
                name=name,
                description=description,
                end_date=end_date)
    goal.save()

    start_time = datetime.datetime.now()
    end_time = datetime.datetime.now() + datetime.timedelta(hours=2)
    goal_log = GoalLog(goal=goal,
                       notes='some notes on how the log went.',
                       start_time=start_time,
                       end_time=end_time)
    goal_log.save()
    assert len(GoalLog.objects.all()) == 1
Esempio n. 6
0
def signup(request):
    if request.method == "POST":
        if not request.POST['email'] or not request.POST['username'] or not request.POST['password1']: # Check if email field empty
            return render(request, 'accounts/signup.html', {'error': 'Cannot leave fields blank'})

        if request.POST['password1'] == request.POST['password2']:
            # Check that email is not already taken
            try:
                profile = User.objects.get(email=request.POST['email'])
                return render(request, 'accounts/signup.html', {'error': 'Email has already been taken'})
            except:
                pass

            # Check that username is not already taken
            try:
                user = User.objects.get(username=request.POST['username'])
                return render(request, 'accounts/signup.html', {'error': 'Username has already been taken'})
            except User.DoesNotExist:
                user = User.objects.create_user(request.POST['username'], email=request.POST['email'], password=request.POST['password1'])
                login(request, user)

                # If successful sign up, create a profile
                profile = Profile()
                profile.user = request.user
                profile.save()

                # Add examples to profile
                # Example todo
                todo = Todo()
                todo.title = "Groceries"
                todo.pub_date = timezone.now()
                todo.author = request.user
                todo.point_value = 10
                todo.completed = False
                todo.save()

                todo2 = Todo()
                todo2.title = "Add a new Task!"
                todo2.pub_date = timezone.now()
                todo2.author = request.user
                todo2.point_value = 10
                todo2.completed = False
                todo2.save()

                todo3 = Todo()
                todo3.title = "Clean room"
                todo3.pub_date = timezone.now()
                todo3.author = request.user
                todo3.point_value = 10
                todo3.completed = False
                todo3.save()

                # Example Goals
                goal = Goal()
                goal.title = "Study"
                goal.amount_goal = 10
                goal.units = "hours"
                goal.amount_per_increment = 1
                goal.point_value = 25
                goal.pub_date = timezone.now()
                goal.author = request.user
                goal.current_amount_done = 0
                goal.times_completed = 0
                goal.save()

                goal2 = Goal()
                goal2.title = "Jogging"
                goal2.amount_goal = 30
                goal2.units = "miles"
                goal2.amount_per_increment = 1
                goal2.point_value = 30
                goal2.pub_date = timezone.now()
                goal2.author = request.user
                goal2.current_amount_done = 0
                goal2.times_completed = 0
                goal2.save()

                goal2 = Goal()
                goal2.title = "Pull-ups"
                goal2.amount_goal = 100
                goal2.units = "reps"
                goal2.amount_per_increment = 20
                goal2.point_value = 15
                goal2.pub_date = timezone.now()
                goal2.author = request.user
                goal2.current_amount_done = 0
                goal2.times_completed = 0
                goal2.save()

                # Example journal entry
                entry = Entry()
                entry.title = "Hello world!"
                entry.content = "Welcome to the Productivity Helper app! This is an example Journal entry, which you are free to edit or delete."
                entry.author = request.user
                entry.published_date = timezone.now()
                entry.save()

                return redirect('todos:home')
        else:
            return render(request, 'accounts/signup.html', {'error': 'Passwords did not match'})
    else:
        return render(request, 'accounts/signup.html')