예제 #1
0
    def test_add_assignments(self):
        # Add a single assignment
        datetime_format = '%Y-%m-%dT%H:%M:%SZ'
        self.course1.add_assignments(
            Assignment(1, 'hw1', '2018-01-02T23:59:00Z', None,
                       datetime_format))
        self.assertEqual(len(self.course1.assignments), 1)

        # Add multiple assignments (note that assignment added in previous test already exists, so three total)
        datetime_format = '%Y-%m-%dT%H:%M:%SZ'
        self.course1.add_assignments([
            Assignment(2, 'hw2', '2018-01-02T23:59:00Z', None,
                       datetime_format),
            Assignment(3, 'hw3', '2018-02-03T23:59:00Z', None, datetime_format)
        ])
        self.assertEqual(len(self.course1.assignments), 3)
예제 #2
0
 def setUp(self):
     student = Student('test', 1)
     course = Course(1, 'test_course')
     datetime_format = '%Y-%m-%dT%H:%M:%SZ'
     assignment = Assignment(1, 'hw1', '2018-01-02T23:59:00Z', course,
                             datetime_format)
     self.grade = Grade(student, course, assignment, 0.85)
예제 #3
0
 def add_student_assignment(self, deadline, title, description):
     """Add new assignment to student"""
     if self.assignments:
         for existing_assignment in self.assignments:
             if existing_assignment.title.lower() == title.lower():
                 return
     assignment = Assignment(deadline, title, description)
     self.assignments.append(assignment)
예제 #4
0
def new_assignment():
    data = request.get_json()
    assignment = Assignment()
    for key, val in data:
        if hasattr(assignment, key):
            setattr(assignment, key, val)

    assignment.save()
    return jsonify({"assignment": assignment.json()})
def create_assignment():
    '''
    Creates new Assignemnt obj. and updated Solutions of all Students objs. in data
    '''
    name, add_date, deadline, max_grade, solutions = get_assignment_data()

    Assignment(name, add_date, deadline, max_grade, solutions)

    Assignment.save_assignments_to_file('assignments.csv')
예제 #6
0
    def setUp(self):
        student = Student('test', 1)
        course = Course(1, 'test_course')
        datetime_format = '%Y-%m-%dT%H:%M:%SZ'
        assignment1 = Assignment(1, 'hw1', '2018-01-02T23:59:00Z', course,
                                 datetime_format)
        assignment2 = Assignment(2, 'hw2', '2018-01-02T23:59:00Z', course,
                                 datetime_format)
        assignment3 = Assignment(3, 'hw3', '2018-01-02T23:59:00Z', course,
                                 datetime_format)
        assignment4 = Assignment(4, 'hw4', '2018-01-02T23:59:00Z', course,
                                 datetime_format)
        self.grade1 = Grade(student, course, assignment1, 0.85)
        self.grade2 = Grade(student, course, assignment2, 0.75)
        self.grade3 = Grade(student, course, assignment3, 0.65)
        self.grade4 = Grade(student, course, assignment4, 0.55)

        self.enrollment = Enrollment(student, course, [self.grade1], 0.75)
예제 #7
0
    def run(self, **kwargs):
        from models.user import User
        from models.course import Course
        from models.role import Role
        from models.assignment_group import AssignmentGroup
        from models.assignment_group_membership import AssignmentGroupMembership
        from models.assignment import Assignment

        default_course = Course.query.first()

        print("Adding Teacher")
        teacher = User(first_name="Klaus",
                       last_name="Bart",
                       password=hash_password("password"),
                       confirmed_at=datetime.datetime.now(),
                       active=True,
                       email="*****@*****.**")
        db.session.add(teacher)
        db.session.flush()
        db.session.add(
            Role(name='instructor',
                 course_id=default_course.id,
                 user_id=teacher.id))

        print("Adding Student")
        student = User(first_name="Ada",
                       last_name="Bart",
                       password=hash_password("password"),
                       confirmed_at=datetime.datetime.now(),
                       active=True,
                       email="*****@*****.**")
        db.session.add(student)
        db.session.flush()
        db.session.add(
            Role(name='student',
                 course_id=default_course.id,
                 user_id=student.id))

        print("Adding basic assignments")
        basic_group = AssignmentGroup(name="First Group",
                                      course_id=default_course.id,
                                      owner_id=teacher.id)
        db.session.add(basic_group)
        db.session.flush()
        for i in range(5):
            assignment = Assignment(name="Problem {}".format(i),
                                    instructions="Complete this problem",
                                    owner_id=teacher.id,
                                    course_id=default_course.id)
            db.session.add(assignment)
            db.session.flush()
            db.session.add(
                AssignmentGroupMembership(assignment_group_id=basic_group.id,
                                          assignment_id=assignment.id))

        db.session.commit()
        print("Complete")
