Skip to content

Commit

Permalink
Backported Issue-2219 into 3.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonski committed Sep 15, 2017
1 parent 532f2f4 commit d2555dc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 52 deletions.
2 changes: 1 addition & 1 deletion bika/lims/browser/analysisrequest/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def workflow_action_copy_to_new(self):
return
url = self.context.absolute_url() + "/ar_add" + \
"?ar_count={0}".format(len(objects)) + \
"&copy_from={0}".format(",".join(objects.keys()))
"&copy_from={0}".format(",".join(reversed(objects.keys())))
self.request.response.redirect(url)
return

Expand Down
91 changes: 40 additions & 51 deletions bika/lims/browser/bika_listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,39 @@

import json
import copy
import collections

import plone
from Acquisition import aq_inner
from DateTime import DateTime

from Products.AdvancedQuery import And, Or, MatchRegexp, Between, Generic, Eq
from Products.CMFCore.utils import getToolByName
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile

from zope.component import getAdapters

import plone
from plone import api as ploneapi
from plone.app.content.browser import tableview
from plone.memoize.volatile import cache
from plone.memoize.volatile import store_on_context
try:
from plone.batching import Batch
except:
# Plone < 4.3
from plone.app.content.batching import Batch # noqa

from bika.lims import PMF
from bika.lims import api
from bika.lims import bikaMessageFactory as _
from bika.lims import logger
from bika.lims.browser import BrowserView
from bika.lims.interfaces import IFieldIcons
from bika.lims.subscribers import doActionFor
from bika.lims.subscribers import skip
from bika.lims.utils import getFromString
from bika.lims.utils import isActive, getHiddenAttributesForClass
from bika.lims.utils import t
from bika.lims.utils import to_utf8
from bika.lims.utils import getFromString
from plone.app.content.browser import tableview
from plone import api as ploneapi
from zope.component import getAdapters
from zope.component._api import getMultiAdapter

try:
from plone.batching import Batch
except:
# Plone < 4.3
from plone.app.content.batching import Batch


from bika.lims import api
from plone.memoize.volatile import cache
from plone.memoize.volatile import store_on_context


