feat: added featured checkbox and validation
This commit is contained in:
parent
78cb3a9c17
commit
5f4cf98ee2
2 changed files with 21 additions and 3 deletions
|
|
@ -10,12 +10,13 @@
|
|||
"title",
|
||||
"published_on",
|
||||
"published",
|
||||
"read_time",
|
||||
"featured",
|
||||
"disable_comments",
|
||||
"column_break_3",
|
||||
"blog_category",
|
||||
"blogger",
|
||||
"route",
|
||||
"read_time",
|
||||
"section_break_5",
|
||||
"blog_intro",
|
||||
"content_type",
|
||||
|
|
@ -143,7 +144,8 @@
|
|||
{
|
||||
"fieldname": "meta_image",
|
||||
"fieldtype": "Attach Image",
|
||||
"label": "Meta Image"
|
||||
"label": "Meta Image",
|
||||
"mandatory_depends_on": "eval:doc.featured"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_20",
|
||||
|
|
@ -167,6 +169,12 @@
|
|||
"fieldtype": "Int",
|
||||
"label": "Read Time",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "featured",
|
||||
"fieldtype": "Check",
|
||||
"label": "Featured"
|
||||
}
|
||||
],
|
||||
"has_web_view": 1,
|
||||
|
|
@ -175,7 +183,7 @@
|
|||
"is_published_field": "published",
|
||||
"links": [],
|
||||
"max_attachments": 5,
|
||||
"modified": "2020-04-30 17:32:41.055883",
|
||||
"modified": "2020-05-28 21:40:26.068480",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Website",
|
||||
"name": "Blog Post",
|
||||
|
|
|
|||
|
|
@ -39,8 +39,18 @@ class BlogPost(WebsiteGenerator):
|
|||
if self.published and not self.published_on:
|
||||
self.published_on = today()
|
||||
|
||||
if self.featured:
|
||||
if not self.meta_image:
|
||||
frappe.throw(_("A featured post must have a cover image"))
|
||||
self.reset_featured_for_other_blogs()
|
||||
|
||||
self.set_read_time()
|
||||
|
||||
def reset_featured_for_other_blogs(self):
|
||||
all_posts = frappe.get_all("Blog Post", {"featured": 1})
|
||||
for post in all_posts:
|
||||
frappe.db.set_value("Blog Post", post.name, "featured", 0)
|
||||
|
||||
def on_update(self):
|
||||
super(BlogPost, self).on_update()
|
||||
clear_cache("writers")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue