+ # function to get the category or article ID from current selected item in a tree widget
+ def get_selected_item_id (self, twidget):
+ selitems = twidget.selectedItems ()
+ if selitems:
+ # get the first column data as integer
+ selindex = selitems[0].data(0, 0).toInt ()[0]
+ return selindex
+ else:
+ return None
+
+ # category edit action
+ def onCategoryEdit (self):
+ # if no database is open
+ if self.current_db == None:
+ PyQt4.QtGui.QMessageBox.critical (self, "Error",
+ "Cannot edit category. You need to create or open a website first")
+ # database is open
+ else:
+ catid = self.get_selected_item_id (self.categories)
+ # if no category is selected, display an error
+ if catid is None:
+ PyQt4.QtGui.QMessageBox.critical (self, "Error", "No category selected")
+ # category is selected
+ else:
+ cat = biaweb_db.get_category (self.current_db, catid)
+ # if the category cannot be retrieved from database
+ if cat == False:
+ PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error reading category")
+ return
+
+ # set the data in the dialog
+ dlg = catd.CategoryDialog (self)
+ dlg.category_name.setText (cat[1])
+ dlg.category_desc.setText (cat[2])
+ dlg.category_stub.setText (cat[3])
+
+ # if accepted
+ if dlg.exec_ () == PyQt4.QtGui.QDialog.Accepted:
+ category_name = str (dlg.category_name.text ()).strip ()
+ category_desc = str (dlg.category_desc.text ()).strip ()
+ category_stub = str (dlg.category_stub.text ()).strip ()
+
+ ret = biaweb_db.update_category (self.current_db,
+ catid, category_name, category_desc, category_stub)
+ if ret == True:
+ PyQt4.QtGui.QMessageBox.information (self, "Success", "Category successfully updated")
+ else:
+ PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in updating category")
+