Пример #1
0
    def GET(self, courseid):
        """ GET request """

        if User.is_logged_in():
            try:
                course = FrontendCourse(courseid)
                registration_uncomplete = not course.is_open_to_user(User.get_username(), course.is_group_course())
                if registration_uncomplete and course.can_students_choose_group():
                    raise web.seeother("/group/"+courseid)
                elif registration_uncomplete:
                    return renderer.course_unavailable()

                last_submissions = course.get_user_last_submissions(one_per_task=True)
                except_free_last_submissions = []
                for submission in last_submissions:
                    try:
                        submission["task"] = course.get_task(submission['taskid'])
                        except_free_last_submissions.append(submission)
                    except:
                        pass

                return renderer.course(course, except_free_last_submissions)
            except:
                if web.config.debug:
                    raise
                else:
                    raise web.notfound()
        else:
            return renderer.index(False)
Пример #2
0
    def call_main(self):
        """ Display main page (only when logged) """

        username = User.get_username()

        # Handle registration to a course
        user_input = web.input()
        registration_status = None
        if "register_courseid" in user_input and user_input["register_courseid"] != "":
            try:
                course = FrontendCourse(user_input["register_courseid"])
                if not course.is_registration_possible(username):
                    registration_status = False
                else:
                    registration_status = course.register_user(username, user_input.get("register_password", None))

                if course.is_group_course() and course.can_students_choose_group():
                    raise web.seeother("/group/"+course.get_id())
            except:
                registration_status = False
        if "unregister_courseid" in user_input:
            try:
                course = FrontendCourse(user_input["unregister_courseid"])
                course.unregister_user(username)
            except:
                pass

        # Display
        last_submissions = get_user_last_submissions({}, 5, True)
        except_free_last_submissions = []
        for submission in last_submissions:
            try:
                submission["task"] = FrontendCourse(submission['courseid']).get_task(submission['taskid'])
                except_free_last_submissions.append(submission)
            except:
                pass

        all_courses = FrontendCourse.get_all_courses()

        open_courses = {courseid: course for courseid, course in all_courses.iteritems() if course.is_open_to_user(username)}
        open_courses = OrderedDict(sorted(open_courses.iteritems(), key=lambda x: x[1].get_name()))

        registerable_courses = {courseid: course for courseid, course in all_courses.iteritems() if
                                not course.is_open_to_user(username) and course.is_registration_possible(username)}
        registerable_courses = OrderedDict(sorted(registerable_courses.iteritems(), key=lambda x: x[1].get_name()))

        return renderer.main(open_courses, registerable_courses, except_free_last_submissions, registration_status)