Some first steps towards data validation.

pull/17/head
Christian Jacobs 2013-03-25 02:41:58 +00:00
rodzic c5a22e3ca3
commit fc2f6124fa
2 zmienionych plików z 67 dodań i 26 usunięć

Wyświetl plik

@ -91,23 +91,39 @@ class PyQSO(Gtk.Window):
return
def add_record_callback(self, widget):
dialog = RecordDialog(self, index=None)
all_valid = False # Are all the field entries valid?
response = dialog.run()
if(response == Gtk.ResponseType.OK):
fields_and_data = {}
field_names = self.logbook.SELECTED_FIELD_NAMES_ORDERED
for i in range(0, len(field_names)):
#TODO: Validate user input!
fields_and_data[field_names[i]] = dialog.get_data(field_names[i])
while(not all_valid):
# This while loop gives the user infinite attempts at giving valid data.
# The add/edit record window will stay open until the user gives valid data,
# or until the Cancel button is clicked.
all_valid = True
response = dialog.run() #FIXME: Is it ok to call .run() multiple times on the same RecordDialog object?
if(response == Gtk.ResponseType.OK):
fields_and_data = {}
field_names = self.logbook.SELECTED_FIELD_NAMES_ORDERED
for i in range(0, len(field_names)):
#TODO: Validate user input!
fields_and_data[field_names[i]] = dialog.get_data(field_names[i])
if(not(dialog.is_valid(field_names[i], fields_and_data[field_names[i]]))):
# Data is not valid - inform the user.
message = Gtk.MessageDialog(self, Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MessageType.ERROR, Gtk.ButtonsType.OK,
"The data in field \"%s\" is not valid!" % field_names[i])
message.run()
message.destroy()
all_valid = False
break # Don't check the other data until the user has fixed the current one.
self.logbook.add_record(fields_and_data)
# Select the new Record's row.
self.treeselection.select_path(self.logbook.get_number_of_records()-1)
if(all_valid):
# All data has been validated, so we can go ahead and add the new record.
self.logbook.add_record(fields_and_data)
# Select the new Record's row in the treeview.
self.treeselection.select_path(self.logbook.get_number_of_records()-1)
dialog.destroy()
return
def delete_record_callback(self, widget):
@ -145,22 +161,39 @@ class PyQSO(Gtk.Window):
return
dialog = RecordDialog(self, index=row_index)
all_valid = False # Are all the field entries valid?
while(not all_valid):
# This while loop gives the user infinite attempts at giving valid data.
# The add/edit record window will stay open until the user gives valid data,
# or until the Cancel button is clicked.
all_valid = True
response = dialog.run() #FIXME: Is it ok to call .run() multiple times on the same RecordDialog object?
if(response == Gtk.ResponseType.OK):
fields_and_data = {}
field_names = self.logbook.SELECTED_FIELD_NAMES_ORDERED
for i in range(0, len(field_names)):
#TODO: Validate user input!
fields_and_data[field_names[i]] = dialog.get_data(field_names[i])
if(not(dialog.is_valid(field_names[i], fields_and_data[field_names[i]]))):
# Data is not valid - inform the user.
message = Gtk.MessageDialog(self, Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MessageType.ERROR, Gtk.ButtonsType.OK,
"The data in field \"%s\" is not valid!" % field_names[i])
message.run()
message.destroy()
all_valid = False
break # Don't check the other data until the user has fixed the current one.
if(all_valid):
# All data has been validated, so we can go ahead and add the new record.
# First update the Record object...
self.logbook.records[row_index].set_data(field_names[i], fields_and_data[field_names[i]])
# ...and then the Logbook.
# (we add 1 onto the column_index here because we don't want to consider the index column)
self.logbook[row_index][i+1] = fields_and_data[field_names[i]]
response = dialog.run()
if(response == Gtk.ResponseType.OK):
fields_and_data = {}
field_names = self.logbook.SELECTED_FIELD_NAMES_ORDERED
for i in range(0, len(field_names)):
#TODO: Validate user input!
fields_and_data[field_names[i]] = dialog.get_data(field_names[i])
# First update the Record object...
self.logbook.records[row_index].set_data(field_names[i], fields_and_data[field_names[i]])
# ...and then the Logbook.
# (we add 1 onto the column_index here because we don't want to consider the index column)
self.logbook[row_index][i+1] = fields_and_data[field_names[i]]
dialog.destroy()
return
def show_about(self, widget):

Wyświetl plik

@ -89,6 +89,7 @@ class RecordDialog(Gtk.Dialog):
vbox_inner.pack_start(hbox_temp, False, False, 6)
if(index is not None):
# The record already exists, so display its current data in the input boxes.
record = parent.logbook.get_record(index)
field_names = parent.logbook.SELECTED_FIELD_NAMES_ORDERED
for i in range(0, len(field_names)):
@ -103,6 +104,13 @@ class RecordDialog(Gtk.Dialog):
def get_data(self, field_name):
return self.sources[field_name].get_text()
def is_valid(self, field_name, data):
if(field_name == "FREQ"):
return True
else:
return True
def lookup_callback(self, widget):
# TODO: If a session doesn't already exist: Show a username and password dialog, and initiate a session.
# Get the callsign-related data from the qrz.com database.