Example #1
0
def index():
    if current_user.is_authenticated:
        enrollments = current_user.enrollments(VALID_ROLES)
        student_enrollments = [e for e in enrollments if e.role == STUDENT_ROLE]
        staff_enrollments = [e.course for e in enrollments if e.role in STAFF_ROLES]

        is_staff_only = staff_enrollments and not student_enrollments

        # If not a student elsewhere - send staff members directly the admin view
        if (is_staff_only or current_user.is_admin) and not request.args.get('student'):
            if len(staff_enrollments) == 1:
                return redirect(url_for('admin.course', cid=staff_enrollments[0].id))
            return redirect(url_for('admin.list_courses'))

        all_courses = Course.query.all()
        courses = {
            'instructor': staff_enrollments,
            'current': [e.course for e in student_enrollments if e.course.active],
            'past': [e.course for e in student_enrollments if not e.course.active],
            'all': all_courses,
            'num_enrolled': len(enrollments)
        }
        displayed_courses = courses['current'] + courses['past']
        courses['all'] = [c for c in all_courses if c not in displayed_courses]
        return render_template('student/courses/index.html', **courses)
    else:
        return render_template('index.html')
Example #2
0
def get_courses(cid=None):
    if current_user.is_authenticated and current_user.is_admin:
        courses = (Course.query.order_by(Course.created.desc()).all())
    else:
        enrollments = current_user.enrollments(roles=STAFF_ROLES)
        courses = [e.course for e in enrollments]
    if not cid:
        return courses, []

    matching_courses = [c for c in courses if c.id == cid]
    if len(matching_courses) == 0:
        abort(401)
    current_course = matching_courses[0]
    return courses, current_course
Example #3
0
File: admin.py Project: gratimax/ok
def get_courses(cid=None):
    #  TODO : The decorator could add these to the routes
    if current_user.is_authenticated and current_user.is_admin:
        courses = Course.query.all()
    else:
        enrollments = current_user.enrollments(roles=STAFF_ROLES)
        courses = [e.course for e in enrollments]
    if not cid:
        return courses, []

    matching_courses = [c for c in courses if c.id == cid]
    if len(matching_courses) == 0:
        abort(401)  # TODO to actual error page
    current_course = matching_courses[0]
    return courses, current_course
Example #4
0
 def wrapper(*args, **kwargs):
     if current_user.is_authenticated:
         if current_user.is_admin:
             return func(*args, **kwargs)
         roles = current_user.enrollments(roles=STAFF_ROLES)
         if len(roles) > 0:
             if course_arg:
                 course = kwargs[course_arg]
                 if course in [r.course.id for r in roles]:
                     return func(*args, **kwargs)
             else:
                 return func(*args, **kwargs)
     else:
         return redirect(url_for("student.index"))
     flash("You are not on the course staff", "error")
     return redirect(url_for("student.index"))
Example #5
0
File: admin.py Project: gratimax/ok
 def wrapper(*args, **kwargs):
     if current_user.is_authenticated:
         if current_user.is_admin:
             return func(*args, **kwargs)
         roles = current_user.enrollments(roles=STAFF_ROLES)
         if len(roles) > 0:
             if course_arg:
                 course = kwargs[course_arg]
                 if course in [r.course.id for r in roles]:
                     return func(*args, **kwargs)
             else:
                 return func(*args, **kwargs)
     else:
         return redirect(url_for("student.index"))
     flash("You are not on the course staff", "error")
     return redirect(url_for("student.index"))
Example #6
0
File: student.py Project: kvakil/ok
def index():
    if current_user.is_authenticated:
        enrollments = current_user.enrollments(VALID_ROLES)
        student_enrollments = [e for e in enrollments if e.role == STUDENT_ROLE]
        all_courses = Course.query.all()
        courses = {
            'instructor': [e.course for e in enrollments if e.role in STAFF_ROLES],
            'current': [e.course for e in student_enrollments if e.course.active],
            'past': [e.course for e in student_enrollments if not e.course.active],
            'all': all_courses,
            'num_enrolled': len(enrollments)
        }
        displayed_courses = courses['current'] + courses['past']
        courses['all'] = [c for c in all_courses if c not in displayed_courses]
        return render_template('student/courses/index.html', **courses)
    else:
        return render_template('index.html')