本文整理汇总了Python中bika.lims.browser.bika_listing.WorkflowAction类的典型用法代码示例。如果您正苦于以下问题:Python WorkflowAction类的具体用法?Python WorkflowAction怎么用?Python WorkflowAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WorkflowAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
def __call__(self):
form = self.request.form
plone.protect.CheckAuthenticator(form)
action, came_from = WorkflowAction._get_form_workflow_action(self)
if action == 'submit':
objects = WorkflowAction._get_selected_items(self)
if not objects:
message = self.context.translate(
_b("No analyses have been selected"))
self.context.plone_utils.addPortalMessage(message, 'info')
self.destination_url = self.context.absolute_url() + \
"/batchbook"
self.request.response.redirect(self.destination_url)
return
for ar_uid, ar in objects.items():
for analysis in ar.getAnalyses(full_objects=True):
kw = analysis.getKeyword()
values = form.get(kw)
analysis.setResult(values[0][ar_uid])
if values[0][ar_uid]:
doActionFor(analysis, 'submit')
message = self.context.translate(_p("Changes saved."))
self.context.plone_utils.addPortalMessage(message, 'info')
self.request.response.redirect(self.request.get('URL'))
return
else:
WorkflowAction.__call__(self)
示例2: __call__
def __call__(self):
form = self.request.form
plone.protect.CheckAuthenticator(form)
workflow = getToolByName(self.context, 'portal_workflow')
rc = getToolByName(self.context, REFERENCE_CATALOG)
action, came_from = WorkflowAction._get_form_workflow_action(self)
if action == 'reassign':
selected_worksheets = WorkflowAction._get_selected_items(self)
selected_worksheet_uids = selected_worksheets.keys()
if selected_worksheets:
changes = False
for uid in selected_worksheet_uids:
worksheet = selected_worksheets[uid]
# Double-check the state first
if workflow.getInfoFor(worksheet, 'review_state') == 'open':
worksheet.setAnalyst(form['Analyst'][0][uid])
changes = True
if changes:
message = self.context.translate(PMF('Changes saved.'))
self.context.plone_utils.addPortalMessage(message, 'info')
self.destination_url = self.request.get_header("referer",
self.context.absolute_url())
self.request.response.redirect(self.destination_url)
else:
# default bika_listing.py/WorkflowAction for other transitions
WorkflowAction.__call__(self)
示例3: workflow_action_preserve
def workflow_action_preserve(self):
form = self.request.form
workflow = getToolByName(self.context, 'portal_workflow')
action, came_from = WorkflowAction._get_form_workflow_action(self)
checkPermission = self.context.portal_membership.checkPermission
# Partition Preservation
# the partition table shown in AR and Sample views sends it's
# action button submits here.
objects = WorkflowAction._get_selected_items(self)
transitioned = []
incomplete = []
for obj_uid, obj in objects.items():
part = obj
# can't transition inactive items
if workflow.getInfoFor(part, 'inactive_state', '') == 'inactive':
continue
if not checkPermission(PreserveSample, part):
continue
# grab this object's Preserver and DatePreserved from the form
Preserver = form['getPreserver'][0][obj_uid].strip()
Preserver = Preserver and Preserver or ''
DatePreserved = form['getDatePreserved'][0][obj_uid].strip()
DatePreserved = DatePreserved and DateTime(DatePreserved) or ''
# write them to the sample
part.setPreserver(Preserver)
part.setDatePreserved(DatePreserved)
# transition the object if both values are present
if Preserver and DatePreserved:
workflow.doActionFor(part, action)
transitioned.append(part.id)
else:
incomplete.append(part.id)
part.reindexObject()
part.aq_parent.reindexObject()
message = None
if len(transitioned) > 1:
message = _('${items} are waiting to be received.',
mapping={'items': safe_unicode(', '.join(transitioned))})
self.context.plone_utils.addPortalMessage(message, 'info')
elif len(transitioned) == 1:
message = _('${item} is waiting to be received.',
mapping={'item': safe_unicode(', '.join(transitioned))})
self.context.plone_utils.addPortalMessage(message, 'info')
if not message:
message = _('No changes made.')
self.context.plone_utils.addPortalMessage(message, 'info')
if len(incomplete) > 1:
message = _('${items} are missing Preserver or Date Preserved',
mapping={'items': safe_unicode(', '.join(incomplete))})
self.context.plone_utils.addPortalMessage(message, 'error')
elif len(incomplete) == 1:
message = _('${item} is missing Preserver or Preservation Date',
mapping={'item': safe_unicode(', '.join(incomplete))})
self.context.plone_utils.addPortalMessage(message, 'error')
self.destination_url = self.request.get_header("referer",
self.context.absolute_url())
self.request.response.redirect(self.destination_url)
示例4: workflow_action_receive
def workflow_action_receive(self):
# default bika_listing.py/WorkflowAction, but then
# print automatic labels.
if 'receive' in self.context.bika_setup.getAutoPrintLabels():
size = self.context.bika_setup.getAutoLabelSize()
q = "/sticker?size=%s&items=%s" % (size, self.context.getId())
self.destination_url = self.context.absolute_url() + q
WorkflowAction.__call__(self)
示例5: __call__
def __call__(self):
form = self.request.form
plone.protect.CheckAuthenticator(form)
workflow = getToolByName(self.context, 'portal_workflow')
rc = getToolByName(self.context, REFERENCE_CATALOG)
uc = getToolByName(self.context, 'uid_catalog')
action, came_from = WorkflowAction._get_form_workflow_action(self)
if action == 'duplicate':
selected_services = WorkflowAction._get_selected_items(self)
## Create a copy of the selected services
folder = self.context.bika_setup.bika_analysisservices
created = []
for service in selected_services.values():
_id = folder.invokeFactory('AnalysisService', id = 'tmp')
dup = folder[_id]
dup.setTitle('%s (copy)' % service.Title())
_id = renameAfterCreation(dup)
dup.edit(
description = service.Description(),
PointOfCapture = service.getPointOfCapture(),
ReportDryMatter = service.getReportDryMatter(),
Unit = service.getUnit(),
Precision = service.getPrecision(),
Price = service.getPrice(),
CorporatePrice = service.getCorporatePrice(),
VAT = service.getVAT(),
Calculation = service.getCalculation(),
Instrument = service.getInstrument(),
MaxTimeAllowed = service.getMaxTimeAllowed(),
DuplicateVariation = service.getDuplicateVariation(),
Category = service.getCategory(),
Department = service.getDepartment(),
Accredited = service.getAccredited(),
Uncertainties = service.getUncertainties(),
ResultOptions = service.getResultOptions()
)
created.append(_id)
if len(created) > 1:
message = self.context.translation_service.translate(
_('Services ${services} were successfully created.',
mapping = {'services': ', '.join(created)}))
self.destination_url = self.request.get_header("referer",
self.context.absolute_url())
else:
message = self.context.translation_service.translate(
_('Analysis request ${service} was successfully created.',
mapping = {'service': ', '.join(created)}))
self.destination_url = dup.absolute_url() + "/base_edit"
self.context.plone_utils.addPortalMessage(message, 'info')
self.request.response.redirect(self.destination_url)
else:
# default bika_listing.py/WorkflowAction for other transitions
WorkflowAction.__call__(self)
示例6: workflow_action_save_analyses_button
def workflow_action_save_analyses_button(self):
form = self.request.form
workflow = getToolByName(self.context, 'portal_workflow')
action, came_from = WorkflowAction._get_form_workflow_action(self)
# AR Manage Analyses: save Analyses
ar = self.context
sample = ar.getSample()
objects = WorkflowAction._get_selected_items(self)
if not objects:
message = _("No analyses have been selected")
self.context.plone_utils.addPortalMessage(message, 'info')
self.destination_url = self.context.absolute_url() + "/analyses"
self.request.response.redirect(self.destination_url)
return
Analyses = objects.keys()
prices = form.get("Price", [None])[0]
specs = {}
if form.get("min", None):
for service_uid in Analyses:
specs[service_uid] = {
"min": form["min"][0][service_uid],
"max": form["max"][0][service_uid],
"error": form["error"][0][service_uid]
}
else:
for service_uid in Analyses:
specs[service_uid] = {"min": "", "max": "", "error": ""}
new = ar.setAnalyses(Analyses, prices=prices, specs=specs)
# link analyses and partitions
# If Bika Setup > Analyses > 'Display individual sample
# partitions' is checked, no Partitions available.
# https://github.com/bikalabs/Bika-LIMS/issues/1030
if 'Partition' in form:
for service_uid, service in objects.items():
part_id = form['Partition'][0][service_uid]
part = sample[part_id]
analysis = ar[service.getKeyword()]
analysis.setSamplePartition(part)
analysis.reindexObject()
if new:
for analysis in new:
# if the AR has progressed past sample_received, we need to bring it back.
ar_state = workflow.getInfoFor(ar, 'review_state')
if ar_state in ('attachment_due', 'to_be_verified'):
# Apply to AR only; we don't want this transition to cascade.
ar.REQUEST['workflow_skiplist'].append("retract all analyses")
workflow.doActionFor(ar, 'retract')
ar.REQUEST['workflow_skiplist'].remove("retract all analyses")
ar_state = workflow.getInfoFor(ar, 'review_state')
# Then we need to forward new analyses state
analysis.updateDueDate()
changeWorkflowState(analysis, 'bika_analysis_workflow', ar_state)
message = PMF("Changes saved.")
self.context.plone_utils.addPortalMessage(message, 'info')
self.destination_url = self.context.absolute_url()
self.request.response.redirect(self.destination_url)
示例7: __call__
def __call__(self):
form = self.request.form
plone.protect.CheckAuthenticator(form)
action, _ = WorkflowAction._get_form_workflow_action(self)
if action == 'receive' and 'Type' in form:
BiospecimenWorkflowAction.__call__(self)
elif action == 'receive' and 'AliquotType' in form:
AliquotWorkflowAction.__call__(self)
else:
WorkflowAction.__call__(self)
示例8: workflow_action_keep
def workflow_action_keep(self):
workflow = getToolByName(self.context, 'portal_workflow')
action, came_from = WorkflowAction._get_form_workflow_action(self)
objects = WorkflowAction._get_selected_items(self)
for obj_uid, obj in objects.items():
pitem = obj
old_d = pitem.Description()
new_message = "\n*** Restored in Inventory at " + time.strftime("%c") + " ***\n"
pitem.setDescription(old_d + new_message)
pitem.reindexObject()
workflow.doActionFor(pitem, action)
message = PMF("Changes saved.")
self.context.plone_utils.addPortalMessage(message, 'info')
self.destination_url = self.context.absolute_url()
self.request.response.redirect(self.destination_url)
示例9: workflow_action_verify
def workflow_action_verify(self):
# default bika_listing.py/WorkflowAction, but then go to view screen.
self.destination_url = self.context.absolute_url()
action, came_from = WorkflowAction._get_form_workflow_action(self)
if type(came_from) in (list, tuple):
came_from = came_from[0]
return self.workflow_action_default(action="verify", came_from=came_from)
示例10: __call__
def __call__(self):
form = self.request.form
plone.protect.CheckAuthenticator(form)
action, came_from = WorkflowAction._get_form_workflow_action(self)
if type(action) in (list, tuple):
action = action[0]
if type(came_from) in (list, tuple):
came_from = came_from[0]
# Call out to the workflow action method
# Use default bika_listing.py/WorkflowAction for other transitions
method_name = 'workflow_action_' + action
method = getattr(self, method_name, False)
if method:
method()
else:
WorkflowAction.__call__(self)
示例11: workflow_action_aliquot_receive
def workflow_action_aliquot_receive(self):
form = self.request.form
selected_aliquots = WorkflowAction._get_selected_items(self)
aliquots = []
for uid in selected_aliquots.keys():
if not form["AliquotType"][0][uid] or not form["Volume"][0][uid] or not form["Unit"][0][uid]:
continue
try:
aliquot = selected_aliquots.get(uid, None)
aliquot.getField("SampleType").set(aliquot, form["AliquotType"][0][uid])
aliquot.getField("Volume").set(aliquot, form["Volume"][0][uid])
unit = "ml"
for u in VOLUME_UNITS:
if u["ResultValue"] == form["Unit"][0][uid]:
unit = u["ResultText"]
aliquot.getField("Unit").set(aliquot, unit)
aliquot.reindexObject()
aliquots.append(aliquot)
except ReferenceException:
continue
message = PMF("Changes saved.")
self.context.plone_utils.addPortalMessage(message, "info")
for aliquot in aliquots:
doActionFor(aliquot, "receive")
for partition in aliquot.objectValues("SamplePartition"):
doActionFor(partition, "receive")
self.destination_url = self.context.absolute_url()
if self.context.portal_type == "Project":
self.destination_url += "/aliquots"
self.request.response.redirect(self.destination_url)
示例12: workflow_action_schedule_sampling
def workflow_action_schedule_sampling(self):
"""
This function prevent the transition if the fields "SamplingDate"
and "ScheduledSamplingSampler" are uncompleted.
:return: bool
"""
from bika.lims.utils.workflow import schedulesampling
message = "Not expected transition."
# In Samples Folder we have to get each selected item
if interfaces.ISamplesFolder.providedBy(self.context):
select_objs = WorkflowAction._get_selected_items(self)
message = _("Transition done.")
for key in select_objs.keys():
sample = select_objs[key]
# Getting the sampler
sch_sampl = (
self.request.form.get("getScheduledSamplingSampler", None)[0].get(key)
if self.request.form.get("getScheduledSamplingSampler", None)
else ""
)
# Getting the date
sampl_date = (
self.request.form.get("getSamplingDate", None)[0].get(key)
if self.request.form.get("getSamplingDate", None)
else ""
)
# Setting both values
sample.setScheduledSamplingSampler(sch_sampl)
sample.setSamplingDate(sampl_date)
# Transitioning the sample
success, errmsg = schedulesampling.doTransition(sample)
if errmsg == "missing":
message = _(
"'Sampling date' and 'Define the Sampler for the"
+ " scheduled sampling' must be completed and saved "
+ "in order to schedule a sampling. Element: %s" % sample.getId()
)
elif errmsg == "cant_trans":
message = _("The item %s can't be transitioned." % sample.getId())
else:
message = _("Transition done.")
self.context.plone_utils.addPortalMessage(message, "info")
else:
success, errmsg = schedulesampling.doTransition(self.context)
if errmsg == "missing":
message = _(
"'Sampling date' and 'Define the Sampler for the"
+ " scheduled sampling' must be completed and saved in "
+ "order to schedule a sampling."
)
elif errmsg == "cant_trans":
message = _("The item can't be transitioned.")
else:
message = _("Transition done.")
self.context.plone_utils.addPortalMessage(message, "info")
# Reload the page in order to show the portal message
self.request.response.redirect(self.context.absolute_url())
return success
示例13: workflow_action_publish
def workflow_action_publish(self):
action, came_from = WorkflowAction._get_form_workflow_action(self)
if not isActive(self.context):
message = _('Item is inactive.')
self.context.plone_utils.addPortalMessage(message, 'info')
self.request.response.redirect(self.context.absolute_url())
return
# AR publish preview
self.request.response.redirect(self.context.absolute_url() + "/publish")
示例14: __call__
def __call__(self):
form = self.request.form
CheckAuthenticator(form)
workflow = getToolByName(self.context, 'portal_workflow')
rc = getToolByName(self.context, REFERENCE_CATALOG)
action, came_from = WorkflowAction._get_form_workflow_action(self)
if action == 'reassign':
mtool = getToolByName(self.context, 'portal_membership')
if not mtool.checkPermission(ManageWorksheets, self.context):
# Redirect to WS list
msg = _('You do not have sufficient privileges to '
'manage worksheets.')
self.context.plone_utils.addPortalMessage(msg, 'warning')
portal = getToolByName(self.context, 'portal_url').getPortalObject()
self.destination_url = portal.absolute_url() + "/worksheets"
self.request.response.redirect(self.destination_url)
return
selected_worksheets = WorkflowAction._get_selected_items(self)
selected_worksheet_uids = selected_worksheets.keys()
if selected_worksheets:
changes = False
for uid in selected_worksheet_uids:
worksheet = selected_worksheets[uid]
# Double-check the state first
if workflow.getInfoFor(worksheet, 'review_state') == 'open':
worksheet.setAnalyst(form['Analyst'][0][uid])
worksheet.reindexObject(idxs=['getAnalyst'])
changes = True
if changes:
message = PMF('Changes saved.')
self.context.plone_utils.addPortalMessage(message, 'info')
self.destination_url = self.request.get_header("referer",
self.context.absolute_url())
self.request.response.redirect(self.destination_url)
else:
# default bika_listing.py/WorkflowAction for other transitions
WorkflowAction.__call__(self)
示例15: workflow_action_save_partitions_button
def workflow_action_save_partitions_button(self):
form = self.request.form
# Sample Partitions or AR Manage Analyses: save Partition Table
sample = self.context.portal_type == 'Sample' and self.context or\
self.context.getSample()
part_prefix = sample.getId() + "-P"
nr_existing = len(sample.objectIds())
nr_parts = len(form['PartTitle'][0])
# add missing parts
if nr_parts > nr_existing:
for i in range(nr_parts - nr_existing):
part = _createObjectByType("SamplePartition", sample, tmpID())
part.setDateReceived = DateTime()
part.processForm()
# remove excess parts
if nr_existing > nr_parts:
for i in range(nr_existing - nr_parts):
part = sample['%s%s' % (part_prefix, nr_existing - i)]
for a in part.getBackReferences("AnalysisSamplePartition"):
a.setSamplePartition(None)
sample.manage_delObjects(['%s%s' % (part_prefix, nr_existing - i), ])
# modify part container/preservation
for part_uid, part_id in form['PartTitle'][0].items():
part = sample["%s%s" % (part_prefix, part_id.split(part_prefix)[1])]
part.edit(
Container=form['getContainer'][0][part_uid],
Preservation=form['getPreservation'][0][part_uid],
)
part.reindexObject()
# Adding the Security Seal Intact checkbox's value to the container object
container_uid = form['getContainer'][0][part_uid]
uc = getToolByName(self.context, 'uid_catalog')
cbr = uc(UID=container_uid)
if cbr and len(cbr) > 0:
container_obj = cbr[0].getObject()
else:
continue
value = form.get('setSecuritySealIntact', {}).get(part_uid, '') == 'on'
container_obj.setSecuritySealIntact(value)
objects = WorkflowAction._get_selected_items(self)
if not objects:
message = _("No items have been selected")
self.context.plone_utils.addPortalMessage(message, 'info')
if self.context.portal_type == 'Sample':
# in samples his table is on 'Partitions' tab
self.destination_url = self.context.absolute_url() +\
"/partitions"
else:
# in ar context this table is on 'ManageAnalyses' tab
self.destination_url = self.context.absolute_url() +\
"/analyses"
self.request.response.redirect(self.destination_url)