Skip to content

Commit

Permalink
Merge pull request #17 from ONE-F-M/186663140
Browse files Browse the repository at this point in the history
[186663140] BUG FIx Can Create Course Function in ONE LMS
  • Loading branch information
mymi14s authored Dec 13, 2023
2 parents 037fa77 + 095903b commit 8699c50
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 30 deletions.
6 changes: 4 additions & 2 deletions one_lms/www/assignments/assignment.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import frappe
from frappe import _
from lms.lms.utils import can_create_courses
from lms.lms.utils import has_course_moderator_role, has_course_instructor_role



def get_context(context):
context.no_cache = 1

if not can_create_courses():
if not has_course_moderator_role() or not has_course_instructor_role():
message = "You do not have permission to access this page."
if frappe.session.user == "Guest":
message = "Please login to access this page."
Expand All @@ -21,3 +22,4 @@ def get_context(context):
context.assignment = frappe.db.get_value(
"LMS Assignment", assignment, ["title", "name", "type", "question"], as_dict=1
)

2 changes: 1 addition & 1 deletion one_lms/www/batch/learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_context(context):
context.class_info = frappe._dict(
{
"name": class_name,
"title": frappe.db.get_value("LMS Class", class_name, "title"),
"title": frappe.db.get_value("LMS Batch", class_name, "title"),
}
)

Expand Down
17 changes: 13 additions & 4 deletions one_lms/www/batch/quiz.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import frappe
from frappe.utils import cstr
from frappe import _
from lms.lms.utils import can_create_courses
from lms.lms.utils import has_course_instructor_role, has_course_moderator_role


def get_context(context):
context.no_cache = 1

if not can_create_courses():
if not has_course_moderator_role() or not has_course_instructor_role():
message = "You do not have permission to access this page."
if frappe.session.user == "Guest":
message = "Please login to access this page."
Expand All @@ -18,14 +18,23 @@ def get_context(context):
if quizname == "new-quiz":
context.quiz = frappe._dict()
else:
fields_arr = ["name", "question", "type"]

context.quiz = frappe.db.get_value(
"LMS Quiz",
quizname,
["title", "name", "max_attempts", "show_answers", "show_submission_history"],
[
"title",
"name",
"max_attempts",
"passing_percentage",
"show_answers",
"show_submission_history",
],
as_dict=1,
)

fields_arr = ["name", "question", "marks"]
context.quiz.questions = frappe.get_all(
"LMS Quiz Question", {"parent": quizname}, fields_arr, order_by="idx"
)

4 changes: 2 additions & 2 deletions one_lms/www/batch/quiz_list.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import frappe
from lms.lms.utils import can_create_courses, has_course_moderator_role
from lms.lms.utils import has_course_instructor_role, has_course_moderator_role
from frappe import _


def get_context(context):
context.no_cache = 1