예제 #8
0
    def get_asns(self, dao):
        from models.assignment import Assignment

        sql = ("SELECT a.*, e.name AS employee, p.name AS project "
               "FROM assignments a "
               "LEFT JOIN employees e ON a.employee_id=e.id "
               "LEFT JOIN projects p ON a.project_id=p.id "
               "WHERE a.employee_id=?")
        vals = (self.id, )
        rex = dao.execute(sql, vals)
        return [Assignment(rec) for rec in rex] if rex else []
    def add_assignment(self):
        """
        Adds new assigments

        :return: None
        """
        students_list = UserContainer.get_instance().get_students_list()
        deadline, title, description = MentorView.return_assignment_values()
        new_assignment = Assignment(deadline, title, description)
        AssignmentContainer.get_instance().add_assignment(new_assignment)
        for student in students_list:
            student.add_student_assignment(deadline, title, description)
예제 #10
0
    def test_remove_assignments(self):
        # Add assignments (so that you can remove them for testing)
        datetime_format = '%Y-%m-%dT%H:%M:%SZ'
        self.course1.add_assignments([
            Assignment(1, 'hw1', '2018-01-02T23:59:00Z', None,
                       datetime_format),
            Assignment(2, 'hw2', '2018-02-03T23:59:00Z', None,
                       datetime_format),
            Assignment(3, 'hw3', '2018-02-03T23:59:00Z', None, datetime_format)
        ])
        self.assertEqual(len(self.course1.assignments), 3)

        # Remove a single assignment
        self.course1.remove_assignments(Assignment(1, 'hw1',
                                                   '2018-01-02T23:59:00Z',
                                                   None, datetime_format),
                                        unique_attr='lms_id')
        self.assertEqual(len(self.course1.assignments), 2)

        # Remove multiple assignments
        self.course1.remove_assignments([
            Assignment(2, 'hw2', '2018-01-02T23:59:00Z', None,
                       datetime_format),
            Assignment(3, 'hw3', '2018-02-03T23:59:00Z', None, datetime_format)
        ],
                                        unique_attr='lms_id')
        self.assertEqual(len(self.course1.assignments), 0)
예제 #11
0
def upload(user_id, course_title, post_id):
    user = User.get_or_none(User.id == user_id)
    course = Course.get_or_none(Course.title == course_title)
    thread = Thread.get_or_none(Thread.course_id == course.id)

    post =  Post.get_or_none(Post.file_path != 'NULL', Post.thread_id == thread.id)
    
    params = request.form

    title = params.get("title")

    info = StudentCourse.get_or_none(StudentCourse.student_id == user_id, StudentCourse.course_name_id == course.id)
    
    if info:
        if current_user.id == user.id:
            # We check the request.files object for a user_file key. (user_file is the name of the file input on our form). If it's not there, we return an error message.
            if "assignment" not in request.files:
                flash("No file provided!", "danger")
                return redirect(url_for('posts.show', course_name=course_title, user_id=current_user.id, post_id = post.id))
            
            # If the key is in the object, we save it in a variable called file.
            file = request.files["assignment"]

            # we sanitize the filename using the secure_filename helper function provided by the werkzeurg.security module.
            # file.filename = secure_filename(file.filename)

            # get path to image on S3 bucket using function in helper.py
            file_path = upload_file_to_s3(file, user.username)
            
            new_assignment = Assignment(title=title, info_id=info.id, file_path=file_path, post_id=post.id)
            
            if new_assignment.save():
                flash("Successfully uploaded!","success")
                return redirect(url_for('posts.show', course_name=course_title, user_id=current_user.id, post_id = post.id))  # then redirect to profile page
            else:
                flash("Upload failed. Please try again!", "danger")
                return redirect(url_for('posts.show', course_name=course_title, user_id=current_user.id, post_id = post.id))
        else:
            flash("Cannot upload assignments for other users", "danger")
            return redirect(url_for('posts.show', course_name=course_title, user_id=current_user.id, post_id = post.id))
            
    else:
        flash("Failed to upload!", "danger")
        return redirect(url_for('posts.show', course_name=course_title, user_id=current_user.id, post_id = post.id))
