Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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,
    )
Ejemplo n.º 5
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,
    )