Skip to content

Commit

Permalink
Merge branch 'hotfix/3.1.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
Pau Soliva committed Oct 8, 2015
2 parents ca85a6c + 6527856 commit 4928c74
Show file tree
Hide file tree
Showing 354 changed files with 147,876 additions and 33,892 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ parts
report.html
selenium-screenshot*
Thumbs.db
var
tags
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Bika LIMS
=========

v3.1.8.1 (2015-06-23)
v3.1.9 (2015-10-8)

The meaning of Gaob
-------------------
Expand Down
1 change: 1 addition & 0 deletions bika/lims/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# import this to create messages in the bika domain.
from zope.i18nmessageid import MessageFactory
bikaMessageFactory = MessageFactory('bika')
_ = MessageFactory('bika.lims')
from Products.Archetypes import PloneMessageFactory as PMF

# import this to log messages
Expand Down
129 changes: 83 additions & 46 deletions bika/lims/barcode.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,101 @@
from Products.CMFCore.utils import getToolByName
from Products.CMFCore.WorkflowCore import WorkflowException

from bika.lims.browser import BrowserView
from bika.lims import bikaMessageFactory as _
from bika.lims.utils import t
from bika.lims import interfaces
from bika.lims import logger
from bika.lims.permissions import EditResults, EditWorksheet
from bika.lims.permissions import EditResults

import json
import plone.protect


class barcode_entry(BrowserView):
""" return redirect url if the item exists
passes the request to catalog
"""Decide the best redirect URL for any barcode scanned into the browser.
"""
def __call__(self):
try:
plone.protect.CheckAuthenticator(self.request)
plone.protect.PostOnly(self.request)
except:
return ""
return self.return_json({
'success': False,
'failure': True,
'error': 'Cannot verify authenticator token'})

mtool = getToolByName(self.context, 'portal_membership')
uc = getToolByName(self.context, 'uid_catalog')
entry = self.request.get("entry", '').replace("*", "")
entry = self.get_entry()
if not entry:
return self.return_json({
'success': False,
'failure': True,
'error': 'No barcode entry submitted'})

instance = self.resolve_item(entry)
if not instance:
return self.return_json({
'success': False,
'failure': True,
'error': 'Cannot resolve ID or Title: %s' % entry})

items = uc(UID=entry)
if not items:
return ""
item = items[0].getObject()
url = getattr(self, 'handle_' + instance.portal_type)(instance) \
if hasattr(self, 'handle_' + instance.portal_type) \
else instance.absolute_url()

if item.portal_type == "AnalysisRequest":
if mtool.checkPermission(EditResults, item):
destination_url = item.absolute_url() + "/manage_results"
else:
destination_url = item.absolute_url()
return self.request.response.redirect(destination_url)
return self.return_json({
'success': True,
'failure': False,
'url': url})

elif item.portal_type == "Sample":
ars = item.getAnalysisRequests()
if len(ars) == 1:
# If there's only one AR, go there
if mtool.checkPermission(EditResults, ars[0]):
destination_url = ars[0].absolute_url() + "/manage_results"
else:
destination_url = ars[0].absolute_url()
return self.request.response.redirect(destination_url)
else:
# multiple or no ARs: direct to sample.
destination_url = item.absolute_url()
return self.request.response.redirect(destination_url)
def get_entry(self):
entry = self.request.get('entry', '')
entry = entry.replace('*', '')
entry = entry.strip()
return entry

elif item.portal_type == "Worksheet":
if mtool.checkPermission(EditWorksheet, item):
destination_url = item.absolute_url()
return self.request.response.redirect(destination_url)
def resolve_item(self, entry):
for catalog in [self.bika_catalog, self.bika_setup_catalog]:
brains = catalog(title=entry)
if brains:
return brains[0].getObject()
brains = catalog(id=entry)
if brains:
return brains[0].getObject()

elif item.portal_type == "ReferenceSample":
destination_url = item.absolute_url()
return self.request.response.redirect(destination_url)
def return_json(self, value):
output = json.dumps(value)
self.request.RESPONSE.setHeader('Content-Type', 'application/json')
self.request.RESPONSE.write(json.dumps(output))
return output

def handle_AnalysisRequest(self, instance):
"""Possible redirects for an AR.
- If AR is sample_due: receive it before proceeding.
- If AR belongs to Batch, redirect to the BatchBook view.
- If AR does not belong to Batch:
- if permission/workflow permit: go to AR manage_results.
- For other ARs, just redirect to the view screen.
"""
# - If AR is sample_due: receive it before proceeding.
wf = getToolByName(self.context, 'portal_workflow')
if wf.getInfoFor(instance, 'review_state') == 'sample_due':
try:
wf.doActionFor(instance, 'receive')
except WorkflowException:
pass
# - If AR belongs to Batch, redirect to the BatchBook view.
batch = instance.getBatch()
if batch:
return batch.absolute_url() + "/batchbook"
# - if permission/workflow permit: go to AR manage_results.
mtool = getToolByName(self.context, 'portal_membership')
if mtool.checkPermission(EditResults, instance):
return instance.absolute_url() + '/manage_results'
# - For other ARs, just redirect to the view screen.
return instance.absolute_url()

"""
Sample round/COC the user lands on the sampling round's view, if he/she is\
authorised to see it
"""
def handle_Sample(self, instance):
"""If this sample has a single AR, go there.
If the sample has 0 or >1 ARs, go to the sample's view URL.
"""
ars = instance.getAnalysisRequests()
if len(ars) == 1:
return self.handle_AnalysisRequest(instance)
else:
return instance.absolute_url()
31 changes: 31 additions & 0 deletions bika/lims/browser/analysisprofile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from bika.lims.jsonapi import load_field_values
from bika.lims.interfaces import IJSONReadExtender, IAnalysisProfile
from zope.component import adapts
from zope.interface import implements


class JSONReadExtender(object):
"""- Place additional information about profile services
into the returned records.
Used in AR Add to prevent extra requests
"""

implements(IJSONReadExtender)
adapts(IAnalysisProfile)

def __init__(self, context):
self.context = context

def __call__(self, request, data):
service_data = []
for service in self.context.getService():
this_service = {'UID': service.UID(),
'Title': service.Title(),
'Keyword': service.getKeyword(),
'Price': service.getPrice(),
'VAT': service.getVAT(),
'PointOfCapture': service.getPointOfCapture(),
'CategoryTitle': service.getCategory().Title()}
service_data.append(this_service)
data['service_data'] = service_data

20 changes: 20 additions & 0 deletions bika/lims/browser/analysisprofile.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:i18n="http://namespaces.zope.org/i18n"
i18n_domain="bika">

<adapter
factory="bika.lims.browser.analysisprofile.JSONReadExtender"
provides="bika.lims.interfaces.IJSONReadExtender"
/>

<browser:page
for="bika.lims.interfaces.IAnalysisProfile"
name="analysisprofile_analysesview"
class="bika.lims.browser.widgets.analysisprofileanalyseswidget.AnalysisProfileAnalysesView"
permission="zope.Public"
layer="bika.lims.interfaces.IBikaLIMS"
/>

</configure>
Loading

0 comments on commit 4928c74

Please sign in to comment.