Merge pull request #1657 from pateljannat/course-card-gradient

feat: course card gradient
This commit is contained in:
Jannat Patel
2025-07-25 18:56:50 +05:30
committed by GitHub
12 changed files with 1620 additions and 99 deletions

View File

@@ -16,13 +16,14 @@
"field_order": [
"title",
"video_link",
"tags",
"column_break_3",
"instructors",
"tags",
"column_break_htgn",
"image",
"category",
"status",
"column_break_htgn",
"image",
"card_gradient",
"section_break_7",
"published",
"published_on",
@@ -98,8 +99,7 @@
{
"fieldname": "image",
"fieldtype": "Attach Image",
"label": "Preview Image",
"reqd": 1
"label": "Preview Image"
},
{
"fieldname": "tags",
@@ -272,6 +272,12 @@
"fieldtype": "Link",
"label": "Evaluator",
"options": "Course Evaluator"
},
{
"fieldname": "card_gradient",
"fieldtype": "Select",
"label": "Color",
"options": "Red\nBlue\nGreen\nAmber\nCyan\nOrange\nPink\nPurple\nTeal\nViolet\nYellow\nGray"
}
],
"is_published_field": "published",
@@ -290,8 +296,8 @@
}
],
"make_attachments_public": 1,
"modified": "2025-05-29 12:38:01.002898",
"modified_by": "Administrator",
"modified": "2025-07-25 17:50:44.983391",
"modified_by": "sayali@frappe.io",
"module": "LMS",
"name": "LMS Course",
"owner": "Administrator",

View File

@@ -21,6 +21,7 @@ class LMSCourse(Document):
self.validate_certification()
self.validate_amount_and_currency()
self.image = validate_image(self.image)
self.validate_card_gradient()
def validate_published(self):
if self.published and not self.published_on:
@@ -73,6 +74,24 @@ class LMSCourse(Document):
if self.paid_certificate and (cint(self.course_price) <= 0 or not self.currency):
frappe.throw(_("Amount and currency are required for paid certificates."))
def validate_card_gradient(self):
if not self.image and not self.card_gradient:
colors = [
"Red",
"Blue",
"Green",
"Yellow",
"Orange",
"Pink",
"Amber",
"Violet",
"Cyan",
"Teal",
"Gray",
"Purple",
]
self.card_gradient = random.choice(colors)
def on_update(self):
if not self.upcoming and self.has_value_changed("upcoming"):
self.send_email_to_interested_users()

View File

@@ -565,10 +565,13 @@ def get_courses_under_review():
def validate_image(path):
if path and "/private" in path:
file = frappe.get_doc("File", {"file_url": path})
file.is_private = 0
file.save()
return file.file_url
frappe.db.set_value(
"File",
{"file_url": path},
"is_private",
0,
)
return path.replace("/private", "")
return path
@@ -1097,6 +1100,7 @@ def get_course_fields():
"title",
"tags",
"image",
"card_gradient",
"short_introduction",
"published",
"upcoming",