Beispiel #1
0
 def getSelectedTemplate(self):
     """ Returns the id of the sticker template selected. If no specific
         template found in the request (parameter template), returns the
         default template set in Bika Setup > Stickers.
         If the template doesn't exist, uses the default bika.lims'
         Code_128_1x48mm.pt template (was sticker_small.pt).
         If no template selected but size param, get the sticker template
         set as default in Bika Setup for the size set.
     """
     bs_template = self.context.bika_setup.getAutoStickerTemplate()
     size = self.request.get('size', '')
     if size == 'small':
         bs_template = self.context.bika_setup.getSmallStickerTemplate()
     elif size == 'large':
         bs_template = self.context.bika_setup.getLargeStickerTemplate()
     rq_template = self.request.get('template', bs_template)
     # Check if the template exists. If not, fallback to default's
     if rq_template.find(':') >= 0:
         prefix, rq_template = rq_template.split(':')
         templates_dir = queryResourceDirectory('stickers', prefix).directory
     else:
         this_dir = os.path.dirname(os.path.abspath(__file__))
         templates_dir = os.path.join(this_dir, 'templates/stickers/')
     if not os.path.isfile(os.path.join(templates_dir, rq_template)):
         rq_template = 'Code_128_1x48mm.pt'
     return rq_template
Beispiel #2
0
 def getSelectedTemplate(self):
     """ Returns the id of the sticker template selected. If no specific
         template found in the request (parameter template), returns the
         default template set in Bika Setup > Stickers.
         If the template doesn't exist, uses the default bika.lims'
         Code_128_1x48mm.pt template (was sticker_small.pt).
         If no template selected but size param, get the sticker template
         set as default in Bika Setup for the size set.
     """
     bs_template = self.context.bika_setup.getAutoStickerTemplate()
     size = self.request.get('size', '')
     if size == 'small':
         bs_template = self.context.bika_setup.getSmallStickerTemplate()
     elif size == 'large':
         bs_template = self.context.bika_setup.getLargeStickerTemplate()
     rq_template = self.request.get('template', bs_template)
     # Check if the template exists. If not, fallback to default's
     if rq_template.find(':') >= 0:
         prefix, rq_template = rq_template.split(':')
         templates_dir = queryResourceDirectory('stickers',
                                                prefix).directory
     else:
         this_dir = os.path.dirname(os.path.abspath(__file__))
         templates_dir = os.path.join(this_dir, 'templates/stickers/')
     if not os.path.isfile(os.path.join(templates_dir, rq_template)):
         rq_template = 'Code_128_1x48mm.pt'
     return rq_template
Beispiel #3
0
 def getReportStyle(self):
     """ Returns the css style to be used for the current template.
         If the selected template is 'default.pt', this method will
         return the content from 'default.css'. If no css file found
         for the current template, returns empty string
     """
     template = self.request.form.get('template', self._DEFAULT_TEMPLATE)
     content = ''
     if template.find(':') >= 0:
         prefix, template = template.split(':')
         resource = queryResourceDirectory('reports', prefix)
         css = '{0}.css'.format(template[:-3])
         if css in resource.listDirectory():
             content = resource.readFile(css)
     else:
         this_dir = os.path.dirname(os.path.abspath(__file__))
         templates_dir = os.path.join(this_dir, 'templates/reports/')
         path = '%s/%s.css' % (templates_dir, template[:-3])
         with open(path, 'r') as content_file:
             content = content_file.read()
     return content
Beispiel #4
0
 def getReportStyle(self):
     """ Returns the css style to be used for the current template.
         If the selected template is 'default.pt', this method will
         return the content from 'default.css'. If no css file found
         for the current template, returns empty string
     """
     template = self.request.form.get('template', self._DEFAULT_TEMPLATE)
     content = ''
     if template.find(':') >= 0:
         prefix, template = template.split(':')
         resource = queryResourceDirectory('reports', prefix)
         css = '{0}.css'.format(template[:-3])
         if css in resource.listDirectory():
             content = resource.readFile(css)
     else:
         this_dir = os.path.dirname(os.path.abspath(__file__))
         templates_dir = os.path.join(this_dir, 'templates/reports/')
         path = '%s/%s.css' % (templates_dir, template[:-3])
         with open(path, 'r') as content_file:
             content = content_file.read()
     return content
