Example #1
0
 def get(self):
     user = self.get_current_student()
     if not user:
         self.redirect('/')
         return
         
     key = db.Key(encoded=self.request.get('course'))
     course = Course.get(key)
     chapters = []
     chapter_keys = []
     for q in course.chapters:
         chapter = Chapter.get(q)
         if chapter:
             chapters.append(chapter)
             chapter_keys.append(str(chapter.key()))
     
     goto = self.request.get("goto")
     if goto == None or goto == '':
         goto = '/'
     
     template_values = {'course': course,
                        'chapters': chapters,
                        'chapter_keys': chapter_keys,
                        'goto': goto,
                        }
     write_template(self, user, 'student_course.html', template_values)
Example #2
0
    def get(self):
        user = self.get_current_user()
        if not user:
            self.redirect("/")
            return

        key = db.Key(encoded=self.request.get("key"))
        course = Course.get(key)
        class_key = db.Key(encoded=self.request.get("class"))

        goto = self.request.get("goto")
        if goto == None or goto == "":
            goto = "/"

        # if class is different copy list to the new class
        if class_key != course.parent_key():
            aclass = Class.get(class_key)
            newCourse = Course(parent=aclass)
            newCourse.name = course.name
            newCourse.chapters = course.chapters
            newCourse.count_questions()
            newCourse.put()

        self.stop_edit_course()

        self.redirect(goto)
Example #3
0
 def get(self):
     user = self.get_current_student()
     if not user:
         self.redirect('/')
         return
     
     encoded_chapter_key = self.request.get('chapter')
     chapter, encoded_chapter_key = get_chapter_by_encoded_key(encoded_chapter_key)
     
     encoded_course_key = self.request.get('course')
     course = Course.get(db.Key(encoded=encoded_course_key))
     
     if not course.has_chapter(chapter):
         self.redirect('/studentcoursepage?course='+encoded_course_key)
     
     subchapters = chapter.subchapters()
     subchapters_empty = len(subchapters) == 0
     parents = list_parents(chapter)
     parents.reverse()
     
     if chapter.text != None:
         chapter_formatted_text = mymarkdown(chapter.text)
     else:
         chapter_formatted_text = ''
         
     questions = list_questions(chapter)
     for q in questions:
         q.result = get_result(user,q)
         q.formatted_text = mymarkdown(q.text)
         
     has_questions = len(questions) > 0
     
     template_values = {
                        'subchapters': subchapters,
                        'subchapters_empty': subchapters_empty,
                        'parents' : parents,
                        'chapter_formatted_text' : chapter_formatted_text,
                        'questions' : questions,
                        'has_questions' : has_questions,
                        'course' : course,
                        }
     
     add_chapter_values(template_values, chapter)
     
     write_template(self, user, 'student_chapter.html',template_values)
Example #4
0
    def get(self):
        # check if generic janedoe account exists, if not, populate info for starting point
        student = User.query(User.ePantherID == "janedoe").fetch()
        if len(student) == 0:
            # create new course
            course_key = Course(name="CS361").put()

            # create new users
            janedoe_key = User(ePantherID="janedoe",
                               password="******",
                               isInstructor=0).put()
            jrock_key = User(ePantherID="jrock",
                             password="******",
                             isInstructor=1).put()

            # pull course info from key
            course = course_key.get()

            # update course instructors by appending an instructor
            course.instructors.append(jrock_key)
            course.put()

            # update course students by appending a student
            course.students.append(janedoe_key)
            course.put()

            # pull instructor from key and add a course
            instructor = jrock_key.get()
            instructor.courses.append(course_key)
            instructor.put()

            # pull student from key and add a course
            student = janedoe_key.get()
            student.courses.append(course_key)
            student.put()

        template = JINJA_ENVIRONMENT.get_template('HTML/Login.html')
        self.response.write(template.render())
