def parent(self, template='default', room='', first='', last='', code='', secure='', link=None, barcode=True): """ Applies data to a nametag template and returns the resulting HTML. Accepts template theme from listTemplates() as first argument; 'default' if None. Accepts the following formats (defaults are blank): - room - first - last - medical - code - secure This method processes parent.html only. """ #Check that theme specified is valid: if template != 'default': themes = self.listTemplates() if template not in themes: self.log.error("Bad theme specified. Using default instead.") template = 'default' #Read in the HTML from template. try: directory = self._getTemplatePath(template) except KeyError: self.log.error( "Unable to process template '{0}'. Aborting.".format(template)) return None self.log.debug('Generating child tag using {0} from {1}'.format( 'parent.html', directory)) f = open(os.path.join(directory, 'parent.html')) inp = f.read() f.close() #Generate barcodes if needed: if barcode: try: if secure == '': codebar.gen('code128', os.path.join(directory, 'parent-secure.png'), code) else: codebar.gen('code128', os.path.join(directory, 'parent-secure.png'), secure) except NotImplementedError as e: self.log.error('Unable to generate barcode: {0}'.format(e)) inp = inp.replace(u'parent-secure.png', u'white.gif') else: #replace barcode image with white.gif inp = inp.replace(u'parent-secure.png', u'white.gif') self.log.debug("Disabled barcode.") #Generate QR code if needed: if link == '': link = None if link != None: codebar.gen('qr', os.path.join(directory, 'parent-link.png'), link) #get the current date/time now = datetime.datetime.now() #Perform substitutions: inp = self.date_re.sub(now.strftime("%a %d %b, %Y"), inp) #date inp = self.time_re.sub(now.strftime("%H:%M:%S"), inp) #time inp = self.room_re.sub(room, inp) #room inp = self.first_re.sub(first, inp) #first name inp = self.last_re.sub(last, inp) #surname inp = self.code_re.sub(code, inp) #paging code inp = self.secure_re.sub(secure, inp) #security code return inp
def parent(self, template='default', room='', first='', last='', code='', secure='', link=None, barcode=True): """ Applies data to a nametag template and returns the resulting HTML. Accepts template theme from listTemplates() as first argument; 'default' if None. Accepts the following formats (defaults are blank): - room - first - last - medical - code - secure This method processes parent.html only. """ #Check that theme specified is valid: if template != 'default': themes = self.listTemplates() if template not in themes: self.log.error("Bad theme specified. Using default instead.") template = 'default' #Read in the HTML from template. try: directory = self._getTemplatePath(template) except KeyError: self.log.error("Unable to process template '{0}'. Aborting." .format(template)) return None self.log.debug('Generating child tag using {0} from {1}' .format('parent.html', directory)) f = open(os.path.join(directory, 'parent.html')) inp = f.read() f.close() #Generate barcodes if needed: if barcode: try: if secure == '': codebar.gen('code128', os.path.join(directory, 'parent-secure.png'), code) else: codebar.gen('code128', os.path.join(directory, 'parent-secure.png'), secure) except NotImplementedError as e: self.log.error('Unable to generate barcode: {0}'.format(e)) inp = inp.replace(u'parent-secure.png', u'white.gif') else: #replace barcode image with white.gif inp = inp.replace(u'parent-secure.png', u'white.gif') self.log.debug("Disabled barcode.") #Generate QR code if needed: if link == '': link = None if link != None: codebar.gen('qr', os.path.join(directory, 'parent-link.png'), link) #get the current date/time now = datetime.datetime.now() #Perform substitutions: inp = self.date_re.sub(now.strftime("%a %d %b, %Y"), inp) #date inp = self.time_re.sub(now.strftime("%H:%M:%S"), inp) #time inp = self.room_re.sub(room, inp) #room inp = self.first_re.sub(first, inp) #first name inp = self.last_re.sub(last, inp) #surname inp = self.code_re.sub(code, inp) #paging code inp = self.secure_re.sub(secure, inp) #security code return inp
def nametag(self, template='default', room='', first='', last='', medical='', code='', secure='', barcode=True): """ Convenience function for generating nametag html and the coresponding barcodes. Applies data to a nametag template and returns the resulting HTML. Does not query database; pass barcode bool to disable. Accepts template theme from listTemplates() as first argument; 'default' if none. Accepts the following formats (defaults are blank): - room - first - last - medical - code - secure - Barcode=True This method processes default.html only. Disabled barcodes will be replaced with white.gif """ #Check that theme specified is valid: if template != 'default': themes = self.listTemplates() if template not in themes: self.log.error("Bad theme specified. Using default instead.") template = 'default' #Read in the HTML from template. try: directory = self._getTemplatePath(template) except KeyError: self.log.error( "Unable to process template '{0}'. Aborting.".format(template)) return None #read in the HTML self.log.debug('Generating nametag with nametag()') self.log.debug('Reading {0}...'.format( os.path.join(directory, 'default.html'))) f = open(os.path.join(directory, 'default.html')) html = f.read() f.close() if len(html) == 0: #template file is empty: use default instead. self.log.warn('HTML template file {0} is blank.'.format( os.path.join(directory, 'default.html'))) #generate barcode of secure code, code128: if barcode: try: if secure == '': codebar.gen('code128', os.path.join(directory, 'default-secure.png'), code) else: codebar.gen('code128', os.path.join(directory, 'default-secure.png'), secure) except NotImplementedError as e: self.log.error('Unable to generate barcode: {0}'.format(e)) html = html.replace(u'default-secure.png', u'white.gif') else: #replace barcode image with white.gif html = html.replace(u'default-secure.png', u'white.gif') self.log.debug("Disabled barcode.") #get the current date/time now = datetime.datetime.now() #Perform substitutions: html = self.date_re.sub(now.strftime("%a %d %b, %Y"), html) html = self.time_re.sub(now.strftime("%H:%M:%S"), html) html = self.room_re.sub(room, html) #Fix for if database returns None instead of empty string: if medical == None: medical = '' html = self.first_re.sub(str(first), html) html = self.last_re.sub(str(last), html) html = self.medical_re.sub(str(medical), html) html = self.code_re.sub(code, html) html = self.secure_re.sub(secure, html) #show medical icon if len(medical) > 0: html = self.medicalIcon_re.sub('', html) return html
def nametag(self, template='default', room='', first='', last='', medical='', code='', secure='', barcode=True): """ Convenience function for generating nametag html and the coresponding barcodes. Applies data to a nametag template and returns the resulting HTML. Does not query database; pass barcode bool to disable. Accepts template theme from listTemplates() as first argument; 'default' if none. Accepts the following formats (defaults are blank): - room - first - last - medical - code - secure - Barcode=True This method processes default.html only. Disabled barcodes will be replaced with white.gif """ #Check that theme specified is valid: if template != 'default': themes = self.listTemplates() if template not in themes: self.log.error("Bad theme specified. Using default instead.") template = 'default' #Read in the HTML from template. try: directory = self._getTemplatePath(template) except KeyError: self.log.error("Unable to process template '{0}'. Aborting." .format(template)) return None #read in the HTML self.log.debug('Generating nametag with nametag()') self.log.debug('Reading {0}...'.format(os.path.join(directory, 'default.html'))) f = open(os.path.join(directory, 'default.html')) html = f.read() f.close() if len(html) == 0: #template file is empty: use default instead. self.log.warn('HTML template file {0} is blank.'.format( os.path.join(directory, 'default.html'))) #generate barcode of secure code, code128: if barcode: try: if secure == '': codebar.gen('code128', os.path.join(directory, 'default-secure.png'), code) else: codebar.gen('code128', os.path.join(directory, 'default-secure.png'), secure) except NotImplementedError as e: self.log.error('Unable to generate barcode: {0}'.format(e)) html = html.replace(u'default-secure.png', u'white.gif') else: #replace barcode image with white.gif html = html.replace(u'default-secure.png', u'white.gif') self.log.debug("Disabled barcode.") #get the current date/time now = datetime.datetime.now() #Perform substitutions: html = self.date_re.sub(now.strftime("%a %d %b, %Y"), html) html = self.time_re.sub(now.strftime("%H:%M:%S"), html) html = self.room_re.sub(room, html) #Fix for if database returns None instead of empty string: if medical == None: medical = '' html = self.first_re.sub(str(first), html) html = self.last_re.sub(str(last), html) html = self.medical_re.sub(str(medical), html) html = self.code_re.sub(code, html) html = self.secure_re.sub(secure, html) #show medical icon if len(medical) > 0: html = self.medicalIcon_re.sub('', html) return html