Skip to content

Commit b43f640

Browse files
author
stephanie
committed
fix saving a new series
1 parent 1e20fec commit b43f640

File tree

8 files changed

+310
-511
lines changed

8 files changed

+310
-511
lines changed

odmtools/gui/wizSave.py

Lines changed: 83 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,19 @@ def on_wizard_finished(self, event):
189189
site, variable, method, action, proc_level = self.get_metadata()
190190
#if qcl exits use its its
191191
closeSuccessful = False
192-
193-
rbSave = self.pgIntro.pnlIntroduction.rbSave.GetValue()
194-
rbSaveAsNew = self.pgIntro.pnlIntroduction.rbSaveAs.GetValue()
195-
rbSaveAsExisting = self.pgIntro.pnlIntroduction.rbSaveExisting.GetValue()
196-
if rbSaveAsExisting:
197-
append = self.pgExisting.pnlExisting.rbAppend.GetValue()
198-
overwrite = self.pgExisting.pnlExisting.rbOverwrite.GetValue()
199-
if append:
200-
original = self.pgExisting.pnlExisting.rbOriginal.GetValue()
201-
new = self.pgExisting.pnlExisting.rbNew.GetValue()
202-
203-
if proc_level.ProcessingLevelID == 0 and not rbSaveAsNew:
192+
saveSuccessful=False
193+
194+
self.rbSave = self.pgIntro.pnlIntroduction.rbSave.GetValue()
195+
self.rbSaveAsNew = self.pgIntro.pnlIntroduction.rbSaveAs.GetValue()
196+
self.rbSaveAsExisting = self.pgIntro.pnlIntroduction.rbSaveExisting.GetValue()
197+
if self.rbSaveAsExisting:
198+
self.append = self.pgExisting.pnlExisting.rbAppend.GetValue()
199+
self.overwrite = self.pgExisting.pnlExisting.rbOverwrite.GetValue()
200+
if self.append:
201+
self.original = self.pgExisting.pnlExisting.rbOriginal.GetValue()
202+
self.new = self.pgExisting.pnlExisting.rbNew.GetValue()
203+
204+
if proc_level.ProcessingLevelID == 0 and not self.rbSaveAsNew:
204205
"""
205206
If we're looking at a QCL with Control level 0 and the following cases:
206207
Save
@@ -212,19 +213,19 @@ def on_wizard_finished(self, event):
212213
wx.YES_NO | wx.ICON_QUESTION)
213214
if val == 2:
214215
logger.info("User selected yes to save a level 0 dataset")
215-
val_2 = wx.MessageBox("This interactive_item cannot be undone.\nAre you sure you are sure?\n",
216+
val_2 = wx.MessageBox("This cannot be undone.\nAre you sure you are sure?\n",
216217
'Are you REALLY sure?',
217218
wx.YES_NO | wx.ICON_QUESTION)
218219
if val_2 == 2:
219220
closeSuccessful = True
220221

221-
elif rbSaveAsExisting:
222+
elif self.rbSaveAsExisting:
222223
keyword = "overwrite"
223224

224225
if self.pgExisting.pnlExisting.rbAppend.GetValue():
225226
keyword = "append to"
226227

227-
message = "You are about to " + keyword + " an existing series_service,\nthis interactive_item cannot be undone.\nWould you like to continue?\n"
228+
message = "You are about to " + keyword + " an existing series_service,\nthis cannot be undone.\nWould you like to continue?\n"
228229
cont = wx.MessageBox(message, 'Are you sure?', wx.YES_NO | wx.ICON_QUESTION)
229230
if cont == 2:
230231
closeSuccessful = True
@@ -234,95 +235,80 @@ def on_wizard_finished(self, event):
234235
closeSuccessful = True
235236

236237
if closeSuccessful:
237-
#if qcl exists use its id
238-
# if self.series_service.qcl_exists(QCL):
239-
# if QCL == self.currSeries.quality_control_level:
240-
# QCL = None
241-
# else:
242-
# QCL = self.record_service.get_qcl(QCL)
243-
# else:
244-
# QCL = self.record_service.create_processing_level(QCL.code, QCL.definition, QCL.explanation)
245-
if self.series_service.get_processing_level_by_code(proc_level.ProcessingLevelCode) is None:
246-
proc_level = self.series_service.create_processing_level(proc_level.ProcessingLevelCode, proc_level.Definition, proc_level.Explanation)
247-
elif proc_level.ProcessingLevelCode == self.__processing_level_from_series.ProcessingLevelCode:
248-
proc_level = None
249-
else:
250-
proc_level = self.series_service.get_processing_level_by_code(proc_level.ProcessingLevelCode)
251-
252-
253-
#if variable exists use its id
254-
# if self.series_service.variable_exists(Variable):
255-
# Variable = self.record_service.get_variable(Variable)
256-
# else:
257-
# Variable = self.record_service.create_variable(Variable)
258-
if self.series_service.get_variable_by_code(variable.VariableCode) is None:
259-
variable = self.series_service.create_variable_by_var(variable)
260-
else:
261-
variable = self.series_service.get_variable_by_code(variable.VariableCode)
262-
263-
264-
#if method exists use its id
265-
# if self.series_service.method_exists(Method):
266-
# if Method == self.currSeries.method:
267-
# Method = None
268-
# else:
269-
# Method = self.record_service.get_method(Method)
270-
# else:
271-
# Method = self.record_service.create_method(Method)
272-
if self.series_service.get_method_by_code(method.MethodCode) is None:
273-
method = self.series_service.create_method(method.MethodDescription, method.MethodLink)
274-
elif method == self.__method_from_series:
275-
method = None
276-
else:
277-
method = self.series_service.get_method_by_code(method.MethodCode)
278-
279-
# initiate either "Save as" or "Save"
280-
'''
281-
if self.page1.pnlIntroduction.rbSave.GetValue():
282-
result = self.record_service.save(Variable, Method, QCL, False)
283-
else:
284-
result = self.record_service.saveAs(Variable, Method, QCL, True)
285-
'''
286-
affiliation = self.action_page.get_affiliation()
287-
288-
action_by = ActionBy()
289-
#action_by.ActionID = action.ActionID
290-
action_by.RoleDescription = self.action_page.action_view.role_description_text_box.GetValue()
291-
action_by.AffiliationID = affiliation.AffiliationID
292-
action_by.AffiliationObj = affiliation
293-
294-
# result = self.series_service.getResult(var=variable, meth=method, proc=proc_level, action=action, actionby=action_by)
295-
result = self.pgExisting.pnlExisting.olvSeriesList.GetSelectedObject().ResultObj
296-
297-
#result = self.record_service._edit_service.getResult(var=variable, meth=method, proc=proc_level, action=action, actionby=action_by)
298-
299238
try:
300-
if rbSave:
301-
result = self.record_service.save()
302-
elif rbSaveAsNew:
303-
result = self.record_service.save_as(variable=variable, method=method, proc_level=proc_level,
304-
action=action, action_by=action_by)
305-
elif rbSaveAsExisting:
306-
if overwrite:
307-
result = self.record_service.save_existing(result=result)
308-
elif append:
309-
#TODO send in just the result
310-
#def save_appending(self, var = None, method =None, qcl = None, overwrite = False):
311-
#TODO if i require that original or new is selected I can call once with overwrite = original
312-
if original:
313-
result = self.record_service.save_appending(result=result, overwrite=False)
314-
elif new:
315-
result = self.record_service.save_appending(result=result, overwrite=True)
316-
317-
Publisher.sendMessage("refreshSeries")
318-
319-
#self.page1.pnlIntroduction.rb
239+
saveSuccessful = self.try_to_save(variable, method, proc_level, action)
320240
except Exception as e:
321241
message = "Save was unsuccessful %s" % e.message
322242
logger.error(message)
323243
wx.MessageBox(message, "Error!", wx.ICON_ERROR | wx.ICON_EXCLAMATION)
244+
saveSuccessful=False
245+
246+
if saveSuccessful:
324247
event.Skip()
325248
self.Close()
249+
self.Destroy()
250+
251+
def create_needed_meta(self, proc_level,variable, method):
252+
if self.series_service.get_processing_level_by_code(proc_level.ProcessingLevelCode) is None:
253+
proc_level = self.series_service.create_processing_level(proc_level.ProcessingLevelCode, proc_level.Definition, proc_level.Explanation)
254+
elif proc_level.ProcessingLevelCode == self.__processing_level_from_series.ProcessingLevelCode:
255+
proc_level = None
256+
else:
257+
proc_level = self.series_service.get_processing_level_by_code(proc_level.ProcessingLevelCode)
258+
259+
260+
261+
if self.series_service.get_variable_by_code(variable.VariableCode) is None:
262+
variable = self.series_service.create_variable_by_var(variable)
263+
else:
264+
variable = self.series_service.get_variable_by_code(variable.VariableCode)
265+
266+
267+
268+
if self.series_service.get_method_by_code(method.MethodCode) is None:
269+
method = self.series_service.create_method(method.MethodDescription, method.MethodLink)
270+
elif method == self.__method_from_series:
271+
method = None
272+
else:
273+
method = self.series_service.get_method_by_code(method.MethodCode)
274+
275+
276+
def try_to_save(self, variable, method, proc_level, action):
277+
self.create_needed_meta(proc_level, variable, method)
278+
affiliation = self.action_page.get_affiliation()
279+
280+
action_by = ActionBy()
281+
# action_by.ActionID = action.ActionID
282+
action_by.RoleDescription = self.action_page.action_view.role_description_text_box.GetValue()
283+
action_by.AffiliationID = affiliation.AffiliationID
284+
action_by.AffiliationObj = affiliation
285+
286+
# result = self.series_service.getResult(var=variable, meth=method, proc=proc_level, action=action, actionby=action_by)
287+
result = self.pgExisting.pnlExisting.olvSeriesList.GetSelectedObject().ResultObj
288+
289+
if self.rbSave:
290+
result = self.record_service.save()
291+
elif self.rbSaveAsNew:
292+
result = self.record_service.save_as(variable=variable, method=method, proc_level=proc_level,
293+
action=action, action_by=action_by)
294+
elif self.rbSaveAsExisting:
295+
if self.overwrite:
296+
result = self.record_service.save_existing(result=result)
297+
elif self.append:
298+
#TODO send in just the result
299+
#def save_appending(self, var = None, method =None, qcl = None, overwrite = False):
300+
#TODO if i require that original or new is selected I can call once with overwrite = original
301+
if self.original:
302+
result = self.record_service.save_appending(result=result, overwrite=False)
303+
elif self.new:
304+
result = self.record_service.save_appending(result=result, overwrite=True)
305+
306+
Publisher.sendMessage("refreshSeries")
307+
return True
308+
309+
310+
311+
326312

327313

328314

odmtools/odmdata/memory_database.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from sqlalchemy import bindparam
44

55
from odmtools.common.logger import LoggerTool
6-
from odmtools.odmservices import SeriesService
76
from odmtools.odmservices import ServiceManager, SeriesService
87

98
# from odmtools.odmdata import SeriesService#ODM
@@ -12,11 +11,10 @@
1211
from odm2api.ODM2.models import setSchema
1312
import pandas as pd
1413

15-
1614
logger =logging.getLogger('main')
1715

1816
class MemoryDatabase(object):
19-
### this code should be changed to work with the database abstract layer so that sql queries are not in the code
17+
## this code should be changed to work with the database abstract layer so that sql queries are not in the code
2018

2119
# series_service is a SeriesService
2220
def __init__(self, taskserver=None):
@@ -75,7 +73,6 @@ def getDataValuesDF(self):
7573
logging.debug("done updating memory dataframe")
7674
return self.df
7775

78-
7976
def get_annotations(self, query_db_again=False):
8077
# self.mem_service._session.commit()
8178
setSchema(self.series_service._session_factory.engine)
@@ -84,8 +81,6 @@ def get_annotations(self, query_db_again=False):
8481
annotation = self.series_service.get_annotations_by_result(resultid=result_id)
8582
self.results_annotations = annotation
8683

87-
88-
8984
def getDataValues(self):
9085
# TODO: fix me! this commit location is only temoporarily. should be flushing so that we can restore
9186
self.mem_service._session.commit()

0 commit comments

Comments
 (0)