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

Migrate AnalysisCategories to DX #2567

Merged
merged 18 commits into from
Jun 13, 2024
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
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
2.6.0 (unreleased)
------------------

- #2567 Migrate AnalysisCategories to Dexterity
- #2570 Use reference widget API in sample add form
- #2553 Migrate BatchLabels to Dexterity
- #2566 Migrate SamplePoint Latitude and Longitude fields to Location
Expand Down
2 changes: 1 addition & 1 deletion src/bika/lims/content/abstractbaseanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
from bika.lims.config import SERVICE_POINT_OF_CAPTURE
from bika.lims.content.bikaschema import BikaSchema
from bika.lims.interfaces import IBaseAnalysis
from bika.lims.interfaces import IHaveAnalysisCategory
from bika.lims.interfaces import IHaveDepartment
from bika.lims.interfaces import IHaveInstrument
from senaite.core.interfaces import IHaveAnalysisCategory
from senaite.core.permissions import FieldEditAnalysisHidden
from senaite.core.permissions import FieldEditAnalysisRemarks
from senaite.core.permissions import FieldEditAnalysisResult
Expand Down
1 change: 1 addition & 0 deletions src/bika/lims/content/analysiscategory.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
schema['description'].schemata = 'default'


# TODO: Migrated to DX - https://github.com/senaite/senaite.core/pull/2567
class AnalysisCategory(BaseContent):
implements(IAnalysisCategory, IHaveDepartment, IDeactivable)
security = ClassSecurityInfo()
Expand Down
108 changes: 1 addition & 107 deletions src/bika/lims/controlpanel/bika_analysiscategories.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,126 +18,20 @@
# Copyright 2018-2024 by it's authors.
# Some rights reserved, see README and LICENSE.

import collections

from Products.ATContentTypes.content import schemata
from Products.Archetypes import atapi
from bika.lims import api
from bika.lims import bikaMessageFactory as _
from bika.lims.browser.bika_listing import BikaListingView
from bika.lims.config import PROJECTNAME
from bika.lims.interfaces import IAnalysisCategories
from senaite.core.permissions import AddAnalysisCategory
from bika.lims.utils import get_link
from plone.app.content.browser.interfaces import IFolderContentsView
from plone.app.folder.folder import ATFolder
from plone.app.folder.folder import ATFolderSchema
from plone.app.layout.globals.interfaces import IViewView
from senaite.core.interfaces import IHideActionsMenu
from zope.interface.declarations import implements


# TODO: Separate content and view into own modules!


class AnalysisCategoriesView(BikaListingView):
implements(IFolderContentsView, IViewView)

def __init__(self, context, request):
super(AnalysisCategoriesView, self).__init__(context, request)

self.catalog = "senaite_catalog_setup"

self.contentFilter = {
"portal_type": "AnalysisCategory",
"sort_on": "sortable_title",
"sort_order": "ascending",
}

self.context_actions = {
_("Add"): {
"url": "createObject?type_name=AnalysisCategory",
"permission": AddAnalysisCategory,
"icon": "++resource++bika.lims.images/add.png"}
}

self.title = self.context.translate(_("Analysis Categories"))
self.icon = "{}/{}".format(
self.portal_url,
"/++resource++bika.lims.images/category_big.png"
)

self.show_select_row = False
self.show_select_column = True
self.pagesize = 25

self.columns = collections.OrderedDict((
("Title", {
"title": _("Category"),
"index": "sortable_title"}),
("Description", {
"title": _("Description"),
"index": "Description",
"toggle": True,
}),
("Department", {
"title": _("Department"),
"index": "department_title",
}),
("SortKey", {
"title": _("Sort Key"),
"sortable": True
}),
))

self.review_states = [
{
"id": "default",
"title": _("Active"),
"contentFilter": {"is_active": True},
"columns": self.columns.keys(),
}, {
"id": "inactive",
"title": _("Inactive"),
"contentFilter": {'is_active': False},
"columns": self.columns.keys(),
}, {
"id": "all",
"title": _("All"),
"contentFilter": {},
"columns": self.columns.keys(),
},
]

def folderitem(self, obj, item, index):
"""Service triggered each time an item is iterated in folderitems.
The use of this service prevents the extra-loops in child objects.
:obj: the instance of the class to be foldered
:item: dict containing the properties of the object to be used by
the template
:index: current index of the item
"""
obj = api.get_object(obj)
title = obj.Title()
description = obj.Description()
url = obj.absolute_url()

item["replace"]["Title"] = get_link(url, value=title)
item["Description"] = description
item["SortKey"] = obj.getSortKey()

department = obj.getDepartment()
if department:
title = department.Title()
url = department.absolute_url()
item["replace"]["Department"] = get_link(url, value=title)

return item


schema = ATFolderSchema.copy()


