Esempio n. 1
0
def incomplete_tasks():
    # If the visitor is not logged in as a user:
    # Then redirect them to the login page
    if 'username' not in session:
        return redirect(url_for('login'))

    # if the request method is post
    if request.method == 'POST':
        # Then retrieve the username from the session and find its user
        user = User.get(User.name == session['username'])
        # Retrieve the task_id from the form submission
        # and use it to find the associated task
        task = Task.get(request.form['task_id'] == Task.id)
        # Update the task to indicate that it has been completed
        # at datetime.now() by the current user.
        # update is a peewee function
        task.update(performed_by=user.name, performed=datetime.now())
        #task.execute() # throws an error
        print(type(task))
        Task.update(performed=datetime.now(), performed_by=user)\
            .where(Task.id == request.form['task_id'])\
            .execute()

    # Retrieve a list of all incomplete tasks & pass to renderer
    incomplete = Task.select().where(Task.performed.is_null())
    return render_template('incomplete.jinja2', tasks=incomplete)
Esempio n. 2
0
def incomplete_tasks():
    if 'username' not in session:
        return redirect(url_for('login'))
    if request.method == "POST":
        user = User.select().where(User.name == session['username']).get()
        Task.update(performed=datetime.now(), performed_by=user)\
            .where(Task.id==request.form['task_id'])\
                .execute()
    return render_template('incomplete.jinja2',
                           tasks=Task.select().where(Task.performed.is_null()))
Esempio n. 3
0
def incomplete():
    if 'username' not in session:
        return redirect(url_for('login'))

    if request.method == "POST":
        user = User.select().where(User.username == session["username"]).get()
        Task.update(completed=datetime.now(), completed_by=user).where(
            Task.id == request.form["task_id"]).execute()

    return render_template("incomplete.jinja2",
                           tasks=Task.select().where(
                               Task.completed_by.is_null()))
Esempio n. 4
0
def incomplete_tasks():
	"""Creates the Incomplete Tasks webpage (http://localhost:5000/incomplete)"""
	if 'username' not in session:
		return redirect(url_for('login'))

	if request.method == 'POST':
		user = User.select().where(User.name == session['username']).get()

		Task.update(performed=datetime.now(), performed_by=user)\
		    .where(Task.id == request.form['task_id'])\
		    .execute()

	return render_template('incomplete.html', tasks=Task.select().where(Task.performed.is_null()))
Esempio n. 5
0
def debug():
    if request.method == 'POST' and request.form[
            'debug_action'] == 'mark_all_as_incomplete':
        Task.update(performed=None).execute()
        Task.update(performed_by=None).execute()
        return redirect(url_for('all_tasks'))

    # username = "******"
    # if 'username' not in session:
    #     username = "******"
    # else:
    # username = str(session.get('current_user'))
    username = session['current_user']

    return render_template('debug.jinja2', user=username)
Esempio n. 6
0
def incomplete_tasks():
    if 'username' not in session:
        return redirect(url_for('login'))
    # If the visitor is not logged in as a user:
    # Then redirect them to the login page

    if request.method == 'POST':
        user = User.select().where(User.name == session['username']).get()

        Task.update(performed=datetime.now(), performed_by=user) \
            .where(Task.id == request.form['task_id']) \
                .execute()

    return render_template('incomplete.jinja2',
                           tasks=Task.select().where(Task.performed.is_null()))
Esempio n. 7
0
def incomplete_tasks():
    if 'username' not in session:
        return redirect(url_for('login'))
    else:
        if request.method == 'POST':
            try:
                user = User.get(User.name == session['username'][0])
            except model.DoesNotExist:
                user = None

            Task.update(performed=datetime.now(), performed_by=user).where(
                Task.id == request.form['task_id']).execute()

        return render_template('incomplete.jinja2',
                               tasks=Task.select().where(
                                   Task.performed.is_null()))
Esempio n. 8
0
def incomplete_tasks():
    """
    Base on the user's login status display the login page or the incomplete
    task page.
    :return: The login or incomplete task page
    """
    if 'username' not in session:
        return redirect(url_for('login'))

    if request.method == 'POST':
        user = User.select().where(User.name == session['username']).get()

        Task.update(performed=datetime.now(), performed_by=user)\
            .where(Task.id == request.form['task_id'])\
            .execute()

    return render_template('incomplete.jinja2', tasks=Task.select().where(Task.performed.is_null()))
Esempio n. 9
0
def incomplete_tasks():
    # If the visitor is not logged in as a user:
    # Then redirect them to the login page
    """
    If the request method is POST
    # Then retrieve the username from the session and find the associated user
    # Retrieve the task_id from the form submission and use it to find the
    associated task # Update the task to indicate that it has been completed
    at datetime.now() by the current user # Retrieve a list of all incomplete
    tasks # Render the incomplete.jinja2 template, injecting in the list of
    all incomplete tasks
    """
    msg = ""
    username = ""
    if session.get('current_user') == None:
        username = '******'
        msg = username
    else:
        username = session.get('current_user')
        msg = "User: "******"task_id = " + task_id

        # user = User.select().where(User.name == username)
        user2 = User.select().where(User.name == username).get()

        # AttributeError: 'User' object has no attribute '_hash'
        # assert user == user2, "Are these equal?"

        Task.update(performed=datetime.now()).where(
            Task.id == task_id).execute()
        Task.update(performed_by=user2).where(Task.id == task_id).execute()

        # user = User.get(User.name == input_name)
        # Task.update(performed=datetime.now(), performed_by=user)\
        #     .where(Task.id = request.form['task_id'])\
        #     .execute()

    return render_template('incomplete.jinja2',
                           debug=msg,
                           tasks=Task.select().where(Task.performed.is_null()))
Esempio n. 10
0
def incomplete_tasks():
    # If the visitor is not logged in as a user:
    # Then redirect them to the login page
    if 'username' not in session:
        return redirect(url_for('login'))

    # If the request method is POST
    # Then retrieve the username from the session and find the associated user
    # Retrieve the task_id from the form submission and use it to find the associated task
    # Update the task to indicate that it has been completed at datetime.now() by the current user
    # Retrieve a list of all incomplete tasks
    # Render the incomplete.jinja2 template, injecting in the list of all incomplete tasks
    if request.method == 'POST':
        user = User.select().where(User.name == session['username']).get()

        Task.update(performed=datetime.now(), performed_by=user)\
            .where(Task.id ==request.form['task_id'])\
            .execute()

    return render_template('incomplete.jinja2',
                           tasks=Task.select().where(Task.performed.is_null()))