class WorkflowAction:
Expand Down Expand Up @@ -97,9 +97,10 @@ def _get_selected_items(self, full_objects=True):
"""
form = self.request.form
uc = getToolByName(self.context, 'uid_catalog')
uids = form.get("uids", [])

selected_items = {}
for uid in form.get('uids', []):
selected_items = collections.OrderedDict()
for uid in uids:
try:
item = uc(UID=uid)[0].getObject()
except:
Expand Down Expand Up @@ -141,14 +142,13 @@ def workflow_action_copy_to_new(self):
message = self.context.translate(
_("No analyses have been selected"))
self.context.plone_utils.addPortalMessage(message, 'info')
self.destination_url = self.context.absolute_url() + \
"/batchbook"
self.destination_url = self.context.absolute_url() + "/batchbook"
self.request.response.redirect(self.destination_url)
return

url = self.context.absolute_url() + "/ar_add" + \
"?ar_count={0}".format(len(objects)) + \
"&copy_from={0}".format(",".join(objects.keys()))
"?ar_count={0}".format(len(objects)) + \
"&copy_from={0}".format(",".join(reversed(objects.keys())))
self.request.response.redirect(url)
return

Expand Down Expand Up @@ -219,8 +219,8 @@ def submitTransition(self, action, came_from, items):
# of verifications done for the analysis is, at least,
# the number of verifications performed previously+1
if (action == 'verify' and
hasattr(item, 'getNumberOfVerifications') and
hasattr(item, 'getNumberOfRequiredVerifications')):
hasattr(item, 'getNumberOfVerifications') and
hasattr(item, 'getNumberOfRequiredVerifications')):

success = True
revers = item.getNumberOfRequiredVerifications()
Expand All @@ -240,8 +240,7 @@ def submitTransition(self, action, came_from, items):
self.context.plone_utils.addPortalMessage(message, 'error')

# automatic label printing
if transitioned and action == 'receive' \
and 'receive' in self.portal.bika_setup.getAutoPrintStickers():
if transitioned and action == 'receive' and 'receive' in self.portal.bika_setup.getAutoPrintStickers():
q = "/sticker?template=%s&items=" % (self.portal.bika_setup.getAutoStickerTemplate())
# selected_items is a list of UIDs (stickers for AR_add use IDs)
q += ",".join(transitioned)
Expand Down Expand Up @@ -518,7 +517,7 @@ def _process_request(self):
# this way, a single table among many can request a redraw,
# and only it's content will be rendered.
if form_id not in self.request.get('table_only', form_id) \
or form_id not in self.request.get('rows_only', form_id):
or form_id not in self.request.get('rows_only', form_id):
return ''

self.rows_only = self.request.get('rows_only', '') == form_id
Expand Down Expand Up @@ -621,7 +620,7 @@ def _process_request(self):
if not idx:
logger.debug("index named '%s' not found in %s. "
"(Perhaps the index is still empty)." %
(index, self.catalog))
(index, self.catalog))
continue
request_key = "%s_%s" % (form_id, index)
value = self.request.get(request_key, '')
Expand Down Expand Up @@ -751,15 +750,14 @@ def __call__(self):
# Saving the filter bar values
cookie_filter_bar = ''
if cookie_value is not None and \
cookie_value not in ([], '', [None]): #There maybe more
cookie_value not in ([], '', [None]): # There maybe more
try:
cookie_filter_bar = json.loads(cookie_value)
except ValueError, e:
logger.error(
'BikaListingView: cannot parse cookie value %s (%s)' % (
str(e), cookie_value))


# Creating a dict from cookie data
cookie_data = {}
for k, v in cookie_filter_bar:
Expand All @@ -774,7 +772,7 @@ def __call__(self):
return self.rendered_items()

if self.request.get('table_only', '') == self.form_id \
or self.request.get('rows_only', '') == self.form_id:
or self.request.get('rows_only', '') == self.form_id:
return self.contents_table(table_only=self.form_id)
else:
return self.template()
Expand All @@ -793,8 +791,8 @@ def selected_cats(self, items):
for item in items:
cat = item.get('category', 'None')
if item.get('selected', False) \
or self.expand_all_categories \
or not self.show_categories:
or self.expand_all_categories \
or not self.show_categories:
if cat not in cats:
cats.append(cat)
return cats
Expand Down Expand Up @@ -897,12 +895,12 @@ def make_listing_item(self, brain):
review_state = "active"
state_title = _("Active")

#for state_var, state in states.items():
# if not state_title:
# state_title = workflow.getTitleForStateOnType(state, portal_type)
# item.update({
# state_var: state
# })
# for state_var, state in states.items():
# if not state_title:
# state_title = workflow.getTitleForStateOnType(state, portal_type)
# item.update({
# state_var: state
# })

# allow field icons to alert in a listing row
for name, adapter in getAdapters((obj, ), IFieldIcons):
Expand Down Expand Up @@ -963,7 +961,6 @@ def make_listing_item(self, brain):
"replace": {},
}


def folderitems(self, full_objects=False):
"""
>>> portal = layer['portal']
Expand All @@ -985,9 +982,6 @@ def folderitems(self, full_objects=False):
if not hasattr(self, 'contentsMethod'):
self.contentsMethod = getToolByName(self.context, self.catalog)

context = aq_inner(self.context)
workflow = getToolByName(context, 'portal_workflow')

if self.request.get('show_all', '').lower() == 'true' \
or self.show_all is True \
or self.pagesize == 0:
Expand Down Expand Up @@ -1021,8 +1015,7 @@ def folderitems(self, full_objects=False):
# otherwise, self.contentsMethod must handle contentFilter
brains = self.contentsMethod(contentFilterTemp)
else:
logger.debug(
"Bika Listing Table Query={}".format(contentFilterTemp))
logger.debug("Bika Listing Table Query={}".format(contentFilterTemp))
brains = self.contentsMethod(contentFilterTemp)

# idx increases one unit each time an object is added to the 'items'
Expand Down Expand Up @@ -1086,19 +1079,15 @@ def folderitems(self, full_objects=False):
results.append(item)
idx += 1


# Need manual_sort?
# Note that the order has already been set in contentFilter, so
# there is no need to reverse
if self.manual_sort_on:
results.sort(lambda x, y: cmp(x.get(self.manual_sort_on, ''),
y.get(self.manual_sort_on, '')))


return results



def contents_table(self, table_only=False):
""" If you set table_only to true, then nothing outside of the
<table/> tag will be printed (form tags, authenticator, etc).
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
3.2.1rc2 (unreleased)
---------------------

- Issue-2219: Copied ARs are created in random order
- Issue-2214: AR Add Controls need to be styled correctly


Expand Down

0 comments on commit d2555dc

Please sign in to comment.