Beispiel #5
0
 def getReportTemplate(self):
     """ Returns the html template for the current ar and moves to
         the next ar to be processed. Uses the selected template
         specified in the request ('template' parameter)
     """
     templates_dir = 'templates/reports'
     embedt = self.request.form.get('template', self._DEFAULT_TEMPLATE)
     if embedt.find(':') >= 0:
         prefix, template = embedt.split(':')
         templates_dir = queryResourceDirectory('reports', prefix).directory
         embedt = template
     embed = ViewPageTemplateFile(os.path.join(templates_dir, embedt))
     reptemplate = ""
     try:
         reptemplate = embed(self)
     except:
         tbex = traceback.format_exc()
         arid = self._ars[self._current_ar_index].id
         reptemplate = "<div class='error-report'>%s - %s '%s':<pre>%s</pre></div>" % (arid, _("Unable to load the template"), embedt, tbex)
     self._nextAnalysisRequest()
     return reptemplate
Beispiel #6
0
 def renderWSTemplate(self):
     """ Returns the current worksheet rendered with the template
         specified in the request (param 'template').
         Moves the iterator to the next worksheet available.
     """
     templates_dir = self._TEMPLATES_DIR
     embedt = self.request.get('template', self._DEFAULT_TEMPLATE)
     if embedt.find(':') >= 0:
         prefix, embedt = embedt.split(':')
         templates_dir = queryResourceDirectory(self._TEMPLATES_ADDON_DIR, prefix).directory
     embed = ViewPageTemplateFile(os.path.join(templates_dir, embedt))
     reptemplate = ""
     try:
         reptemplate = embed(self)
     except:
         tbex = traceback.format_exc()
         wsid = self._worksheets[self._current_ws_index].id
         reptemplate = "<div class='error-print'>%s - %s '%s':<pre>%s</pre></div>" % (wsid, _("Unable to load the template"), embedt, tbex)
     if self._current_ws_index < len(self._worksheets):
         self._current_ws_index += 1
     return reptemplate
Beispiel #7
0
 def getReportTemplate(self):
     """ Returns the html template for the current ar and moves to
         the next ar to be processed. Uses the selected template
         specified in the request ('template' parameter)
     """
     templates_dir = 'templates/reports'
     embedt = self.request.form.get('template', self._DEFAULT_TEMPLATE)
     if embedt.find(':') >= 0:
         prefix, template = embedt.split(':')
         templates_dir = queryResourceDirectory('reports', prefix).directory
         embedt = template
     embed = ViewPageTemplateFile(os.path.join(templates_dir, embedt))
     reptemplate = ""
     try:
         reptemplate = embed(self)
     except:
         tbex = traceback.format_exc()
         arid = self._ars[self._current_ar_index].id
         reptemplate = "<div class='error-report'>%s - %s '%s':<pre>%s</pre></div>" % (
             arid, _("Unable to load the template"), embedt, tbex)
     self._nextAnalysisRequest()
     return reptemplate
Beispiel #8
0
 def renderWSTemplate(self):
     """ Returns the current worksheet rendered with the template
         specified in the request (param 'template').
         Moves the iterator to the next worksheet available.
     """
     templates_dir = self._TEMPLATES_DIR
     embedt = self.request.get('template', self._DEFAULT_TEMPLATE)
     if embedt.find(':') >= 0:
         prefix, embedt = embedt.split(':')
         templates_dir = queryResourceDirectory(self._TEMPLATES_ADDON_DIR,
                                                prefix).directory
     embed = ViewPageTemplateFile(os.path.join(templates_dir, embedt))
     reptemplate = ""
     try:
         reptemplate = embed(self)
     except:
         tbex = traceback.format_exc()
         wsid = self._worksheets[self._current_ws_index].id
         reptemplate = "<div class='error-print'>%s - %s '%s':<pre>%s</pre></div>" % (
             wsid, _("Unable to load the template"), embedt, tbex)
     if self._current_ws_index < len(self._worksheets):
         self._current_ws_index += 1
     return reptemplate
