-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: ticket priority: add integer value field * feat: add `sort_options` * feat: patch: integer values for ticket priorities * chore: install: change priority integer logic * fix: sort: remove cache
- Loading branch information
Showing
11 changed files
with
181 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from types import FunctionType | ||
|
||
import frappe | ||
from frappe.model.document import get_controller | ||
from frappe.query_builder import Order, Query | ||
|
||
SORT_OPTIONS_METHOD = "sort_options" | ||
DEFAULT_SORT_FIELD = "modified" | ||
DEFAULT_SORT_DIRECTION = Order.desc | ||
|
||
|
||
@frappe.whitelist() | ||
def sort_options(doctype: str): | ||
c = get_controller(doctype) | ||
|
||
if not hasattr(c, SORT_OPTIONS_METHOD): | ||
return [] | ||
|
||
return c.sort_options().keys() | ||
|
||
|
||
def apply_sort(doctype: str, order_by: str, query: Query): | ||
controller = get_controller(doctype) | ||
fallback = query.orderby(DEFAULT_SORT_FIELD, order=DEFAULT_SORT_DIRECTION) | ||
|
||
if not hasattr(controller, SORT_OPTIONS_METHOD): | ||
return fallback | ||
|
||
action = controller.sort_options().get(order_by) | ||
|
||
if isinstance(action, FunctionType): | ||
return action(query) | ||
|
||
if isinstance(action, (list, tuple)): | ||
return query.orderby(action[0], order=action[1]) | ||
|
||
if isinstance(action, str): | ||
return query.orderby(action, order=DEFAULT_SORT_DIRECTION) | ||
|
||
return fallback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.