Exemplo n.º 1
0
def get_context(context):
    try:
        program = frappe.form_dict['program']
    except KeyError:
        frappe.local.flags.redirect_location = '/lms'
        raise frappe.Redirect

    context.education_settings = frappe.get_single("Education Settings")
    context.program = get_program(program)
    is_strict = 0
    try:
        wela_settings = frappe.get_doc("Wela Settings")
        is_strict = wela_settings.restrict_subject_assignment
    except:
        pass
    roles = frappe.get_roles(frappe.session.user)
    if is_strict and frappe.session.user != "Administrator" and "Student" not in roles and "Instructor" in roles:
        allowed_courses = []
        assigned_courses = []
        user_assigned_courses = frappe.db.sql(
            f"SELECT course FROM tabCourses WHERE parent LIKE '%{frappe.session.user}%' AND docstatus LIKE '1'",
            as_dict=1)
        for course in user_assigned_courses:
            assigned_courses.append(course['course'])

        for course in context.program.courses:
            if course.course in assigned_courses:
                allowed_courses.append(course.course)

        if len(allowed_courses) == 1:
            tuple_list = str(tuple(allowed_courses))
            tuple_list = tuple_list.replace(",", "")
        else:
            tuple_list = str(tuple(allowed_courses))
        if len(allowed_courses) > 0:
            context.courses = frappe.db.sql(
                f"SELECT name,course_name,description,hero_image from `tabCourse` WHERE name in {tuple_list}",
                as_dict=1)
        else:
            context.courses = []
    else:
        allowed_courses = []
        for course in context.program.courses:
            if course.course not in allowed_courses:
                allowed_courses.append(course.course)
        if len(allowed_courses) == 1:
            tuple_list = str(tuple(allowed_courses))
            tuple_list = tuple_list.replace(",", "")
        else:
            tuple_list = str(tuple(allowed_courses))

        if len(allowed_courses) > 0:
            context.courses = frappe.db.sql(
                f"SELECT name,course_name,description,hero_image FROM `tabCourse` WHERE name in {tuple_list}",
                as_dict=1)
        else:
            context.courses = []

    context.has_access = utils.allowed_program_access(program)
    context.progress = get_course_progress(context.courses, context.program)
Exemplo n.º 2
0
def get_context(context):
	try:
		program = frappe.form_dict['program']
	except KeyError:
		frappe.local.flags.redirect_location = '/lms'
		raise frappe.Redirect

	context.education_settings = frappe.get_single("Education Settings")
	context.program = get_program(program)
	context.courses = [frappe.get_doc("Course", course.course) for course in context.program.courses]
	context.has_access = utils.allowed_program_access(program)
	context.progress = get_course_progress(context.courses, context.program)
Exemplo n.º 3
0
def get_context(context):
    try:
        course = frappe.form_dict['course']
        program = frappe.form_dict['program']
        topic = frappe.form_dict['topic']
    except KeyError:
        frappe.local.flags.redirect_location = '/lms'
        raise frappe.Redirect

    context.program = program
    context.course = course
    context.topic = frappe.get_doc("Topic", topic)
    context.contents = get_contents(context.topic, course, program)
    context.has_access = utils.allowed_program_access(program)
Exemplo n.º 4
0
def get_context(context):
	try:
		program = frappe.form_dict['program']
		course_name = frappe.form_dict['name']
	except KeyError:
		frappe.local.flags.redirect_location = '/lms'
		raise frappe.Redirect

	context.education_settings = frappe.get_single("Education Settings")
	course = frappe.get_doc('Course', course_name)
	context.program = program
	context.course = course

	context.topics = course.get_topics()
	context.has_access =  utils.allowed_program_access(context.program)
	context.progress = get_topic_progress(context.topics, course, context.program)
Exemplo n.º 5
0
def get_context(context):
    # Load Query Parameters
    try:
        program = frappe.form_dict['program']
        content = frappe.form_dict['content']
        content_type = frappe.form_dict['type']
        course = frappe.form_dict['course']
        topic = frappe.form_dict['topic']
    except KeyError:
        frappe.local.flags.redirect_location = '/lms'
        raise frappe.Redirect

    # Check if user has access to the content
    has_program_access = utils.allowed_program_access(program)
    has_content_access = allowed_content_access(program, content, content_type)

    if frappe.session.user == "Guest" or not has_program_access or not has_content_access:
        frappe.local.flags.redirect_location = '/lms'
        raise frappe.Redirect

    # Set context for content to be displayer
    context.content = frappe.get_doc(content_type, content).as_dict()
    context.content_type = content_type
    context.program = program
    context.course = course
    context.topic = topic
    course = frappe.get_doc('Course', context.course)
    context.topics = course.get_topics()
    content_list = []
    for t in context.topics:
        for topic_content in t.topic_content:
            content_list.append({
                'content_type': topic_content.content_type,
                'content': topic_content.content
            })

    # Set context for progress numbers
    context.position = content_list.index({
        'content': content,
        'content_type': content_type
    })
    context.length = len(content_list)

    # Set context for navigation
    context.previous = utils.get_previous_content(content_list,
                                                  context.position)
    context.next = utils.get_next_content(content_list, context.position)
