Example #1
0
def assignment_delete(username, course, assignment):
    """
        GET - Show the assignment delete form

        POST - Validate the form and delete the assignment
    """

    form = None
    if g.user.is_authenticated():
        if g.user.username == username:
            asn_id = [ a.assignment_id for a in
                        Assignment.get_assignments(username, course)
                        if a.assignment_id == assignment]
            form = AssignmentDeleteForm()
            course_id = [ c.course_id for c in g.user.get_courses()
                    if c.title == course and c.instructor_id == g.user.user_id]
            if course_id[0] and form.validate_on_submit():
                rc = Assignment.delete_assignment()
                return redirect(url_for('course_home', username=username,
                                course=course))
            else:
                return render_template('assignment/delete.html', course=course,
                                        form=form, assignment=assignment)
        else:
            # unauthorized user
            flash('You can not delete that.')
            return redirect(url_for('course_home', username=username,
                            course=course))
    else:
        return redirect(url_for('login'))