def regenerate_id_server_values(self): bsc = ploneapi.portal.get_tool('bika_setup_catalog') for brain in bsc(): generateUniqueId(brain.getObject()) pc = ploneapi.portal.get_tool('portal_catalog') for brain in pc(): generateUniqueId(brain.getObject()) return 'Done'
def process_form(self, instance, field, form, empty_marker=None, emptyReturnsMarker=False, validating=True): value = form.get(field.getName()) # Allow non-required fields if not value: return None, {} # Is this Identifier temporary? true_values = ("true", "1", "on", "True", True, 1) temporary = value.get("temporary", False) in true_values # The ID might need to be auto-generated if temporary? autogenerated = value.get("autogenerated", "") identifier = value.get("value") or None if temporary and identifier in [None, AUTO_ID_MARKER]: kwargs = {"portal_type": field.getName()} identifier = generateUniqueId(api.get_portal(), **kwargs) autogenerated = identifier value = { "temporary": temporary, "value": identifier, "value_auto": autogenerated, } return value, {}
def lab_data(self): portal = self.context.portal_url.getPortalObject() lab = self.context.bika_setup.laboratory supervisor = lab.getLaboratorySupervisor() bsc = getToolByName(self.context, "bika_setup_catalog") labcontact = bsc(portal_type="LabContact", id=supervisor) signature = None lab_manager = '' signature = '' if len(labcontact) == 1: labcontact = labcontact[0].getObject() lab_manager = to_utf8(labcontact.getFullname()) address = lab.getPhysicalAddress() address = ', '.join((address['address'], address['city'], address['state'], address['zip'])) adict = { 'title': to_utf8(lab.Title()), 'lab_license_id': to_utf8(lab.getLaboratoryLicenseID()), 'name': to_utf8(lab.getName()), 'url': to_utf8(lab.getLabURL()), 'phone': to_utf8(lab.getPhone()), 'email': to_utf8(lab.getEmailAddress()), 'confidence': lab.getConfidence(), 'accredited': lab.getLaboratoryAccredited(), 'accreditation_body': to_utf8(lab.getAccreditationBody()), 'accreditation_logo': lab.getAccreditationBodyLogo(), 'logo': "%s/logo_print.png" % portal.absolute_url(), 'lab_manager': to_utf8(lab_manager), 'signature': signature, 'today': self.ulocalized_time(DateTime(), long_format=0), 'address': to_utf8(address), 'chain_coc': generateUniqueId(self.context, portal_type='COC'), } return adict
def prepare_number_generator(portal): number_generator = getUtility(INumberGenerator) if len(number_generator.keys()) > 1: logger.info('Skip number generator initialisation') return logger.info('Initialise number generator') # Load IDServer defaults config_map = [ {'context': 'sample', 'counter_reference': 'AnalysisRequestSample', 'counter_type': 'backreference', 'form': '{sampleId}-R{seq:02d}', 'portal_type': 'AnalysisRequest', 'prefix': '', 'sequence_type': 'counter', 'split_length': ''}, {'context': '', 'counter_reference': '', 'counter_type': '', 'form': 'B-{seq:03d}', 'portal_type': 'Batch', 'prefix': 'batch', 'sequence_type': 'generated', 'split_length': 1}, {'context': '', 'counter_reference': '', 'counter_type': '', 'form': '{sampleType}-{seq:04d}', 'portal_type': 'Sample', 'prefix': 'sample', 'sequence_type': 'generated', 'split_length': 1}, {'context': '', 'counter_reference': '', 'counter_type': '', 'form': 'WS-{seq:03d}', 'portal_type': 'Worksheet', 'prefix': 'worksheet', 'sequence_type': 'generated', 'split_length': 1}, {'context': '', 'counter_reference': '', 'counter_type': '', 'form': 'I-{seq:03d}', 'portal_type': 'Invoice', 'prefix': 'invoice', 'sequence_type': 'generated', 'split_length': 1}, {'context': '', 'counter_reference': '', 'counter_type': '', 'form': 'AI-{seq:03d}', 'portal_type': 'ARImport', 'prefix': 'arimport', 'sequence_type': 'generated', 'split_length': 1}, {'context': '', 'counter_reference': '', 'counter_type': '', 'form': 'QC-{seq:03d}', 'portal_type': 'ReferenceSample', 'prefix': 'refsample', 'sequence_type': 'generated', 'split_length': 1}, {'context': '', 'counter_reference': '', 'counter_type': '', 'form': 'SA-{seq:03d}', 'portal_type': 'ReferenceAnalysis', 'prefix': 'refanalysis', 'sequence_type': 'generated', 'split_length': 1}, {'context': '', 'counter_reference': '', 'counter_type': '', 'form': 'D-{seq:03d}', 'portal_type': 'DuplicateAnalysis', 'prefix': 'duplicate', 'sequence_type': 'generated', 'split_length': 1}, {'context': 'sample', 'counter_reference': 'SamplePartition', 'counter_type': 'contained', 'form': '{sampleId}-P{seq:d}', 'portal_type': 'SamplePartition', 'prefix': '', 'sequence_type': 'counter', 'split_length': ''}] # portal.bika_setup.setIDFormatting(config_map) # Regenerate every id to prime the number generator bsc = portal.bika_setup_catalog for brain in bsc(): generateUniqueId(brain.getObject()) pc = portal.portal_catalog for brain in pc(): generateUniqueId(brain.getObject())