Exemplo n.º 6
0
def get_context(context):
    # Load Query Parameters
    try:
        program = frappe.form_dict["program"]
        content = frappe.form_dict["content"]
        content_type = frappe.form_dict["type"]
        course = frappe.form_dict["course"]
        topic = frappe.form_dict["topic"]
    except KeyError:
        frappe.local.flags.redirect_location = "/lms"
        raise frappe.Redirect

    # Check if user has access to the content
    has_program_access = utils.allowed_program_access(program)
    has_content_access = allowed_content_access(program, content, content_type)

    if frappe.session.user == "Guest" or not has_program_access or not has_content_access:
        frappe.local.flags.redirect_location = "/lms"
        raise frappe.Redirect

    # Set context for content to be displayer
    context.content = frappe.get_doc(content_type, content).as_dict()
    context.content_type = content_type
    context.program = program
    context.course = course
    context.topic = topic

    topic = frappe.get_doc("Topic", topic)
    content_list = [{
        "content_type": item.content_type,
        "content": item.content
    } for item in topic.topic_content]

    # Set context for progress numbers
    context.position = content_list.index({
        "content": content,
        "content_type": content_type
    })
    context.length = len(content_list)

    # Set context for navigation
    context.previous = get_previous_content(content_list, context.position)
    context.next = get_next_content(content_list, context.position)
Exemplo n.º 7
0
def get_context(context):
    try:
        course = frappe.form_dict['course']
        program = frappe.form_dict['program']
        topic = frappe.form_dict['topic']
    except KeyError:
        frappe.local.flags.redirect_location = '/lms'
        raise frappe.Redirect

    context.program = program
    context.course = course
    context.topic = frappe.get_doc("Topic", topic)
    context.student = utils.get_current_student()
    course_details = frappe.get_doc('Course', course)
    context.course_topics = course_details.get_topics()

    context.contents = get_contents(context.topic, course, program)
    context.has_access = utils.allowed_program_access(program)
    context.has_super_access = utils.has_super_access()
    context.ongoing_topic = get_ongoing_topic(context.contents)
    context.total_progress = utils.get_total_program_progress(
        context.course_topics, course, context.student)
    # Get all topics
    content_list = []
    for t in context.course_topics:
        for topic_content in t.topic_content:
            content_list.append({
                'content_type': topic_content.content_type,
                'content': topic_content.content
            })

    context.length = len(content_list)
    context.completed_topics = utils.get_completed_topic_list(course)

    # Set context for progress numbers
    context.position = len(context.completed_topics)

    # Set context for navigation
    context.previous = utils.get_previous_content(content_list,
                                                  context.position)
    context.next = utils.get_next_content(content_list, context.position - 1)
Exemplo n.º 8
0
def get_context(context):
    # Load Query Parameters
    try:
        program = frappe.form_dict['program']
        content = frappe.form_dict['content']
        content_type = frappe.form_dict['type']
        course = frappe.form_dict['course']
        topic = frappe.form_dict['topic']
    except KeyError:
        frappe.local.flags.redirect_location = '/lms'
        raise frappe.Redirect

    # Check if user has access to the content
    has_program_access = utils.allowed_program_access(program)
    has_content_access = allowed_content_access(program, content, content_type)

    if frappe.session.user == "Guest" or not has_program_access or not has_content_access:
        frappe.local.flags.redirect_location = '/lms'
        raise frappe.Redirect

    # Set context for content to be displayer
    context.content = frappe.get_doc(content_type, content).as_dict()

    if content_type == "Quiz":
        allowed_to_take_quiz = 1
        context.content.allowed_to_take_quiz = allowed_to_take_quiz
        if context.content.check_exam_permit == 1:
            cleared_for_examination = frappe.db.sql(
                """select cleared_for_examination from `tabExam Students` where username=%s""",
                (frappe.session.user))

            if cleared_for_examination != ():
                allowed_to_take_quiz = cleared_for_examination[0][0]

            context.content.allowed_to_take_quiz = allowed_to_take_quiz
            # context.content.allowed_to_take_quiz = 0

    context.content.publish_date = context.content.publish_date if context.content.publish_date is not None else date.today(
    )
    context.content_type = content_type
    context.program = program
    context.course = course
    context.topic = topic
    context.student_name = get_student(frappe.session.user)
    topic = frappe.get_doc("Topic", topic)
    content_list = [{
        'content_type': item.content_type,
        'content': item.content
    } for item in topic.topic_content]

    # Set context for progress numbers
    context.position = content_list.index({
        'content': content,
        'content_type': content_type
    })
    context.length = len(content_list)

    # Set context for navigation
    context.previous = get_previous_content(content_list, context.position)
    context.next = get_next_content(content_list, context.position)
    context.uploaded_files = []
    context.uploaded_files_s3 = ""

    # Get uploaded files
    activity_name = context.content.name
    content_type = context.content.doctype
    user = escape(frappe.session.user)
    activity_name = escape(activity_name)

    if content_type == "Article":

        written_activity_info = frappe.db.sql(
            f"SELECT name,uploads,alternative_uploads from `tabWritten Activity` "
            f"WHERE activity LIKE '%{activity_name}%' "
            f"AND student='{user}'",
            as_dict=1)
        submitted_files = []
        for info in written_activity_info:
            submitted_files = frappe.db.sql(
                f"SELECT file_name,file_url,creation FROM `tabFile` WHERE owner='{user}' "
                f"AND attached_to_name='{escape(info['name'])}'"
                f" AND attached_to_doctype='Written Activity'",
                as_dict=1)
            context.uploaded_files_s3 = (
                info['uploads'] if info['uploads'] else
                "") + (info['alternative_uploads']
                       if info['alternative_uploads'] else "")
        context.uploaded_files = submitted_files

    elif content_type == "Video":
        written_activity_info = frappe.db.sql(
            f"SELECT name, uploads,alternative_uploads from `tabWritten Activity` "
            f"WHERE video LIKE '%{activity_name}%' "
            f"AND student='{user}'",
            as_dict=1)
        submitted_files = []
        for info in written_activity_info:
            submitted_files = frappe.db.sql(
                f"SELECT file_name,file_url,creation FROM `tabFile` WHERE owner='{user}' "
                f"AND attached_to_name='{escape(info['name'])}'"
                f" AND attached_to_doctype='Written Activity'",
                as_dict=1)
            context.uploaded_files_s3 = (
                info['uploads'] if info['uploads'] else
                "") + (info['alternative_uploads']
                       if info['alternative_uploads'] else "")

        context.uploaded_files = submitted_files
    else:
        context.uploaded_files = []
