Beispiel #1
0
def saveEditAssignment(course_id, assignment_id):
    """process edit student form"""
    form = AssignmentForm(request.form)
    assignment = {}
    if request.method == 'POST' and form.validate():
        assignment["title"] = request.form['title']
        assignment["description"] = request.form['description']
        assignment["points"] = request.form['due']
        assignment["due"] = request.form['points']
        db_conn = db_pool.getconn()
        cursor = db_conn.cursor()
        cursor.execute(
            f"UPDATE assignment SET title = %s, description = %s, "
            f"points = %s, due = %s "
            f"WHERE assignment_id = %s;",
            (assignment['title'],
             assignment['description'],
             assignment['due'],
             assignment['points'],
             assignment_id))

        db_conn.commit()
        cursor.close()
        db_pool.putconn(db_conn)

    return redirect(
        url_for(
            'assignment',
            assignment_id=assignment_id,
            course_id=course_id))
Beispiel #2
0
def index():
    addStudentForm = StudentForm()
    addAssignmentForm = AssignmentForm()
    return render_template('gradebook.html',
                           addStudentForm=addStudentForm,
                           addAssignmentForm=addAssignmentForm,
                           students=students,
                           assignments=assignments)
Beispiel #3
0
def edit_assignment(assignment_id):

    post = Assignment.query.filter_by(id=assignment_id).first()
    if post:
        form = AssignmentForm(formdata=request.form, obj=post)
        if request.method == 'POST':
            save_changes(post, form)
            return redirect(url_for('index'))
        return render_template('edit_assignment.html', form=form)
Beispiel #4
0
def create_assignment(course_id):
    # choose course from drop down list
    # choose problems from drop downlist
    problems = Problems.query.filter_by(
        creator_id=current_user._get_current_object().id).all()
    form = AssignmentForm()
    form.problem.choices = problems
    if form.validate_on_submit():
        # write the select problem into Assignments
        assignment = Assignments(course_id=course_id,
                                 problems=form.problem.data,
                                 startdate=form.startdate.data,
                                 enddate=form.enddate.data)
        db.session.add(assignment)
        db.session.commit()
        flash('Your assignment is created!')
        return redirect(url_for('index'))
    return render_template('create_assignment.html', form=form)
Beispiel #5
0
def addAssignment():

    addStudentForm = StudentForm()
    addAssignmentForm = AssignmentForm()

    if addAssignmentForm.validate_on_submit():
        newassignment = Assignment(addAssignmentForm.name.data.strip(),
                                   addAssignmentForm.date.data.strip(),
                                   addAssignmentForm.points.data.strip())
        assignments.append(newassignment)
        # anything you print here gets printed to your terminal
        print(newassignment.name, newassignment.date, newassignment.points)
        return redirect(url_for('index'))
    return render_template('gradebook.html',
                           addStudentForm=addStudentForm,
                           addAssignmentForm=addAssignmentForm,
                           students=students,
                           assignments=assignments)
Beispiel #6
0
def create_assignment():
    form = AssignmentForm()

    if form.validate_on_submit():
        dt = time_convert(str(form.due_date.data), str(form.due_time.data))

        assignment = Assignment(class_name=form.class_name.data,
                                title=form.title.data,
                                summary=form.summary.data,
                                due=dt,
                                creator=current_user)

        db.session.add(assignment)
        db.session.commit()
        flash('Your assignment is posted!')
        return redirect(url_for('index'))

    return render_template('assignment.html',
                           title='New Assignment',
                           form=form)
Beispiel #7
0
def edit_assignment():
    teacher = Teacher.query.filter_by(id=current_user.id).first()
    blocks = teacher.blocks
    form = AssignmentForm()
    form.block.choices = [(
        block.id,
        f'{block.subject.title} {block.title}',
    ) for block in teacher.blocks]

    if request.args:
        args = request.args

        if 'd' in args:
            assignment_id = args['d']
            Assignment.query.filter_by(id=assignment_id).delete()
            db.session.commit()

            return redirect(url_for('assignments'))

        if 'a' in args:
            assignment_id = args['a']
            assignment = Assignment.query.filter_by(id=assignment_id).first()
            form.block.default = assignment.week.block_id
            form.week_number.default = assignment.week.week_number
            form.process()
            form.title.data = assignment.title
            form.description.data = assignment.description

        if form.validate_on_submit():
            assignment.title = form.title.data
            assignment.description = form.description.data
            db.session.commit()

            return redirect(url_for('assignments'))

    return render_template(
        'assignments/edit_assignment.html',
        blocks=blocks,
        assignment=assignment,
        form=form,
    )
