-
-
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
Barcode and labelling depending on Sample Type #607
Changes from all commits
cae4591
9b4e208
785c7d9
c1dae06
fc6ab0a
7050d0b
401d18d
eb2d4b2
708feac
3a729c5
17ad63b
d252f69
5d0320e
4b83ea4
a7cf4d7
0c93e95
257e074
437c440
40c59c6
ebe9800
63c61ee
782b4f5
2a86ec1
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of SENAITE.CORE | ||
# | ||
# Copyright 2018 by it's authors. | ||
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst. | ||
|
||
from zope.interface import implements | ||
|
||
from bika.lims import logger | ||
from bika.lims.interfaces import IGetStickerTemplates | ||
from bika.lims.vocabularies import getStickerTemplates | ||
|
||
|
||
class GetSampleStickers(object): | ||
""" | ||
Returns an array with the templates of stickers available for Sample | ||
object in context. | ||
Each array item is a dictionary with the following structure: | ||
[{'id': <template_id>, | ||
'title': <teamplate_title>, | ||
'selected: True/False'}, ] | ||
""" | ||
|
||
implements(IGetStickerTemplates) | ||
|
||
def __init__(self, context): | ||
self.context = context | ||
self.request = None | ||
self.sample_type = None | ||
|
||
def __call__(self, request): | ||
self.request = request | ||
# Stickers admittance are saved in sample type | ||
if not hasattr(self.context, 'getSampleType'): | ||
logger.warning( | ||
"{} has no attribute 'getSampleType', so no sticker will be " | ||
"returned.". format(self.context.getId()) | ||
) | ||
return [] | ||
self.sample_type = self.context.getSampleType() | ||
sticker_ids = self.sample_type.getAdmittedStickers() | ||
default_sticker_id = self.get_default_sticker_id() | ||
result = [] | ||
# Getting only existing templates and its info | ||
stickers = getStickerTemplates() | ||
for sticker in stickers: | ||
if sticker.get('id') in sticker_ids: | ||
sticker_info = sticker.copy() | ||
sticker_info['selected'] = \ | ||
default_sticker_id == sticker.get('id') | ||
result.append(sticker_info) | ||
return result | ||
|
||
def get_default_sticker_id(self): | ||
""" | ||
Gets the default sticker for that content type depending on the | ||
requested size. | ||
|
||
:return: An sticker ID as string | ||
""" | ||
size = self.request.get('size', '') | ||
if size == 'small': | ||
return self.sample_type.getDefaultSmallSticker() | ||
return self.sample_type.getDefaultLargeSticker() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,14 @@ | |
from bika.lims import bikaMessageFactory as _, t | ||
from bika.lims import logger | ||
from bika.lims.browser import BrowserView | ||
from zope.component.interfaces import ComponentLookupError | ||
from bika.lims.utils import createPdf, to_int | ||
from bika.lims.vocabularies import getStickerTemplates | ||
from plone.resource.utils import iterDirectoriesOfType, queryResourceDirectory | ||
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile | ||
import glob, os, os.path, sys, traceback | ||
from bika.lims.interfaces import IGetStickerTemplates | ||
from zope.component import getAdapters | ||
|
||
import os | ||
import App | ||
|
@@ -168,8 +171,22 @@ def getAvailableTemplates(self): | |
'title': <teamplate_title>, | ||
'selected: True/False'} | ||
""" | ||
seltemplate = self.getSelectedTemplate() | ||
# Getting adapters for current context. those adapters will return | ||
# the desired sticker templates for the current context: | ||
try: | ||
adapters = getAdapters((self.context, ), IGetStickerTemplates) | ||
except ComponentLookupError: | ||
logger.info('No IGetStickerTemplates adapters found.') | ||
adapters = None | ||
templates = [] | ||
if adapters is not None: | ||
# Gather all templates | ||
for name, adapter in adapters: | ||
templates += adapter(self.request) | ||
if templates: | ||
return templates | ||
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. Reduce nesting: if not adapters:
return list()
templates = list()
for name, adapter in adapters:
templates.append(adapter(self.request))
if templates:
... 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. As I said in a previous comment, I can't return until the end of the method. Moreover, |
||
# If there are no adapters, get all sticker templates in the system | ||
seltemplate = self.getSelectedTemplate() | ||
for temp in getStickerTemplates(filter_by_type=self.filter_by_type): | ||
out = temp | ||
out['selected'] = temp.get('id', '') == seltemplate | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from AccessControl import ClassSecurityInfo | ||
|
||
from Products.Archetypes.Registry import registerWidget | ||
|
||
from bika.lims.browser.widgets import RecordsWidget | ||
|
||
|
||
class SampleTypeStickersWidget(RecordsWidget): | ||
security = ClassSecurityInfo() | ||
_properties = RecordsWidget._properties.copy() | ||
_properties.update({ | ||
'helper_js': ( | ||
"bika_widgets/recordswidget.js", | ||
"bika_widgets/sampletypestickerswidget.js",), | ||
}) | ||
|
||
|
||
registerWidget( | ||
SampleTypeStickersWidget, | ||
title="Sample type stickers widget", | ||
description='Defines the available stickers for a sample type.', | ||
) |
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.
no need to do the assignment
adapters = None
here, justreturn list()
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.
The method continues as follows: if there aren't adapters nor templates, get all sticker templates in the system. So we can't return at this point.