Merge pull request #15363 from netchampfaris/browse-blog-by-category
feat(blog): Browse by category
This commit is contained in:
commit
a817a4ac5e
6 changed files with 107 additions and 27 deletions
|
|
@ -9,5 +9,7 @@
|
|||
"retries": {
|
||||
"runMode": 2,
|
||||
"openMode": 2
|
||||
}
|
||||
},
|
||||
"integrationFolder": ".",
|
||||
"testFiles": ["cypress/integration/*.js", "**/ui_test_*.js"]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ Cypress.Commands.add('login', (email, password) => {
|
|||
email = 'Administrator';
|
||||
}
|
||||
if (!password) {
|
||||
password = Cypress.config('adminPassword');
|
||||
password = Cypress.env('adminPassword');
|
||||
}
|
||||
cy.request({
|
||||
url: '/api/method/login',
|
||||
|
|
@ -161,7 +161,7 @@ Cypress.Commands.add('remove_doc', (doctype, name) => {
|
|||
|
||||
Cypress.Commands.add('create_records', doc => {
|
||||
return cy
|
||||
.call('frappe.tests.ui_test_helpers.create_if_not_exists', {doc})
|
||||
.call('frappe.tests.ui_test_helpers.create_if_not_exists', {doc: JSON.stringify(doc)})
|
||||
.then(r => r.message);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -159,10 +159,10 @@ class BlogPost(WebsiteGenerator):
|
|||
like_count = 0
|
||||
|
||||
if frappe.db.count('Feedback'):
|
||||
like_count = frappe.db.count('Feedback',
|
||||
like_count = frappe.db.count('Feedback',
|
||||
filters = dict(
|
||||
reference_doctype = self.doctype,
|
||||
reference_name = self.name,
|
||||
reference_doctype = self.doctype,
|
||||
reference_name = self.name,
|
||||
like = True
|
||||
)
|
||||
)
|
||||
|
|
@ -183,7 +183,6 @@ def get_list_context(context=None):
|
|||
get_list = get_blog_list,
|
||||
no_breadcrumbs = True,
|
||||
hide_filters = True,
|
||||
children = get_children(),
|
||||
# show_search = True,
|
||||
title = _('Blog')
|
||||
)
|
||||
|
|
@ -208,17 +207,34 @@ def get_list_context(context=None):
|
|||
else:
|
||||
list_context.parents = [{"name": _("Home"), "route": "/"}]
|
||||
|
||||
list_context.update(frappe.get_doc("Blog Settings").as_dict(no_default_fields=True))
|
||||
blog_settings = frappe.get_doc("Blog Settings").as_dict(no_default_fields=True)
|
||||
list_context.update(blog_settings)
|
||||
|
||||
if blog_settings.browse_by_category:
|
||||
list_context.blog_categories = get_blog_categories()
|
||||
|
||||
return list_context
|
||||
|
||||
def get_children():
|
||||
return frappe.db.sql("""select route as name,
|
||||
title from `tabBlog Category`
|
||||
where published = 1
|
||||
and exists (select name from `tabBlog Post`
|
||||
where `tabBlog Post`.blog_category=`tabBlog Category`.name and published=1)
|
||||
order by title asc""", as_dict=1)
|
||||
|
||||
def get_blog_categories():
|
||||
from pypika import Order
|
||||
from pypika.terms import ExistsCriterion
|
||||
|
||||
post, category = frappe.qb.DocType("Blog Post"), frappe.qb.DocType("Blog Category")
|
||||
return (
|
||||
frappe.qb.from_(category)
|
||||
.select(category.name, category.route, category.title)
|
||||
.where(
|
||||
(category.published == 1)
|
||||
& ExistsCriterion(
|
||||
frappe.qb.from_(post)
|
||||
.select("name")
|
||||
.where((post.published == 1) & (post.blog_category == category.name))
|
||||
)
|
||||
)
|
||||
.orderby(category.title, order=Order.asc)
|
||||
.run(as_dict=1)
|
||||
)
|
||||
|
||||
def clear_blog_cache():
|
||||
for blog in frappe.db.sql_list("""select route from
|
||||
|
|
|
|||
|
|
@ -4,16 +4,34 @@
|
|||
|
||||
{% block page_content %}
|
||||
|
||||
{{ web_block("Hero",
|
||||
values={
|
||||
'title': blog_title or _("Blog"),
|
||||
'subtitle': blog_introduction or '',
|
||||
},
|
||||
add_container=0,
|
||||
add_top_padding=0,
|
||||
add_bottom_padding=0,
|
||||
css_class="py-5"
|
||||
) }}
|
||||
<div class="row py-8">
|
||||
<div class="col-md-8">
|
||||
<div class="hero">
|
||||
<div class="hero-content">
|
||||
<h1 class="hero-title">{{ blog_title or _('Blog') }}</h1>
|
||||
<p class="hero-subtitle mb-0">{{ blog_introduction or '' }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 align-self-end">
|
||||
{%- if browse_by_category -%}
|
||||
<label for="category-select" class="sr-only">{{ _("Browse by category") }}</label>
|
||||
<select id="category-select" class="custom-select" onchange="window.location.pathname = this.value">
|
||||
<option value="" {{ not frappe.form_dict.category and "selected" or "" }} disabled>
|
||||
{{ _("Browse by category") }}
|
||||
</option>
|
||||
{%- if frappe.form_dict.category -%}
|
||||
<option value="blog">{{ _("Show all blogs") }}</option>
|
||||
{%- endif -%}
|
||||
{%- for category in blog_categories -%}
|
||||
<option value="{{ category.route }}" {{ frappe.form_dict.category == category.name and "selected" or "" }}>
|
||||
{{ _(category.title) }}
|
||||
</option>
|
||||
{%- endfor -%}
|
||||
</select>
|
||||
{%- endif -%}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="blog-list-content">
|
||||
<div class="website-list" data-doctype="{{ doctype }}" data-txt="{{ txt or '[notxt]' | e }}">
|
||||
|
|
|
|||
36
frappe/website/doctype/blog_post/ui_test_blog_post.js
Normal file
36
frappe/website/doctype/blog_post/ui_test_blog_post.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
context('Blog Post', () => {
|
||||
before(() => {
|
||||
cy.login();
|
||||
cy.visit('/app');
|
||||
});
|
||||
|
||||
it('Blog Category dropdown works as expected', () => {
|
||||
cy.create_records([
|
||||
{
|
||||
doctype: 'Blog Category',
|
||||
title: 'Category 1',
|
||||
published: 1
|
||||
},
|
||||
{
|
||||
doctype: 'Blogger',
|
||||
short_name: 'John',
|
||||
full_name: 'John Doe'
|
||||
},
|
||||
{
|
||||
doctype: 'Blog Post',
|
||||
title: 'Test Blog Post',
|
||||
content: 'Test Blog Post Content',
|
||||
blog_category: 'category-1',
|
||||
blogger: 'John',
|
||||
published: 1
|
||||
}
|
||||
]);
|
||||
cy.set_value('Blog Settings', 'Blog Settings', {browse_by_category: 1});
|
||||
cy.visit('/blog');
|
||||
cy.findByLabelText('Browse by category').select('Category 1');
|
||||
cy.location('pathname').should('eq', '/blog/category-1');
|
||||
cy.set_value('Blog Settings', 'Blog Settings', {browse_by_category: 0});
|
||||
cy.visit('/blog');
|
||||
cy.findByLabelText('Browse by category').should('not.exist');
|
||||
});
|
||||
});
|
||||
|
|
@ -11,6 +11,7 @@
|
|||
"enable_social_sharing",
|
||||
"show_cta_in_blog",
|
||||
"allow_guest_to_comment",
|
||||
"browse_by_category",
|
||||
"cta_section",
|
||||
"title",
|
||||
"subtitle",
|
||||
|
|
@ -110,14 +111,20 @@
|
|||
"default": "1",
|
||||
"fieldname": "allow_guest_to_comment",
|
||||
"fieldtype": "Check",
|
||||
"label": "Allow guest to comment"
|
||||
"label": "Allow Guest to comment"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "browse_by_category",
|
||||
"fieldtype": "Check",
|
||||
"label": "Browse by category"
|
||||
}
|
||||
],
|
||||
"icon": "fa fa-cog",
|
||||
"idx": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2021-10-28 20:44:44.143193",
|
||||
"modified": "2021-12-20 13:40:32.312459",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Website",
|
||||
"name": "Blog Settings",
|
||||
|
|
@ -142,5 +149,6 @@
|
|||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue