Code Duplication    Length = 21-22 lines in 4 locations

bika/lims/browser/sample/printform.py 1 location

@@ 511-532 (lines=22) @@
508
                (_("Unable to load the template"), embedt, tbex)
509
        return reptemplate
510
511
    def getCSS(self):
512
        """ Returns the css style to be used for the current template.
513
            If the selected template is 'default.pt', this method will
514
            return the content from 'default.css'. If no css file found
515
            for the current template, returns empty string
516
        """
517
        template = self.request.get('template', self._DEFAULT_TEMPLATE)
518
        content = ''
519
        if template.find(':') >= 0:
520
            prefix, template = template.split(':')
521
            resource = queryResourceDirectory(
522
                self._TEMPLATES_ADDON_DIR, prefix)
523
            css = '{0}.css'.format(template[:-3])
524
            if css in resource.listDirectory():
525
                content = resource.readFile(css)
526
        else:
527
            this_dir = os.path.dirname(os.path.abspath(__file__))
528
            templates_dir = os.path.join(this_dir, self._TEMPLATES_DIR)
529
            path = '%s/%s.css' % (templates_dir, template[:-3])
530
            with open(path, 'r') as content_file:
531
                content = content_file.read()
532
        return content
533
534
    def pdfFromPOST(self):
535
        """

bika/lims/browser/samplinground/printform.py 1 location

@@ 109-130 (lines=22) @@
106
            self._current_sr_index += 1
107
        return reptemplate
108
109
    def getCSS(self):
110
        """ Returns the css style to be used for the current template.
111
            If the selected template is 'default.pt', this method will
112
            return the content from 'default.css'. If no css file found
113
            for the current template, returns empty string
114
        """
115
        template = self.request.get('template', self._DEFAULT_TEMPLATE)
116
        content = ''
117
        if template.find(':') >= 0:
118
            prefix, template = template.split(':')
119
            resource = queryResourceDirectory(
120
                self._TEMPLATES_ADDON_DIR, prefix)
121
            css = '{0}.css'.format(template[:-3])
122
            if css in resource.listDirectory():
123
                content = resource.readFile(css)
124
        else:
125
            this_dir = os.path.dirname(os.path.abspath(__file__))
126
            templates_dir = os.path.join(this_dir, self._TEMPLATES_DIR)
127
            path = '%s/%s.css' % (templates_dir, template[:-3])
128
            with open(path, 'r') as content_file:
129
                content = content_file.read()
130
        return content
131
132
    def getAnalysisRequestTemplatesInfo(self):
133
        """

bika/lims/browser/analysisrequest/publish.py 1 location

@@ 233-253 (lines=21) @@
230
        self._nextAnalysisRequestGroup()
231
        return reptemplate
232
233
    def getReportStyle(self):
234
        """Returns the css style to be used for the current template.
235
        If the selected template is 'default.pt', this method will
236
        return the content from 'default.css'. If no css file found
237
        for the current template, returns empty string
238
        """
239
        template = self.request.form.get('template', self._DEFAULT_TEMPLATE)
240
        content = ''
241
        if template.find(':') >= 0:
242
            prefix, template = template.split(':')
243
            resource = queryResourceDirectory('reports', prefix)
244
            css = '{0}.css'.format(template[:-3])
245
            if css in resource.listDirectory():
246
                content = resource.readFile(css)
247
        else:
248
            this_dir = os.path.dirname(os.path.abspath(__file__))
249
            templates_dir = os.path.join(this_dir, 'templates/reports/')
250
            path = '%s/%s.css' % (templates_dir, template[:-3])
251
            with open(path, 'r') as content_file:
252
                content = content_file.read()
253
        return content
254
255
    def isSingleARTemplate(self):
256
        seltemplate = self.request.form.get('template', self._DEFAULT_TEMPLATE)

bika/lims/browser/worksheet/views/printview.py 1 location

@@ 138-158 (lines=21) @@
135
            self._current_ws_index += 1
136
        return reptemplate
137
138
    def getCSS(self):
139
        """ Returns the css style to be used for the current template.
140
            If the selected template is 'default.pt', this method will
141
            return the content from 'default.css'. If no css file found
142
            for the current template, returns empty string
143
        """
144
        template = self.request.get('template', self._DEFAULT_TEMPLATE)
145
        content = ''
146
        if template.find(':') >= 0:
147
            prefix, template = template.split(':')
148
            resource = queryResourceDirectory(self._TEMPLATES_ADDON_DIR, prefix)
149
            css = '{0}.css'.format(template[:-3])
150
            if css in resource.listDirectory():
151
                content = resource.readFile(css)
152
        else:
153
            this_dir = os.path.dirname(os.path.abspath(__file__))
154
            templates_dir = os.path.join(this_dir, self._TEMPLATES_DIR)
155
            path = '%s/%s.css' % (templates_dir, template[:-3])
156
            with open(path, 'r') as content_file:
157
                content = content_file.read()
158
        return content
159
160
    def getNumColumns(self):
161
        """ Returns the number of columns to display