Exemplo n.º 9
0
def get_context(context):
    # Load Query Parameters

    try:
        program = frappe.form_dict['program']
        content = frappe.form_dict['content']
        content_type = frappe.form_dict['type']
        course = frappe.form_dict['course']
        topic = frappe.form_dict['topic']
    except KeyError:
        frappe.local.flags.redirect_location = '/lms'
        raise frappe.Redirect

    # Check if user has access to the content
    has_program_access = utils.allowed_program_access(program)
    has_content_access = allowed_content_access(program, content, content_type)

    if frappe.session.user == "Guest" or not has_program_access or not has_content_access:
        frappe.local.flags.redirect_location = '/lms'
        raise frappe.Redirect

    roles = frappe.get_roles(frappe.session.user)
    block_role = ["Student"]
    if bool(set(block_role).intersection(
            roles)) and frappe.session.user != "Administrator":
        frappe.local.flags.redirect_location = '/lms'
        raise frappe.Redirect

    # Set context for content to be displayer
    context.content = frappe.get_doc(content_type, content).as_dict()
    context.content.publish_date = context.content.publish_date if context.content.publish_date is not None else date.today(
    )
    context.content_type = content_type
    context.program = program
    context.course = course
    context.topic = topic

    topic = frappe.get_doc("Topic", topic)
    content_list = [{
        'content_type': item.content_type,
        'content': item.content
    } for item in topic.topic_content]

    # Set context for progress numbers
    context.position = content_list.index({
        'content': content,
        'content_type': content_type
    })
    context.length = len(content_list)

    # Set context for navigation
    context.previous = get_previous_content(content_list, context.position)
    context.next = get_next_content(content_list, context.position)
    context.uploaded_files = []

    # Get uploaded files
    activity_name = context.content.name
    content_type = context.content.doctype
    user = escape(frappe.session.user)
    activity_name = escape(activity_name)

    if content_type == "Article":

        written_activity_info = frappe.db.sql(
            f"SELECT name from `tabWritten Activity` "
            f"WHERE activity LIKE '%{activity_name}%' "
            f"AND student='{user}'",
            as_dict=1)
        submitted_files = []
        for info in written_activity_info:
            submitted_files = frappe.db.sql(
                f"SELECT file_name,file_url,creation FROM `tabFile` WHERE owner='{user}' "
                f"AND attached_to_name='{escape(info['name'])}'"
                f" AND attached_to_doctype='Written Activity'",
                as_dict=1)
        context.uploaded_files = submitted_files

    elif content_type == "Video":
        written_activity_info = frappe.db.sql(
            f"SELECT name from `tabWritten Activity` "
            f"WHERE video LIKE '%{activity_name}%' "
            f"AND student='{user}'",
            as_dict=1)
        submitted_files = []
        for info in written_activity_info:
            submitted_files = frappe.db.sql(
                f"SELECT file_name,file_url,creation FROM `tabFile` WHERE owner='{user}' "
                f"AND attached_to_name='{escape(info['name'])}'"
                f" AND attached_to_doctype='Written Activity'",
                as_dict=1)
        context.uploaded_files = submitted_files
    else:
        context.uploaded_files = []