Skip to content

Commit

Permalink
refactor(kb): list query (#1069)
Browse files Browse the repository at this point in the history
* refactor: article list: move fields and filters to api
* fix: remove slug from `frappedesk/article`
  • Loading branch information
ssiyad authored Mar 19, 2023
1 parent 90e2206 commit 608bb97
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
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

0 comments on commit 608bb97

Please sign in to comment.