From: Harishankar Date: Sat, 27 Nov 2010 10:55:06 +0000 (+0530) Subject: Site configuration updating implemented X-Git-Url: https://harishankar.org/repos/?a=commitdiff_plain;h=3632ca174c91a33db13178bc19ad2f93473b52c0;p=biaweb_qt.git Site configuration updating implemented Now the site configuration dialog works fully for updating the configuration for the currently open website --- diff --git a/biaweb_db.py b/biaweb_db.py index 576f284..2c8e6cd 100644 --- a/biaweb_db.py +++ b/biaweb_db.py @@ -4,7 +4,55 @@ import sqlite3 import os import os.path -import pprint + +# function to set the configuration and update the database +def set_configuration (dbname, site_title, site_url, keywords, description, copyright, + num_rss, dest_path): + try: + conn = sqlite3.connect (dbname) + c = conn.cursor () + c.executemany ("UPDATE config SET config_param=? WHERE config_name=?;", + [[site_url, "Website URL"], + [site_title, "Website Title"], + [keywords, "Keywords"], + [description, "Description"], + [num_rss, "No. of RSS items"], + [dest_path, "Destination path"], + [copyright, "Copyright"]]) + conn.commit () + conn.close () + return True + except sqlite3.Error: + return False + +# function to get the existing site configuration and return it as a tuple +def get_configuration (dbname): + try: + conn = sqlite3.connect (dbname) + c = conn.cursor () + c.execute ("SELECT * FROM config;") + conn.commit () + recs = c.fetchall () + conn.close () + for name, param in recs: + if name == "Website URL": + website_url = param + elif name == "Website Title": + website_title = param + elif name == "Keywords": + keywords = param + elif name == "Description": + description = param + elif name == "No. of RSS items": + num_rss = int (param) + elif name == "Destination path": + destination = param + elif name == "Copyright": + copyright = param + return (website_url, website_title, keywords, description, num_rss, destination, copyright) + except sqlite3.Error: + return False + # function to create a category def create_category (dbname, category_name, category_desc, category_stub): @@ -30,6 +78,7 @@ def get_articles (dbname, category_id=None): c.execute ("SELECT * FROM articles WHERE cid=?", (category_id,)) conn.commit () rows = c.fetchall () + conn.close () return rows except sqlite3.Error: return False diff --git a/main_window.py b/main_window.py index b6cb96d..f917e76 100644 --- a/main_window.py +++ b/main_window.py @@ -38,12 +38,44 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow): qrow = PyQt4.QtGui.QTreeWidgetItem ([str(item[0]), str(item[1])]) self.articles.addTopLevelItem (qrow) + # configuration dialog + def onConfiguration (self): + if self.current_db == None: + PyQt4.QtGui.QMessageBox.critical (self, "Error", + "Cannot edit configuration. You need to create or open a website first") + else: + dlg = scd.SiteConfigDialog (self) + configs = biaweb_db.get_configuration (self.current_db) + + dlg.site_url.setText (configs[0]) + dlg.site_title.setText (configs[1]) + dlg.keywords.setText (configs[2]) + dlg.description.setPlainText (configs[3]) + dlg.num_rss_items.setValue (configs[4]) + dlg.destination.setText (configs[5]) + dlg.copyright.setText (configs[6]) + + if (dlg.exec_ () == PyQt4.QtGui.QDialog.Accepted): + site_title = str (dlg.site_title.text ()).strip () + site_url = str (dlg.site_url.text ()).strip () + keywords = str (dlg.keywords.text ()).strip () + destination = str (dlg.destination.text ()).strip () + description = str (dlg.description.toPlainText ()).strip () + num_rss = dlg.num_rss_items.value () + copyright = str (dlg.copyright.text ()).strip () + flag = biaweb_db.set_configuration (self.current_db, site_title, site_url, keywords, description, + copyright, num_rss, destination) + if flag == False: + PyQt4.QtGui.QMessageBox.critical (self, "Error", + "SQLite 3 error in updating configuration") + + # category add action def onCategoryAdd (self): # if there is no database if self.current_db == None: PyQt4.QtGui.QMessageBox.critical (self, "Error", - "Cannot add category. You need to create or open a website first.") + "Cannot add category. You need to create or open a website first") else: # show the category add dialog dlg = catd.CategoryDialog (self) diff --git a/main_window.ui b/main_window.ui index dc14412..4e20f6d 100644 --- a/main_window.ui +++ b/main_window.ui @@ -24,6 +24,9 @@ + + true + Article ID @@ -329,11 +332,28 @@ + + action_Configuration + triggered() + MainWindow + onConfiguration() + + + -1 + -1 + + + 316 + 228 + + + onFileNew() onFileQuit() onCategoryAdd() onFileOpen() + onConfiguration() diff --git a/ui_main_window.py b/ui_main_window.py index bce3eb7..46ecb10 100644 --- a/ui_main_window.py +++ b/ui_main_window.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'main_window.ui' # -# Created: Sat Nov 27 14:06:22 2010 +# Created: Sat Nov 27 16:21:08 2010 # by: PyQt4 UI code generator 4.7.4 # # WARNING! All changes made in this file will be lost! @@ -21,6 +21,7 @@ class Ui_MainWindow(object): self.label_2.setObjectName("label_2") self.gridLayout.addWidget(self.label_2, 0, 0, 1, 1) self.articles = QtGui.QTreeWidget(self.centralwidget) + self.articles.setAlternatingRowColors(True) self.articles.setObjectName("articles") self.gridLayout.addWidget(self.articles, 1, 0, 1, 1) MainWindow.setCentralWidget(self.centralwidget) @@ -119,6 +120,7 @@ class Ui_MainWindow(object): QtCore.QObject.connect(self.action_Quit, QtCore.SIGNAL("triggered()"), MainWindow.onFileQuit) QtCore.QObject.connect(self.action_AddCategory, QtCore.SIGNAL("triggered()"), MainWindow.onCategoryAdd) QtCore.QObject.connect(self.action_Open_site, QtCore.SIGNAL("triggered()"), MainWindow.onFileOpen) + QtCore.QObject.connect(self.action_Configuration, QtCore.SIGNAL("triggered()"), MainWindow.onConfiguration) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow):