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

ID Server seeding function, flushed storage, utf-8 encoding, etc. #386

Merged
merged 7 commits into from
Nov 19, 2017
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
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changelog

**Added**

- #386 PR-2297 Added seeding function to IDServer
- #372 Added build system to project root
- #345 'SearchableText' field and adapter in Batches
- #344 PR-2294 Allow year in any portal type's ID format string
Expand Down Expand Up @@ -39,6 +40,9 @@ Changelog

**Fixed**

- #386 PR-2313 UniqueFieldValidator: Encode value to utf-8 before passing it to the catalog
- #386 PR-2312 IDServer: Fixed default split length value
- #386 PR-2311 Fix ID Server to handle a flushed storage or existing IDs with the same prefix
- #385 PR-2309 Some objects were missed in instrument listing views
- #384 PR-2306 Do not use localized dates for control chart as it breaks the controlchart.js datetime parser
- #382 PR-2305 TypeError in Analysis Specification category expansion
Expand Down
1 change: 1 addition & 0 deletions bika/lims/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<include package=".analysisrequest"/>
<include package=".batch"/>
<include package=".client"/>
<include package=".idserver"/>
<include package=".dashboard"/>
<include package=".department"/>
<include package=".resultsimport"/>
Expand Down
Empty file.
24 changes: 24 additions & 0 deletions bika/lims/browser/idserver/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="bika">

<browser:page
for="*"
name="ng_seed"
class="bika.lims.browser.idserver.view.IDServerView"
attribute="seed"
permission="cmf.ManagePortal"
layer="bika.lims.interfaces.IBikaLIMS"
/>

<browser:page
for="*"
name="ng_flush"
class="bika.lims.browser.idserver.view.IDServerView"
attribute="flush"
permission="cmf.ManagePortal"
layer="bika.lims.interfaces.IBikaLIMS"
/>

</configure>
38 changes: 38 additions & 0 deletions bika/lims/browser/idserver/view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-

from bika.lims.browser import BrowserView
from bika.lims.numbergenerator import INumberGenerator
from zope.component import getUtility


class IDServerView(BrowserView):
""" This browser view is to house ID Server related functions
"""

def seed(self):
""" Reset the number from which the next generated sequence start.
If you seed at 100, next seed will be 101
"""
form = self.request.form
prefix = form.get('prefix', None)
if prefix is None:
return 'No prefix provided'
seed = form.get('seed', None)
if seed is None:
return 'No seed provided'
if not seed.isdigit():
return 'Seed must be a digit'
seed = int(seed)
if seed < 0:
return 'Seed cannot be negative'

number_generator = getUtility(INumberGenerator)
new_seq = number_generator.set_number(key=prefix, value=seed)
return 'IDServerView: "%s" seeded to %s' % (prefix, new_seq)

def flush(self):
""" Flush the storage
"""
number_generator = getUtility(INumberGenerator)
number_generator.flush()
return "IDServerView: Number storage flushed!"
12 changes: 2 additions & 10 deletions bika/lims/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,11 @@
/>


<!-- Bika Auto generate ID for Dexterity types -->
<!-- Bika Auto generate ID behavior for Dexterity types -->
<plone:behavior
title="Auto generate ID Beahvior for Dexterity contents"
title="Auto generate ID Behavior for Dexterity contents"
description="Generates an ID with the IDServer"
provides="bika.lims.interfaces.IGenerateID"
/>

<!-- Name chooser for dexterity types.
N.B. This only works if no `id` is passed to the factory tool -->
<adapter
for="bika.lims.interfaces.IGenerateID"
factory=".idserver.AutoGenerateID"
provides="zope.container.interfaces.INameChooser"
/>

</configure>
62 changes: 43 additions & 19 deletions bika/lims/content/bikasetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,25 +805,49 @@ def getCounterTypes(self, instance=None):
widget=RecordsWidget(
label=_("Formatting Configuration"),
allowDelete=True,
description=_("""The ID Server in Bika LIMS provides IDs for content items base of the given format specification.
The format string is constructed in the same way as a python format() method
based predefined variables per content type. The only variable available to all
type is 'seq'. Currently, 'seq' can be constructed either using number generator
or a counter of existing items. For generated IDs, one can specify the point at
which the format string will be split to create the generator key. For counter
IDs, one must specify the context and the type of counter which is either the
number of backreferences or the number of contained objects.
Configuration Settings:
* format:
- a python format string constructed from predefined variables like sampleId, client, sampleType.
- special variable 'seq' must be positioned last in the format string
* sequence type: [generated|counter]
* context: if type counter, provides context the counting function
* counter type: [backreference|contained]
* counter reference: a parameter to the counting function
* prefix: default prefix if none provided in format string
* split length: the number of parts to be included in the prefix
""")
description=_(
" <p>The Bika LIMS ID Server provides unique sequential IDs "
"for objects such as Samples and Worksheets etc, based on a "
"format specified for each content type.</p>"
"<p>The format is constructed similarly to the Python format"
" syntax, using predefined variables per content type, and"
" advancing the IDs through a sequence number, 'seq' and its"
" padding as a number of digits, e.g. '03d' for a sequence of"
" IDs from 001 to 999.</p>"
"<p>Alphanumeric prefixes for IDs are included as is in the"
" formats, e.g. WS for Worksheet in WS-{seq:03d} produces"
" sequential Worksheet IDs: WS-001, WS-002, WS-003 etc.</p>"
"<p>Variables that can be used include:"
"<table>"
"<tr>"
"<th style='width:150px'>Content Type</th><th>Variables</th>"
"</tr>"
"<tr><td>Client</td><td>{client}</td></tr>"
"<tr><td>Year</td><td>{year}</td></tr>"
"<tr><td>Sample ID</td><td>{sampleId}</td></tr>"
"<tr><td>Sample Type</td><td>{sampleType}</td></tr>"
"<tr><td>Sampling Date</td><td>{samplingDate}</td></tr>"
"<tr><td>Date Sampled</td><td>{dateSampled}</td></tr>"
"</table>"
"</p>"
"<p>Configuration Settings:"
"<ul>"
"<li>format:"
"<ul><li>a python format string constructed from predefined"
" variables like sampleId, client, sampleType.</li>"
"<li>special variable 'seq' must be positioned last in the"
"format string</li></ul></li>"
"<li>sequence type: [generated|counter]</li>"
"<li>context: if type counter, provides context the counting"
" function</li>"
"<li>counter type: [backreference|contained]</li>"
"<li>counter reference: a parameter to the counting"
" function</li>"
"<li>prefix: default prefix if none provided in format"
" string</li>"
"<li>split length: the number of parts to be included in the"
" prefix</li>"
"</ul></p>")
)
),
BooleanField(
Expand Down
Loading