Esempio n. 1
0
def goals(request):
    if request.user.is_authenticated():
        goals = request.user.goal_set.order_by('frequency')
    else:
        goals = [
                Goal(name="Exercise", frequency=Goal.FREQ_DAILY),
                Goal(name="Meditate", frequency=Goal.FREQ_DAILY),
                Goal(name="Floss", frequency=Goal.FREQ_WEEKLY),
                Goal(name="Read", frequency=Goal.FREQ_WEEKLY),
                Goal(name="Blog", frequency=Goal.FREQ_MONTHLY),
        ]
        for goal in goals:
            goal.get_date_count = lambda d: random.randint(0, 2)

    return r2r("index.jinja", request, {"goals": goals})
Esempio n. 2
0
def api_goal_new(request):
    if not request.user.is_authenticated(): return {"logged_out": True}
    goal_name = request.GET['name']
    goal_freq = request.GET['frequency']

    Goal(name=goal_name, frequency=goal_freq, user=request.user).save()
    return JsonResponse({})
Esempio n. 3
0
 def test_required_fields(self):
     goal = Goal(
         name="The name",
         description="The description",
         image=self.test_file,
         slug="the-slug",
     )
     expected = None
     assert expected == goal.clean_fields()
Esempio n. 4
0
def totals(request):
    totals = []
    if request.user.is_authenticated():
        r = Goal().redis
        pipe = r.pipeline()
        for k in r.keys():
            pipe.get(k)
        totals = [{'date': k, 'count': c} for k in r.keys() for c in pipe.execute()]
    return r2r("totals.jinja",request,{'totals':totals})
Esempio n. 5
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. 6
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. 8
0
 def test_has_slug(self):
     goal = Goal(slug="the-slug")
     expected = "the-slug"
     assert expected == goal.slug
Esempio n. 9
0
 def test_has_description(self):
     goal = Goal(description="The description")
     expected = "The description"
     assert expected == goal.description
Esempio n. 10
0
 def test_has_name(self):
     goal = Goal(name="The name")
     expected = "The name"
     assert expected == goal.name
Esempio n. 11
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')