if not can_create_courses():
if not has_course_moderator_role() or not has_course_instructor_role():
message = "You do not have permission to access this page."
if frappe.session.user == "Guest":
message = "Please login to access this page."
Expand Down
2 changes: 1 addition & 1 deletion one_lms/www/classes/class.html
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
{% macro Discussions(class_info) %}
<article class="class-discussion">
{% set condition = is_moderator or is_student or is_evaluator %}
{% set doctype, docname = _("LMS Class"), class_info.name %}
{% set doctype, docname = _("LMS Batch"), class_info.name %}
{% set single_thread = True %}
{% set title = "Discussions" %}
{% set cta_title = "Post" %}
Expand Down
10 changes: 5 additions & 5 deletions one_lms/www/classes/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ const add_course = (values) => {
method: "frappe.client.insert",
args: {
doc: {
doctype: "Class Course",
doctype: "Batch Course",
course: values.course,
parenttype: "LMS Class",
parenttype: "LMS Batch",
parentfield: "courses",
parent: $(".class-details").data("class"),
},
Expand Down Expand Up @@ -402,9 +402,9 @@ const add_student = (values) => {
method: "frappe.client.insert",
args: {
doc: {
doctype: "Class Student",
doctype: "Batch Student",
student: values.student,
parenttype: "LMS Class",
parenttype: "LMS Batch",
parentfield: "students",
parent: $(".class-details").data("class"),
},
Expand Down Expand Up @@ -513,7 +513,7 @@ const add_addessment = (values) => {
doctype: "LMS Assessment",
assessment_type: values.assessment_type,
assessment_name: values.assessment_name,
parenttype: "LMS Class",
parenttype: "LMS Batch",
parentfield: "assessment",
parent: $(".class-details").data("class"),
},
Expand Down
8 changes: 4 additions & 4 deletions one_lms/www/classes/class.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_context(context):
context.is_evaluator = has_course_evaluator_role()

context.class_info = frappe.db.get_value(
"LMS Class",
"LMS Batch",
class_name,
[
"name",
Expand All @@ -40,18 +40,18 @@ def get_context(context):
as_dict=True,
)

context.reference_doctype = "LMS Class"
context.reference_doctype = "LMS Batch"
context.reference_name = class_name

class_courses = frappe.get_all(
"Class Course",
"Batch Course",
{"parent": class_name},
["name", "course", "title"],
order_by="creation desc",
)

class_students = frappe.get_all(
"Class Student",
"Batch Student",
{"parent": class_name},
["name", "student", "student_name", "username"],
order_by="creation desc",
Expand Down
4 changes: 2 additions & 2 deletions one_lms/www/classes/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
{% macro ClassCards(classes) %}
<div class="lms-card-parent">
{% for class in classes %}
{% set course_count = frappe.db.count("Class Course", {"parent": class.name}) %}
{% set student_count = frappe.db.count("Class Student", {"parent": class.name}) %}
{% set course_count = frappe.db.count("Batch Course", {"parent": class.name}) %}
{% set student_count = frappe.db.count("Batch Student", {"parent": class.name}) %}

<div class="common-card-style column-card" style="min-height: 150px;">

Expand Down
10 changes: 5 additions & 5 deletions one_lms/www/classes/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ def get_context(context):
context.no_cache = 1
context.is_moderator = has_course_moderator_role()
classes = frappe.get_all(
"LMS Class",
"LMS Batch",
fields=[
"name",
"title",
"description",
"start_date",
"end_date",
"paid_class",
"paid_batch",
"seat_count",
],
)
Expand All @@ -32,15 +32,15 @@ def get_context(context):
if frappe.session.user != "Guest":
my_classes_info = []
my_classes = frappe.get_all(
"Class Student", {"student": frappe.session.user}, pluck="parent"
"Batch Student", {"student": frappe.session.user}, pluck="parent"
)

for class_ in my_classes:
my_classes_info.append(
frappe.db.get_value(
"LMS Class",
"LMS Batch",
class_,
["name", "title", "start_date", "end_date", "paid_class", "seat_count"],
["name", "title", "start_date", "end_date", "paid_batch", "seat_count"],
as_dict=True,
)
)
Expand Down
4 changes: 2 additions & 2 deletions one_lms/www/classes/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def get_context(context):
raise frappe.PermissionError(_("You don't have permission to access this page."))

context.class_info = frappe.db.get_value(
"LMS Class", class_name, ["name"], as_dict=True
"LMS Batch", class_name, ["name"], as_dict=True
)

context.courses = frappe.get_all(
"Class Course", {"parent": class_name}, pluck="course"
"Batch Course", {"parent": class_name}, pluck="course"
)

context.assessments = get_assessments(class_name, context.student.name)
Expand Down
2 changes: 1 addition & 1 deletion one_lms/www/courses/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_context(context):
redirect_to_courses_list()

if course_name == "new-course":
if not can_create_courses():
if not can_create_courses(course_name):
message = "You do not have permission to access this page."
if frappe.session.user == "Guest":
message = "Please login to access this page."
Expand Down
2 changes: 1 addition & 1 deletion one_lms/www/courses/outline.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def get_context(context):
if not frappe.db.exists("LMS Course", course_name):
redirect_to_courses_list()

if not can_create_courses():
if not can_create_courses(course_name):
message = "You do not have permission to access this page."
if frappe.session.user == "Guest":
message = "Please login to access this page."
Expand Down

0 comments on commit 8699c50

Please sign in to comment.