# Database handling functions
import sqlite3
+import os
+import os.path
+# function to create a category
+def create_category (dbname, category_name, category_desc, category_stub):
+ try:
+ conn = sqlite3.connect (dbname)
+ c = conn.cursor ()
+ c.execute ("INSERT INTO categories (name, desc, stub) VALUES (?, ?, ?);",
+ (category_name, category_desc, category_stub))
+ conn.commit ()
+ conn.close ()
+ return True
+ except sqlite3.Error:
+ return False
+
+
+# function to create a new site database
def create_db (dbname, site_title, site_url, keywords, description, copyright,
num_rss, dest_path):
+ try:
+ if os.path.exists (dbname):
+ os.remove (dbname)
+ except OSError:
+ return False
+
try:
conn = sqlite3.connect (dbname)
c = conn.cursor ()
--- /dev/null
+# BiaWeb Website content manager (c) 2010 V.Harishankar
+# Category dialog class
+
+import PyQt4
+import ui_category_dialog
+
+class CategoryDialog (PyQt4.QtGui.QDialog, ui_category_dialog.Ui_CategoryDialog):
+ def __init__ (self, parent):
+ PyQt4.QtGui.QDialog.__init__ (self, parent)
+ self.setupUi (self)
+
+ def accept (self):
+ category_name = str (self.category_name.text ()).strip ()
+ category_stub = str (self.category_stub.text ()).strip ()
+ if category_name <> "" and category_stub <> "":
+ PyQt4.QtGui.QDialog.accept (self)
+ else:
+ PyQt4.QtGui.QMessageBox.critical (self, "Missing fields", "Some required fields are missing")
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
+ <property name="font">
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
<property name="text">
<string>Category name</string>
</property>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
+ <property name="font">
+ <font>
+ <weight>50</weight>
+ <bold>false</bold>
+ </font>
+ </property>
<property name="text">
<string>Category description</string>
</property>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
+ <property name="font">
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
<property name="text">
<string>Stub (directory)</string>
</property>
import PyQt4
import ui_main_window
import site_configuration_dialog as scd
+import category_dialog as catd
import biaweb_db
import sys
self.setupUi (self)
self.current_db = None
+ # 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.")
+ else:
+ # show the category add dialog
+ dlg = catd.CategoryDialog (self)
+ # if OK button is pressed
+ if dlg.exec_ () == PyQt4.QtGui.QDialog.Accepted:
+ cat_name = str (dlg.category_name.text ()).strip ()
+ cat_desc = str (dlg.category_desc.text ()).strip ()
+ cat_stub = str (dlg.category_stub.text ()).strip ()
+ ret = biaweb_db.create_category (self.current_db, cat_name, cat_desc, cat_stub)
+ if ret == True:
+ PyQt4.QtGui.QMessageBox.information (self, "Success", "Category successfully created")
+ else:
+ PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in creating category")
+
+ # file new menu is clicked
def onFileNew (self):
+ # show the site configuration dialog to get the new site details
dlg = scd.SiteConfigDialog (self)
+ # if OK button is pressed
if dlg.exec_ () == PyQt4.QtGui.QDialog.Accepted:
site_title = str (dlg.site_title.text ()).strip ()
site_url = str (dlg.site_url.text ()).strip ()
savefilename = PyQt4.QtGui.QFileDialog.getSaveFileName (self, "Save site database to")
if savefilename:
- self.current_db = savefilename
+ self.current_db = str (savefilename)
self.setWindowTitle ("BiaWeb - " + self.current_db)
- flag = biaweb_db.create_db (str (savefilename), site_title, site_url, keywords, description,
+ flag = biaweb_db.create_db (self.current_db, site_title, site_url, keywords, description,
copyright, num_rss, destination)
if flag == True:
PyQt4.QtGui.QMessageBox.information (self, "Success",
"New site db successfully created")
else:
- PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in creating database.")
+ PyQt4.QtGui.QMessageBox.critical (self, "Error", "System or SQLite 3 error in creating database")
+ # file quit is clicked
def onFileQuit (self):
sys.exit (0)
</hint>
</hints>
</connection>
+ <connection>
+ <sender>action_AddCategory</sender>
+ <signal>triggered()</signal>
+ <receiver>MainWindow</receiver>
+ <slot>onCategoryAdd()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>-1</x>
+ <y>-1</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>316</x>
+ <y>228</y>
+ </hint>
+ </hints>
+ </connection>
</connections>
<slots>
<slot>onFileNew()</slot>
<slot>onFileQuit()</slot>
+ <slot>onCategoryAdd()</slot>
</slots>
</ui>
self.destination.setText (destpath)
def accept (self):
+ # check the required fields before accepting
site_title = str (self.site_title.text ()).strip ()
site_url = str (self.site_url.text ()).strip ()
keywords = str (self.keywords.text ()).strip ()
# Form implementation generated from reading ui file 'category_dialog.ui'
#
-# Created: Wed Nov 24 14:12:44 2010
+# Created: Fri Nov 26 17:27:34 2010
# by: PyQt4 UI code generator 4.7.4
#
# WARNING! All changes made in this file will be lost!
self.gridLayout = QtGui.QGridLayout(CategoryDialog)
self.gridLayout.setObjectName("gridLayout")
self.label = QtGui.QLabel(CategoryDialog)
+ font = QtGui.QFont()
+ font.setWeight(75)
+ font.setBold(True)
+ self.label.setFont(font)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.category_name = QtGui.QLineEdit(CategoryDialog)
self.category_name.setObjectName("category_name")
self.gridLayout.addWidget(self.category_name, 0, 1, 1, 1)
self.label_2 = QtGui.QLabel(CategoryDialog)
+ font = QtGui.QFont()
+ font.setWeight(50)
+ font.setBold(False)
+ self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1)
self.category_desc = QtGui.QLineEdit(CategoryDialog)
self.category_desc.setObjectName("category_desc")
self.gridLayout.addWidget(self.category_desc, 1, 1, 1, 1)
self.label_3 = QtGui.QLabel(CategoryDialog)
+ font = QtGui.QFont()
+ font.setWeight(75)
+ font.setBold(True)
+ self.label_3.setFont(font)
self.label_3.setObjectName("label_3")
self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1)
self.category_stub = QtGui.QLineEdit(CategoryDialog)
# Form implementation generated from reading ui file 'main_window.ui'
#
-# Created: Fri Nov 26 13:58:47 2010
+# Created: Fri Nov 26 17:19:44 2010
# by: PyQt4 UI code generator 4.7.4
#
# WARNING! All changes made in this file will be lost!
self.retranslateUi(MainWindow)
QtCore.QObject.connect(self.actionNew_site, QtCore.SIGNAL("triggered()"), MainWindow.onFileNew)
QtCore.QObject.connect(self.action_Quit, QtCore.SIGNAL("triggered()"), MainWindow.onFileQuit)
+ QtCore.QObject.connect(self.action_AddCategory, QtCore.SIGNAL("triggered()"), MainWindow.onCategoryAdd)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):