Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(kb): list query #1069

Merged
merged 2 commits into from
Mar 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions desk/src/pages/desk/kb/Articles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,8 @@
ref="articleList"
:options="{
doctype: 'Article',
fields: [
'title',
'status',
'views',
'author',
'modified',
'category.category_name as category_name',
],
order_by: 'modified desc',
order_by: 'modified DESC',
limit: 20,
filters: { status: ['!=', 'Archived'] },
}"
>
<template #body="{ manager }">
Expand Down Expand Up @@ -148,7 +139,7 @@
<template #field-title="{ value, row }">
<router-link
:to="{
path: `/frappedesk/kb/articles/${row.name}/${row.title_slug}`,
path: `/frappedesk/kb/articles/${row.name}`,
}"
class="cursor-pointer text-gray-600 hover:text-gray-900"
>{{ value }}</router-link
Expand Down
4 changes: 3 additions & 1 deletion frappedesk/extends/qb.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def get_query(*args, **kwargs):
table = kwargs.get("table")
order_by_field, order_by_dir = extract_order_by(kwargs)
QBTable = frappe.qb.DocType(table)
query = query.orderby(QBTable[order_by_field], order=Order[order_by_dir])
query = query.orderby(
QBTable[order_by_field], order=Order[order_by_dir.lower()]
)

return query

Expand Down
22 changes: 22 additions & 0 deletions frappedesk/frappedesk/doctype/article/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,32 @@

import frappe
from frappe.model.document import Document
from frappe.query_builder import DocType
from frappe.utils import cint


class Article(Document):
@staticmethod
def get_list_query(query):
QBArticle = DocType("Article")
QBCategory = DocType("Category")

query = (
query.where(QBArticle.status != "Archived")
.left_join(QBCategory)
.on(QBCategory.name == QBArticle.category)
.select(QBCategory.category_name)
.select(
QBArticle.title,
QBArticle.status,
QBArticle.views,
QBArticle.author,
QBArticle.modified,
)
)

return query

def before_insert(self):
self.author = frappe.session.user

Expand Down
6 changes: 3 additions & 3 deletions frappedesk/frappedesk/doctype/category/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from frappe import _
from frappe.model.document import Document
from frappe.utils import cint
from frappe.model.naming import append_number_if_name_exists


class Category(Document):
def before_save(self):
if self.idx == -1 and self.status == "Published":
# index is only set if its not set already, this allows defining index at the time of creation itself
# if not set the index is set to the last index + 1, i.e. the category is added at the end
# index is only set if its not set already, this allows defining
# index at the time of creation itself if not set the index is set
# to the last index + 1, i.e. the category is added at the end
self.idx = cint(
frappe.db.count("Category", {"parent_category": self.parent_category})
)
Expand Down