Completed the template editing functionality
[biaweb_qt.git] / templates_dialog.py
index efd5bd7..64cc70c 100644 (file)
@@ -21,10 +21,10 @@ class TemplatesDialog (PyQt4.QtGui.QDialog, ui_templates_dialog.Ui_TemplatesDial
 
        def onEdit (self):
                # get the currently selected list item
-               tpl_name = self.templates.currentItem ().data (0).toString ()
+               tpl_name = str (self.templates.currentItem ().data (0).toString ())
 
                # get the template content from the database
-               tpl_str = biaweb_db.get_template_text (self.current_db, str (tpl_name))
+               tpl_str = biaweb_db.get_template_text (self.current_db, tpl_name)
 
                # if template string cannot be obtained for some reason
                if tpl_str == False:
@@ -32,4 +32,13 @@ class TemplatesDialog (PyQt4.QtGui.QDialog, ui_templates_dialog.Ui_TemplatesDial
                else:
                        # open edit dialog with title "template name" and text as the template string
                        edlg = editor_dialog.EditorDialog (self, tpl_name, tpl_str)
-                       edlg.exec_ ()
+                       # if editing is confirmed
+                       if edlg.exec_ () == PyQt4.QtGui.QDialog.Accepted:
+                               upd_tpl_str = str (edlg.text.toPlainText ()).strip ()
+
+                               # update the template with the new template string
+                               ret = biaweb_db.update_template (self.current_db, tpl_name, upd_tpl_str)
+                               # if update failed
+                               if ret == False:
+                                       PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in updating template")
+