feat: set a random color is no color or image is present
This commit is contained in:
@@ -145,7 +145,7 @@ const props = defineProps({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const getGradientColor = () => {
|
const getGradientColor = () => {
|
||||||
let color = props.course.card_gradient.toLowerCase()
|
let color = props.course.card_gradient?.toLowerCase() || 'blue'
|
||||||
let colorMap = theme.backgroundColor[color]
|
let colorMap = theme.backgroundColor[color]
|
||||||
return `linear-gradient(to top right, black, ${colorMap[400]})`
|
return `linear-gradient(to top right, black, ${colorMap[400]})`
|
||||||
/* return `bg-gradient-to-br from-${color}-100 via-${color}-200 to-${color}-400` */
|
/* return `bg-gradient-to-br from-${color}-100 via-${color}-200 to-${color}-400` */
|
||||||
|
|||||||
@@ -277,7 +277,7 @@
|
|||||||
"fieldname": "card_gradient",
|
"fieldname": "card_gradient",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"label": "Card Gradient",
|
"label": "Card Gradient",
|
||||||
"options": "Red\nBlue\nGreen\nAmber\nCyan\nOrange\nPink\nPurple\nTeal\nViolet\nYellow"
|
"options": "Red\nBlue\nGreen\nAmber\nCyan\nOrange\nPink\nPurple\nTeal\nViolet\nYellow\nGray"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"is_published_field": "published",
|
"is_published_field": "published",
|
||||||
@@ -296,7 +296,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"make_attachments_public": 1,
|
"make_attachments_public": 1,
|
||||||
"modified": "2025-07-23 18:40:28.707756",
|
"modified": "2025-07-25 17:30:48.553707",
|
||||||
"modified_by": "sayali@frappe.io",
|
"modified_by": "sayali@frappe.io",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "LMS Course",
|
"name": "LMS Course",
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class LMSCourse(Document):
|
|||||||
self.validate_certification()
|
self.validate_certification()
|
||||||
self.validate_amount_and_currency()
|
self.validate_amount_and_currency()
|
||||||
self.image = validate_image(self.image)
|
self.image = validate_image(self.image)
|
||||||
|
self.validate_card_gradient()
|
||||||
|
|
||||||
def validate_published(self):
|
def validate_published(self):
|
||||||
if self.published and not self.published_on:
|
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):
|
if self.paid_certificate and (cint(self.course_price) <= 0 or not self.currency):
|
||||||
frappe.throw(_("Amount and currency are required for paid certificates."))
|
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):
|
def on_update(self):
|
||||||
if not self.upcoming and self.has_value_changed("upcoming"):
|
if not self.upcoming and self.has_value_changed("upcoming"):
|
||||||
self.send_email_to_interested_users()
|
self.send_email_to_interested_users()
|
||||||
|
|||||||
@@ -565,10 +565,13 @@ def get_courses_under_review():
|
|||||||
|
|
||||||
def validate_image(path):
|
def validate_image(path):
|
||||||
if path and "/private" in path:
|
if path and "/private" in path:
|
||||||
file = frappe.get_doc("File", {"file_url": path})
|
frappe.db.set_value(
|
||||||
file.is_private = 0
|
"File",
|
||||||
file.save()
|
{"file_url": path},
|
||||||
return file.file_url
|
"is_private",
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
return path.replace("/private", "")
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user