예제 #12
0
    def save(self):
        from dal.dao import Dao
        from models.assignment import Assignment
        import wx

        form_values = self.get_form_values()
        if self.is_valid(form_values):
            try:
                if self.asn:
                    self.asn.from_dict(form_values)
                    self.asn.update(Dao())
                else:
                    self.asn = Assignment(form_values)
                    self.asn.add(Dao())
            except Exception as ex:
                vl.show_errmsg(None, str(ex))
                return

            wx.MessageBox('Assignment saved!', 'Hallelujah!', wx.OK)
            self.view.Parent.Close()
def AssignmentCreate(class_code):
    if request.method == "GET":
        session["class_code"] = class_code
        return render_template("assignment/assignment_create.html")
    elif request.method == "POST":
        assignment_name = request.form.get("assignment_name")
        assignment_desc = request.form.get("assignment_desc")
        assignment_input_format = request.form.get("assignment_input_format")
        assignment_output_format = request.form.get("assignment_output_format")

        assignment_input_cases = [
            request.form.get(k) if request.form.get(k) != "" else None
            for k in request.form.keys()
            if k.startswith("assignment_input_case_")
        ]
        assignment_input_cases = "---".join(
            [str(x) for x in assignment_input_cases if x])

        assignment_output_cases = [
            request.form.get(k) if request.form.get(k) != "" else None
            for k in request.form.keys()
            if k.startswith("assignment_output_case_")
        ]
        assignment_output_cases = "---".join(
            [str(x) for x in assignment_output_cases if x])

        # print(assignment_input_cases, assignment_output_cases)

        assignment_constraints = request.form.get("assignment_constraints")
        assignment_deadline = request.form.get('assignment_deadline')
        assignment_deadline = datetime.strptime(assignment_deadline,
                                                "%Y-%m-%dT%H:%M")

        user = GetUser(session["email"])

        # return redirect(url_for("classroom_main", class_code=class_code))

        if session.get("class_code") is None:
            flash("Classroom not selected while creating assignment!", "info")
            return redirect(url_for("dashboard"))

        class_code = session["class_code"]
        classroom = Classroom.query.filter_by(code=class_code).first()
        if classroom is None:
            flash("No class found!", "danger")
            return redirect(url_for("dashboard"))

        if not classroom in user.classrooms:
            flash("Access denied to this classroom!", "warning")
            return redirect(url_for("dashboard"))

        assignment = Assignment(assignment_name,
                                assignment_desc,
                                classroom=classroom)
        assignment.update(input_format=assignment_input_format,
                          output_format=assignment_output_format)
        assignment.update(input_cases=assignment_input_cases,
                          output_cases=assignment_output_cases)
        assignment.update(constraints=assignment_constraints,
                          deadline=assignment_deadline)

        db.session.add(assignment)
        db.session.commit()

        # Create assignment upload folder
        if not os.path.exists(os.path.join(SUBMISSION_FOLDER,
                                           assignment.code)):
            os.mkdir(os.path.join(SUBMISSION_FOLDER, assignment.code))

        flash("Assignment created successfully!", "success")
        return redirect(
            url_for("assignment_main", assignment_code=assignment.code))
