mirror of
https://github.com/Kalenis/kalenislims.git
synced 2023-12-14 07:13:04 +01:00
lims_instrument: use base object for results importer
This commit is contained in:
parent
1db6ea82ea
commit
8c59eb14fd
|
@ -30,7 +30,52 @@ class NotebookLine(metaclass=PoolMeta):
|
||||||
imported_inj_date = fields.Date('Inject date')
|
imported_inj_date = fields.Date('Inject date')
|
||||||
|
|
||||||
|
|
||||||
class ResultsImport(ModelSQL, ModelView):
|
class BaseImport(object):
|
||||||
|
|
||||||
|
controller = None
|
||||||
|
infile = None
|
||||||
|
rawresults = {}
|
||||||
|
mimetype = None
|
||||||
|
numline = 0
|
||||||
|
analysis_code = None
|
||||||
|
formula = None
|
||||||
|
header = []
|
||||||
|
|
||||||
|
def getInputFile(self):
|
||||||
|
return self.infile
|
||||||
|
|
||||||
|
def setInputFile(self, infile):
|
||||||
|
self.infile = infile
|
||||||
|
|
||||||
|
def loadController(self):
|
||||||
|
self.controller = None
|
||||||
|
|
||||||
|
def parse(self, infile):
|
||||||
|
self.rawresults = {}
|
||||||
|
if not self.controller:
|
||||||
|
self.loadController()
|
||||||
|
try:
|
||||||
|
return self.controller.parse(self, infile)
|
||||||
|
except AttributeError:
|
||||||
|
traceback.print_exc()
|
||||||
|
raise UserError(gettext('lims_instrument.msg_not_implemented',
|
||||||
|
function='parse'))
|
||||||
|
|
||||||
|
def exportResults(self):
|
||||||
|
'''
|
||||||
|
This function defines whether the importer
|
||||||
|
export results to a file at the end of the process.
|
||||||
|
Default is False
|
||||||
|
'''
|
||||||
|
if not self.controller:
|
||||||
|
self.loadController()
|
||||||
|
try:
|
||||||
|
return self.controller.exportResults(self)
|
||||||
|
except AttributeError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class ResultsImport(BaseImport, ModelSQL, ModelView):
|
||||||
'Results Import'
|
'Results Import'
|
||||||
__name__ = 'lims.resultsimport'
|
__name__ = 'lims.resultsimport'
|
||||||
_rec_name = 'description'
|
_rec_name = 'description'
|
||||||
|
@ -38,12 +83,6 @@ class ResultsImport(ModelSQL, ModelView):
|
||||||
name = fields.Selection([], 'Name', required=True, sort=False,
|
name = fields.Selection([], 'Name', required=True, sort=False,
|
||||||
depends=['description'])
|
depends=['description'])
|
||||||
description = fields.Char('Description', required=True)
|
description = fields.Char('Description', required=True)
|
||||||
controller = None
|
|
||||||
_infile = None
|
|
||||||
header = []
|
|
||||||
rawresults = {}
|
|
||||||
mimetype = None
|
|
||||||
numline = 0
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __setup__(cls):
|
def __setup__(cls):
|
||||||
|
@ -71,35 +110,6 @@ class ResultsImport(ModelSQL, ModelView):
|
||||||
raise UserError(gettext('lims_instrument.msg_not_module',
|
raise UserError(gettext('lims_instrument.msg_not_module',
|
||||||
module=self.name))
|
module=self.name))
|
||||||
|
|
||||||
def getInputFile(self):
|
|
||||||
return self._infile
|
|
||||||
|
|
||||||
def setInputFile(self, infile):
|
|
||||||
self._infile = infile
|
|
||||||
|
|
||||||
def parse(self, infile):
|
|
||||||
if not self.controller:
|
|
||||||
self.loadController()
|
|
||||||
try:
|
|
||||||
return self.controller.parse(self, infile)
|
|
||||||
except AttributeError:
|
|
||||||
traceback.print_exc()
|
|
||||||
raise UserError(gettext('lims_instrument.msg_not_implemented',
|
|
||||||
function='parse'))
|
|
||||||
|
|
||||||
def exportResults(self):
|
|
||||||
'''
|
|
||||||
This function defines whether the importer
|
|
||||||
export results to a file at the end of the process.
|
|
||||||
Default is False
|
|
||||||
'''
|
|
||||||
if not self.controller:
|
|
||||||
self.loadController()
|
|
||||||
try:
|
|
||||||
return self.controller.exportResults(self)
|
|
||||||
except AttributeError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class NotebookLoadResultsFileStart(ModelView):
|
class NotebookLoadResultsFileStart(ModelView):
|
||||||
'Load Results from File'
|
'Load Results from File'
|
||||||
|
@ -301,7 +311,6 @@ class NotebookLoadResultsFile(Wizard):
|
||||||
file_ = getattr(self.start, 'infile_%s' % fline)
|
file_ = getattr(self.start, 'infile_%s' % fline)
|
||||||
if not file_:
|
if not file_:
|
||||||
continue
|
continue
|
||||||
self.start.results_importer.rawresults = {}
|
|
||||||
self.start.results_importer.parse(file_)
|
self.start.results_importer.parse(file_)
|
||||||
raw_results = self.start.results_importer.rawresults
|
raw_results = self.start.results_importer.rawresults
|
||||||
fractions_numbers = list(raw_results.keys())
|
fractions_numbers = list(raw_results.keys())
|
||||||
|
@ -560,9 +569,8 @@ class NotebookLoadResultsFile(Wizard):
|
||||||
if warnings:
|
if warnings:
|
||||||
self.warning.msg = messages
|
self.warning.msg = messages
|
||||||
return 'warning'
|
return 'warning'
|
||||||
else:
|
if export_results:
|
||||||
if export_results:
|
return 'end' # 'export'
|
||||||
return 'end' # 'export'
|
|
||||||
return 'end'
|
return 'end'
|
||||||
|
|
||||||
def transition_cancel(self):
|
def transition_cancel(self):
|
||||||
|
|
|
@ -11,9 +11,6 @@ from . import custom_set_xls
|
||||||
class ResultsImport(metaclass=PoolMeta):
|
class ResultsImport(metaclass=PoolMeta):
|
||||||
__name__ = 'lims.resultsimport'
|
__name__ = 'lims.resultsimport'
|
||||||
|
|
||||||
analysis_code = None
|
|
||||||
formula = None
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __setup__(cls):
|
def __setup__(cls):
|
||||||
super().__setup__()
|
super().__setup__()
|
||||||
|
|
Loading…
Reference in a new issue