Beispiel #8
0
def editAssignment(name, date, points):
    # replace this for loop with database query eventually to find unique assignmentID
    for i, assignment in enumerate(assignments):
        if assignment.name == name:
            assignmentID = i

    editAssignmentForm = AssignmentForm()
    return render_template('editassignment.html',
                           editAssignmentForm=editAssignmentForm,
                           name=name,
                           date=date,
                           points=points,
                           assignmentID=assignmentID)
Beispiel #9
0
def addAssignment(course):
    """display add assignment form"""
    db_conn = db_pool.getconn()
    dict_cur = db_conn.cursor(cursor_factory=extras.DictCursor)

    addAssignmentForm = AssignmentForm()

    dict_cur.close()
    db_pool.putconn(db_conn)

    return render_template(
        'addassignment.html',
        addAssignmentForm=addAssignmentForm,
        course_id=course)
Beispiel #10
0
def new_assignment():
    teacher = Teacher.query.filter_by(id=current_user.id).first()
    blocks = teacher.blocks
    weeks = Week.query.filter(Week.block.has(teacher_id=current_user.id)).all()
    form = AssignmentForm()
    form.block.choices = [(
        block.id,
        f'{block.subject.title} {block.title}',
    ) for block in teacher.blocks]

    if form.validate_on_submit():
        week = Week.query.filter_by(
            block_id=form.block.data,
            week_number=form.week_number.data,
        ).first()
        if form.end_of_week.data:
            due_date = week.end_date
        else:
            due_date = form.due_date.data
        assignment = Assignment(
            week_id=form.week_number.data,
            due_date=due_date,
            title=form.title.data,
            description=form.description.data,
        )

        week.assignments.append(assignment)
        db.session.commit()

        return redirect(url_for('new_assignment'))

    return render_template(
        'assignments/new_assignment.html',
        blocks=blocks,
        weeks=weeks,
        form=form,
    )
Beispiel #11
0
def editAssignment(assignment_id, course_id):
    """display edit student form"""
    db_conn = db_pool.getconn()
    dict_cur = db_conn.cursor(cursor_factory=extras.DictCursor)
    dict_cur.execute(
        f'SELECT * FROM assignment WHERE assignment_id = {assignment_id}')
    assignment = dict_cur.fetchone()
    dict_cur.close()
    db_pool.putconn(db_conn)

    editAssignmentForm = AssignmentForm()
    return render_template(
        'editassignment.html',
        editAssignmentForm=editAssignmentForm,
        assignment=assignment,
        course_id=course_id)
Beispiel #12
0
def profile(request, shortname=None):
    """
    Get people and their tasks and pass them to the view. Update tasks (their
    completion) depending on user POST input (which boxes they checked).
    """
    people = Person.objects.order_by('firstname')
    person = get_object_or_404(Person, shortname=shortname)
    assignments = Assignment.objects.filter(person=person)
    randimg = random.randint(1, 20)
    form = AssignmentForm(request.POST or None)

    if request.method == "POST":
        check_values = request.POST.getlist('assignment')

        for check in check_values:
            if 'mark done' in request.POST.getlist('done'):
                task = Assignment.objects.get(id=check)
                task.complete = True
                task.save()
                messages.success(request, 'Marked complete')

            if 'processing' in request.POST.getlist('processing'):
                task = Assignment.objects.get(id=check)
                task.processing = True
                task.save()
                messages.success(request, 'Moved to processing')

    context = {
        'shortname': shortname,
        'people': people,
        'person': person,
        'assignments': assignments,
        'form': form,
        'message': messages,
        'randimg': randimg
    }

    return render(request, 'app/base_profile.html', context)
Beispiel #13
0
def addNewAssignment():

    addAssignmentForm = AssignmentForm()
    return render_template('addnewassignment.html',
                           addAssignmentForm=addAssignmentForm)