Beispiel #9
0
 def renderItem(self):
     """ Renders the next available sticker.
         Uses the template specified in the request ('template' parameter) by
         default. If no template defined in the request, uses the default
         template set by default in Bika Setup > Stickers.
         If the template specified doesn't exist, uses the default
         bika.lims' Code_128_1x48mm.pt template (was sticker_small.pt).
     """
     curritem = self.nextItem()
     templates_dir = 'templates/stickers'
     embedt = self.getSelectedTemplate()
     if embedt.find(':') >= 0:
         prefix, embedt = embedt.split(':')
         templates_dir = queryResourceDirectory('stickers', prefix).directory
     fullpath = os.path.join(templates_dir, embedt)
     try:
         embed = ViewPageTemplateFile(fullpath)
         return embed(self)
     except:
         tbex = traceback.format_exc()
         stickerid = curritem[2].id if curritem[2] else curritem[1].id
         return "<div class='error'>%s - %s '%s':<pre>%s</pre></div>" % \
                 (stickerid, _("Unable to load the template"), embedt, tbex)
Beispiel #10
0
 def renderItem(self):
     """ Renders the next available sticker.
         Uses the template specified in the request ('template' parameter) by
         default. If no template defined in the request, uses the default
         template set by default in Bika Setup > Stickers.
         If the template specified doesn't exist, uses the default
         bika.lims' Code_128_1x48mm.pt template (was sticker_small.pt).
     """
     curritem = self.nextItem()
     templates_dir = 'templates/stickers'
     embedt = self.getSelectedTemplate()
     if embedt.find(':') >= 0:
         prefix, embedt = embedt.split(':')
         templates_dir = queryResourceDirectory('stickers',
                                                prefix).directory
     fullpath = os.path.join(templates_dir, embedt)
     try:
         embed = ViewPageTemplateFile(fullpath)
         return embed(self)
     except:
         tbex = traceback.format_exc()
         stickerid = curritem[2].id if curritem[2] else curritem[1].id
         return "<div class='error'>%s - %s '%s':<pre>%s</pre></div>" % \
                 (stickerid, _("Unable to load the template"), embedt, tbex)
Beispiel #11
0
 def getSelectedTemplateCSS(self):
     """ Looks for the CSS file from the selected template and return its
         contents. If the selected template is default.pt, looks for a
         file named default.css in the stickers path and return its contents.
         If no CSS file found, retrns an empty string
     """
     template = self.getSelectedTemplate()
     # Look for the CSS
     content = ''
     if template.find(':') >= 0:
         # A template from another add-on
         prefix, template = template.split(':')
         resource = queryResourceDirectory('stickers', prefix)
         css = '{0}.css'.format(template[:-3])
         if css in resource.listDirectory():
             content = resource.readFile(css)
     else:
         this_dir = os.path.dirname(os.path.abspath(__file__))
         templates_dir = os.path.join(this_dir, 'templates/stickers/')
         path = '%s/%s.css' % (templates_dir, template[:-3])
         if os.path.isfile(path):
             with open(path, 'r') as content_file:
                 content = content_file.read()
     return content
Beispiel #12
0
 def getSelectedTemplateCSS(self):
     """ Looks for the CSS file from the selected template and return its
         contents. If the selected template is default.pt, looks for a
         file named default.css in the stickers path and return its contents.
         If no CSS file found, retrns an empty string
     """
     template = self.getSelectedTemplate()
     # Look for the CSS
     content = ''
     if template.find(':') >= 0:
         # A template from another add-on
         prefix, template = template.split(':')
         resource = queryResourceDirectory('stickers', prefix)
         css = '{0}.css'.format(template[:-3])
         if css in resource.listDirectory():
             content = resource.readFile(css)
     else:
         this_dir = os.path.dirname(os.path.abspath(__file__))
         templates_dir = os.path.join(this_dir, 'templates/stickers/')
         path = '%s/%s.css' % (templates_dir, template[:-3])
         if os.path.isfile(path):
             with open(path, 'r') as content_file:
                 content = content_file.read()
     return content