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

Added Auto ID Behavior for Dexterity Contents #1441

Merged
merged 3 commits into from
Sep 19, 2019
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 @@ -6,6 +6,7 @@ Changelog

**Added**

- #1441 Added Auto ID Behavior for Dexterity Contents
- #1431 Added Submitter column in Sample's analyses listing
- #1422 Notify user with failing addresses when emailing of results reports
- #1420 Allow to detach a partition from its primary sample
Expand Down
17 changes: 7 additions & 10 deletions bika/lims/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<i18n:registerTranslations directory="locales" />


<includeDependencies package="." />
// <include package="jarn.jsi18n" />
// <include package="plone.app.z3cform" />
Expand Down Expand Up @@ -44,6 +43,13 @@

<cmf:registerDirectory name="skins" directory="skins" recursive="True" />

<!-- Plone behavior for Dexterity based contents -->
<plone:behavior
title="Auto-Generate ID Beahvior for Dexterity Contents"
description="Generates an ID with the IDServer"
provides="bika.lims.interfaces.IAutoGenerateID"
/>

<!-- jquery redirects here when values are entered into 'document' context (barcodes) -->
<browser:page
for="*"
Expand Down Expand Up @@ -90,13 +96,4 @@
provides="bika.lims.interfaces.INumberGenerator"
factory=".numbergenerator.NumberGenerator"
/>


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

</configure>
5 changes: 5 additions & 0 deletions bika/lims/interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class IBikaLIMS(Interface):
"""


class IAutoGenerateID(Interface):
"""Auto-generate ID with ID server
"""


class IActionHandlerPool(Interface):
"""Marker interface for the ActionHandlerPool utility
"""
Expand Down
1 change: 1 addition & 0 deletions bika/lims/profiles/default/types/SamplingRound.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<!-- enabled behaviors -->
<!-- This allow references between archetypes and dexterity content types. -->
<property name="behaviors">
<element value="bika.lims.interfaces.IAutoGenerateID"/>
<element value="plone.app.referenceablebehavior.referenceable.IReferenceable" />
</property>
</object>
7 changes: 7 additions & 0 deletions bika/lims/subscribers/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
xmlns:i18n="http://namespaces.zope.org/i18n"
i18n_domain="senaite.core">

<!-- ID Server: Object Added -->
<subscriber
for="bika.lims.interfaces.IAutoGenerateID
zope.lifecycleevent.interfaces.IObjectAddedEvent"
handler=".objectadded.auto_generate_id"
/>

<!-- Audit Log: Object Created -->
<subscriber
for="*
Expand Down
15 changes: 15 additions & 0 deletions bika/lims/subscribers/objectadded.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
#
# This file is part of SENAITE.CORE
#
# Copyright 2018 by it's authors.

from bika.lims.idserver import renameAfterCreation
from bika.lims import logger


def auto_generate_id(obj, event):
"""Generate ID with the IDServer from senaite.core
"""
logger.info("Auto-Generate ID for {}".format(repr(obj)))
renameAfterCreation(obj)
18 changes: 8 additions & 10 deletions bika/lims/subscribers/samplinground.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,19 @@
# Copyright 2018-2019 by it's authors.
# Some rights reserved, see README and LICENSE.

from bika.lims.idserver import renameAfterCreation

def SamplingRoundAddedEventHandler(instance, event):
""" Event fired when BikaSetup object gets modified.
Since Sampling Round is a dexterity object we have to change the ID by "hand"
Then we have to redirect the user to the ar add form
"""Redirect user to the sample add form
"""
if instance.portal_type != "SamplingRound":
print("How does this happen: type is %s should be SamplingRound" % instance.portal_type)
return
renameAfterCreation(instance)
raise TypeError("Expected portal type 'SamplingRound', got '{}'"
.format(instance.portal_type))

# renameAfterCreation(instance)
num_art = len(instance.ar_templates)
destination_url = instance.aq_parent.absolute_url() + \
"/portal_factory/" + \
"AnalysisRequest/Request new analyses/ar_add?samplinground=" + \
instance.UID() + "&ar_count=" + str(num_art)
"/portal_factory/" + \
"AnalysisRequest/Request new analyses/ar_add?samplinground=" + \
instance.UID() + "&ar_count=" + str(num_art)
request = getattr(instance, 'REQUEST', None)
request.response.redirect(destination_url)