def fetch_rows(table, criteria, connection):
    objs = []

    try:
        cur = connection.cursor()

        #--- SPLIT NULLS FROM NOT NULLS + COMMON WORK---#
        null_criteria = {}
        deleters = []

        for key in criteria:
            if (criteria[key] is None):
                null_criteria[key] = None
                deleters.append(key)

        for key in deleters:
            criteria.pop(key, None)

        null_phrase = ('IS NULL AND '.join(null_criteria.keys())) + " IS NULL "
        not_null_phrase = '= %s AND '.join(criteria.keys()) + "= %s"

        if (null_criteria and not criteria):
            crit_phrase = " WHERE " + null_phrase
        elif (criteria and not null_criteria):
            crit_phrase = " WHERE " + not_null_phrase
        elif (criteria and null_criteria):
            crit_phrase = " WHERE " + null_phrase + "AND " + not_null_phrase
        else:
            crit_phrase = ""
        #--------------------------------#

        if (table == "in"):

            select_phrase = "SELECT * FROM instructors"
            sql = select_phrase + crit_phrase

            cur.execute(sql, (list(criteria.values())))

            row = cur.fetchone()

            while row is not None:
                instructor = Instructor(row[0], row[1], row[2], row[3], row[4],
                                        row[5], row[6])
                objs.append(instructor)
                row = cur.fetchone()

        if (table == "co"):
            select_phrase = "SELECT * FROM courses"
            sql = select_phrase + crit_phrase

            cur.execute(sql, (list(criteria.values())))

            row = cur.fetchone()

            while row is not None:
                course = Course(row[0], row[1], row[2], row[3], row[4], row[5],
                                row[6], row[7], row[8])
                objs.append(course)
                row = cur.fetchone()

        if (table == "st"):
            select_phrase = "SELECT * FROM students"
            sql = select_phrase + crit_phrase

            #print(cur.mogrify(sql, (list(criteria.values()))))
            cur.execute(sql, (list(criteria.values())))

            row = cur.fetchone()

            while row is not None:
                student = Student(row[0], row[1], row[2], row[3], row[4],
                                  row[5])
                objs.append(student)
                row = cur.fetchone()

        if (table == "cs"):
            select_phrase = "SELECT * FROM coursestudents"
            sql = select_phrase + crit_phrase

            cur.execute(sql, (list(criteria.values())))

            row = cur.fetchone()

            while row is not None:
                coursestudent = Coursestudent(row[0], row[1])
                objs.append(coursestudent)
                row = cur.fetchone()

        if (table == "as"):
            select_phrase = "SELECT * FROM assignments"
            sql = select_phrase + crit_phrase

            cur.execute(sql, (list(criteria.values())))

            row = cur.fetchone()

            while row is not None:
                assignment = Assignment(row[0], row[1], row[2], row[3], row[4],
                                        row[5], row[6], row[7], row[8], row[9])
                objs.append(assignment)
                row = cur.fetchone()

        if (table == "su"):
            select_phrase = "SELECT * FROM submissions"
            sql = select_phrase + crit_phrase

            cur.execute(sql, (list(criteria.values())))

            row = cur.fetchone()

            while row is not None:
                submission = Submission(row[0], row[1], row[2], row[3], row[4],
                                        row[5], row[6], row[7])
                objs.append(submission)
                row = cur.fetchone()

        if (table == "com"):
            select_phrase = "SELECT * FROM comments"
            sql = select_phrase + crit_phrase

            cur.execute(sql, (list(criteria.values())))

            row = cur.fetchone()

            while row is not None:
                comment = Comment(row[0], row[1], row[2], row[3])
                objs.append(comment)
                row = cur.fetchone()

        connection.commit()
        cur.close()

    except Exception as error:
        print(error)

    return objs
예제 #15
0
 def setUp(self):
     datetime_format = '%Y-%m-%dT%H:%M:%SZ'
     self.assignment1 = Assignment(1, 'hw1', '2018-01-02T23:59:00Z', None,
                                   datetime_format)
예제 #16
0
                    Student(name=student['name'], lms_id=student['lms_id'])
                    for student in students_dict
                ]
                course.add_students(students)

                assignments_dict = lms_obj.get_course_assignments(
                    course.lms_id)
                # Check to make sure the course actually has assignments (for example, MATH 4157 does not),
                # then add them to the course object
                if not assignments_dict:
                    assignments = []
                else:
                    assignments = [
                        Assignment(
                            assignment['lms_id'],
                            assignment['name'],
                            assignment['due_date'],
                            course,
                            datetime_format=school_config.DATETIME_FORMAT)
                        for assignment in assignments_dict
                    ]
                course.add_assignments(assignments)

                # Get grades for all assignments, arranged by student
                grades_dict = lms_obj.get_course_grades(
                    course.lms_id, students)
                # Get overall grades for all students (cumulative grade)
                current_scores_dict = lms_obj.get_current_scores(course.lms_id)
                # Create an Enrollment object for each student with all of their assignments,
                # along with their current grade
                if students is not None:
                    for student in students: