20f2e18e76b88d7a4a8021aa31f0392a2310f7ba
1 # BiaWeb Website content manager (c) 2010 V.Harishankar
2 # Templates dialog class
5 import ui_templates_dialog
9 class TemplatesDialog (PyQt4
.QtGui
.QDialog
, ui_templates_dialog
.Ui_TemplatesDialog
):
10 def __init__ (self
, master
, currentdb
):
11 PyQt4
.QtGui
.QDialog
.__init
__ (self
, master
)
14 # set the current database
15 self
.current_db
= currentdb
17 # populate the templates
18 tpls
= biaweb_db
.get_templates (self
.current_db
)
19 # if templates populated
21 for tpl_name
, tpl_content
in tpls
:
22 self
.templates
.addItem (str (tpl_name
))
24 PyQt4
.QtGui
.QMessageBox
.critical (self
, "Error", "SQLite 3 error in retrieving templates")
27 # get the currently selected list item
28 sel_item
= self
.templates
.currentItem ()
29 # if no item is selected return
32 tpl_name
= str (sel_item
.data (0).toString ())
34 # get the template content from the database
35 tpl_str
= biaweb_db
.get_template_text (self
.current_db
, tpl_name
)
37 # if template string cannot be obtained for some reason
39 PyQt4
.QtGui
.QMessageBox
.critical (self
, "Error", "SQLite 3 error in retrieving template")
41 # open edit dialog with title "template name" and text as the template string
42 edlg
= editor_dialog
.EditorDialog (self
, tpl_name
, tpl_str
)
43 # if editing is confirmed
44 if edlg
.exec_ () == PyQt4
.QtGui
.QDialog
.Accepted
:
45 upd_tpl_str
= str (edlg
.text
.toPlainText ()).strip ()
47 # update the template with the new template string
48 ret
= biaweb_db
.update_template (self
.current_db
, tpl_name
, upd_tpl_str
)
51 PyQt4
.QtGui
.QMessageBox
.critical (self
, "Error", "SQLite 3 error in updating template")