Example #5
0
    def get(self):
        user = self.get_current_user()
        if not user:
            self.redirect("/")
            return

        key = db.Key(encoded=self.request.get("key"))
        course = Course.get(key)
        chapters = []
        chapter_keys = []
        for q in course.chapters:
            chapter = Chapter.get(q)
            if chapter:
                chapters.append(chapter)
                chapter_keys.append(str(chapter.key()))

        edit = self.request.get("edit")
        if edit == "true" and user.isTeacher():
            edit = True
            class_list = get_teacher_classes(user)
            self.start_edit_course(course)
        else:
            edit = False
            class_list = []

        goto = self.request.get("goto")
        if goto == None or goto == "":
            goto = "/"

        template_values = {
            "course": course,
            "chapters": chapters,
            "chapter_keys": chapter_keys,
            "edit": edit,
            "class_list": class_list,
            "goto": goto,
        }
        write_template(self, user, "course.html", template_values)
Example #6
0
    def post(self):
        # check for correct cookie
        name = self.request.cookies.get("name")
        if name == "ADMIN":
            # create course exists flag
            preexisting = 0

            # store form data
            course_ID = self.request.get('courseID')
            selected_instructors_list = self.request.get_all('instructors')
            selected_students_list = self.request.get_all('students')

            # check if at least one student and one instructor have been check, if not, render error message
            if len(selected_students_list) == 0 or len(
                    selected_instructors_list) == 0:
                all_instructors = User.query(User.isInstructor == 1).fetch()
                all_students = User.query(User.isInstructor == 0).fetch()

                values = {
                    "username": "******",
                    "all_instructors": all_instructors,
                    "all_students": all_students,
                    "empty_checkboxes": 1,
                }

                template = JINJA_ENVIRONMENT.get_template(
                    'HTML/Course Creation.html')
                self.response.write(template.render(values))
                return

            # check if course exists
            existingCourseList = Course.query(Course.name == course_ID).fetch()

            if len(existingCourseList) != 0:
                preexisting = 1
                existingCourse = existingCourseList[0]

                # iterate over check boxes to check if already added or to add new instructors to courses
                for i in selected_instructors_list:
                    # pull instructor from list
                    instructor = User.query(User.ePantherID == i).fetch()[0]

                    if instructor.key not in existingCourse.instructors:
                        # add course key to instructor and put back
                        instructor.courses.append(existingCourse.key)
                        instructor.put()

                        # add instructor key to course and put back
                        existingCourse.instructors.append(instructor.key)
                        existingCourse.put()

                # iterate over check boxes to add students to courses
                for s in selected_students_list:
                    student = User.query(User.ePantherID == s).fetch()[0]

                    if student.key not in existingCourse.students:
                        # add course key to student and put back
                        student.courses.append(existingCourse.key)
                        student.put()

                        # add student key to course and put back
                        existingCourse.students.append(student.key)
                        existingCourse.put()

            else:
                # create new course and retain key
                course_key = Course(name=course_ID).put()
                course = course_key.get()

                # iterate over check boxes to add instructors to courses
                for i in selected_instructors_list:
                    instructor = User.query(User.ePantherID == i).fetch()[0]

                    # add course key to instructor and put back
                    instructor.courses.append(course_key)
                    instructor.put()

                    # add instructor key to course and put back
                    course.instructors.append(instructor.key)
                    course.put()

                # iterate over check boxes to add students to courses
                for s in selected_students_list:
                    student = User.query(User.ePantherID == s).fetch()[0]

                    # add course key to student and put back
                    student.courses.append(course_key)
                    student.put()

                    # add student key to course and put back
                    course.students.append(student.key)
                    course.put()

            final_instructors_list = Course.query(
                Course.name == course_ID).fetch()[0].instructors
            final_students_list = Course.query(
                Course.name == course_ID).fetch()[0].students
            values = {
                "courseID": course_ID,
                "preexisting": preexisting,
                "addedStudents": selected_students_list,
                "addedInstructors": selected_instructors_list,
                "allStudents": final_students_list,
                "allInstructors": final_instructors_list
            }

            template = JINJA_ENVIRONMENT.get_template(
                'HTML/Course Creation Successful.html')
            self.response.write(template.render(values))

        # else redirect to login page
        else:
            self.redirect('/')