-
-
Notifications
You must be signed in to change notification settings - Fork 152
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
Apply category sort order on analysis specifications #2191
base: 2.x
Are you sure you want to change the base?
Changes from all commits
15bcbdc
425244d
1541f72
a3f930c
8fc4376
a7210d5
d88d2fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,8 @@ | |
from plone.memoize import view | ||
from Products.Archetypes.Registry import registerWidget | ||
from Products.Archetypes.Widget import TypesWidget | ||
from Products.CMFCore.utils import getToolByName | ||
|
||
|
||
|
||
class AnalysisSpecificationView(BikaListingView): | ||
|
@@ -43,7 +45,6 @@ class AnalysisSpecificationView(BikaListingView): | |
|
||
def __init__(self, context, request): | ||
super(AnalysisSpecificationView, self).__init__(context, request) | ||
|
||
self.catalog = "senaite_catalog_setup" | ||
self.contentFilter = { | ||
"portal_type": "AnalysisService", | ||
|
@@ -188,8 +189,25 @@ def get_dynamic_analysisspecs(self): | |
return self.dynamic_spec.get_by_keyword() | ||
|
||
def folderitems(self): | ||
"""Sort by Categories | ||
""" | ||
|
||
bsc = getToolByName(self.context, "senaite_catalog_setup") | ||
self.an_cats = bsc( | ||
portal_type="AnalysisCategory", | ||
sort_on="sortable_title") | ||
self.an_cats_order = dict([ | ||
(b.Title, "{:04}".format(a)) | ||
for a, b in enumerate(self.an_cats)]) | ||
|
||
items = super(AnalysisSpecificationView, self).folderitems() | ||
self.categories.sort() | ||
|
||
|
||
if self.show_categories_enabled(): | ||
self.categories = map(lambda x: x[0], | ||
sorted(self.categories, key=lambda x: x[1])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, above you have already all categories in the right order. It would make more sense to simply filter out those that are not found instead of sorting the found ones afterwards. from bika.lims import api
from senaite.core.catalog import SETUP_CATALOG
catalog = api.get_tool(SETUP_CATALOG)
all_categories = catalog({"portal_type": "AnalysisCategory", "sort_on: "sortable_title"})
sorted_categories = filter(lambda cat: api.get_title(cat) in self.found_categories, all_categories)
self.categories = map(api.get_object, sorted_categories) Note: This code is not tested;) |
||
else: | ||
self.categories.sort() | ||
return items | ||
|
||
def folderitem(self, obj, item, index): | ||
|
@@ -207,6 +225,8 @@ def folderitem(self, obj, item, index): | |
url = api.get_url(obj) | ||
title = api.get_title(obj) | ||
keyword = obj.getKeyword() | ||
cat = obj.getCategoryTitle() | ||
cat_order = self.an_cats_order.get(cat) | ||
|
||
# dynamic analysisspecs | ||
dspecs = self.get_dynamic_analysisspecs() | ||
|
@@ -221,8 +241,8 @@ def folderitem(self, obj, item, index): | |
# get the category | ||
if self.show_categories_enabled(): | ||
category = obj.getCategoryTitle() | ||
if category not in self.categories: | ||
self.categories.append(category) | ||
if (category,cat_order) not in self.categories: | ||
self.categories.append((category,cat_order)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please simply collect here the category title in a instance variable, e.g.:
This one is used later to filter out the already sorted categories. |
||
item["category"] = category | ||
|
||
item["Title"] = title | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use simply
catalog
as variable, because this catalog is no longer namedbika_setup_catalog
. You might also consider to useapi.get_tool
instead ofgetToolByName