# TODO: Migrated to DX - https://github.com/senaite/senaite.core/pull/2567
class AnalysisCategories(ATFolder):
implements(IAnalysisCategories, IHideActionsMenu)
displayContentsTab = False
Expand Down
8 changes: 0 additions & 8 deletions src/bika/lims/controlpanel/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@
layer="bika.lims.interfaces.IBikaLIMS"
/>

<browser:page
for="bika.lims.interfaces.IAnalysisCategories"
name="folder_view"
class=".bika_analysiscategories.AnalysisCategoriesView"
permission="senaite.core.permissions.ManageBika"
layer="bika.lims.interfaces.IBikaLIMS"
/>

<browser:page
for="bika.lims.interfaces.ISampleTypes"
name="folder_view"
Expand Down
17 changes: 0 additions & 17 deletions src/bika/lims/interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,23 +1054,6 @@ def getName(self):
"""


class IHaveAnalysisCategory(Interface):
"""Marker interface for objects that have AnalysisCategory(ies) assigned
"""

def getCategory(self):
"""Returns the category(ies) assigned to this instance
"""

def getCategoryUID(self):
"""Returns the UID of the category(ies) assigned to this instance
"""

def getCategoryTitle(self):
"""Returns the title of the category(ies) assigned to this instance
"""


class IARImportFolder(Interface):
"""Marker interface for a folder that contains ARImports
TODO: Legacy type. Remove after 1.3.3
Expand Down
1 change: 0 additions & 1 deletion src/bika/lims/profiles/default/factorytool.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<type portal_type="ARReport"/>
<type portal_type="ARTemplate"/>
<type portal_type="Analysis"/>
<type portal_type="AnalysisCategory"/>
<type portal_type="AnalysisRequest"/>
<type portal_type="AnalysisService"/>
<type portal_type="AnalysisSpec"/>
Expand Down
1 change: 0 additions & 1 deletion src/bika/lims/profiles/default/propertiestool.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
<element value="ATFile"/>
<element value="Address"/>
<element value="Analysis"/>
<element value="AnalysisCategory"/>
<element value="AnalysisRequest"/>
<element value="AnalysisService"/>
<element value="AnalysisSpec"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
auditlog,AuditLog
bika_analysiscategories,AnalysisCategories
bika_analysisservices,AnalysisServices
bika_analysisspecs,AnalysisSpecs
bika_attachmenttypes,AttachmentTypes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
auditlog
bika_analysiscategories
bika_analysisservices
bika_analysisspecs
bika_artemplates
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions src/bika/lims/profiles/default/types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
<object name="ARTemplate" meta_type="Factory-based Type Information with dynamic views"/>
<object name="ARTemplates" meta_type="Factory-based Type Information with dynamic views"/>
<object name="Analysis" meta_type="Factory-based Type Information with dynamic views"/>
<object name="AnalysisCategories" meta_type="Factory-based Type Information with dynamic views"/>
<object name="AnalysisCategory" meta_type="Factory-based Type Information with dynamic views"/>
<object name="AnalysisRequest" meta_type="Factory-based Type Information with dynamic views"/>
<object name="AnalysisService" meta_type="Factory-based Type Information with dynamic views"/>
<object name="AnalysisServices" meta_type="Factory-based Type Information with dynamic views"/>
Expand Down
28 changes: 0 additions & 28 deletions src/bika/lims/profiles/default/types/AnalysisCategories.xml

This file was deleted.

47 changes: 0 additions & 47 deletions src/bika/lims/profiles/default/types/AnalysisCategory.xml

This file was deleted.

19 changes: 19 additions & 0 deletions src/bika/lims/workflow/analysiscategory/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
#
# This file is part of SENAITE.CORE.
#
# SENAITE.CORE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright 2018-2024 by it's authors.
# Some rights reserved, see README and LICENSE.
33 changes: 33 additions & 0 deletions src/bika/lims/workflow/analysiscategory/guards.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
#
# This file is part of SENAITE.CORE.
#
# SENAITE.CORE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright 2018-2024 by it's authors.
# Some rights reserved, see README and LICENSE.

from bika.lims import api
from senaite.core.catalog import SETUP_CATALOG


def guard_deactivate(analysis_category):
Bugerman58 marked this conversation as resolved.
Show resolved Hide resolved
"""Return whether the transition "deactivate" can be performed or not.
"""

# Analysis Category can't be deactivated if it contains services
query = dict(portal_type="AnalysisService",
category_uid=analysis_category.UID())
brains = api.search(query, SETUP_CATALOG)
return not brains
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
#
# This file is part of SENAITE.CORE.
#
# SENAITE.CORE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright 2018-2024 by it's authors.
# Some rights reserved, see README and LICENSE.
Loading
Loading