walterbyrd a scris:
With PHP, libraries, apps, etc. to do basic CRUD are everywhere. Ajax
and non-Ajax solutions abound.
With Python, finding such library, or apps. seems to be much more
difficult to find.
I thought django might be a good way, but I can not seem to get an
answer on that board.
I would like to put together a CRUD grid with editable/deletable/
addable fields, click on the headers to sort. Something that would
sort-of looks like an online spreadsheet. It would be nice if the
fields could be edited in-line, but it's not entirely necessary.
Are there any Python libraries to do that sort of thing? Can it be
done with django or cherrypy?
Please, don't advertise your PHP/Ajax apps.
SqlAlchemy - SqlSoup - PyQt4 (fragment) example:
import sys
from PyQt4.Qt import *
from PyQt4 import uic
from avc.avcqt4 import *
from sqlalchemy.ext.sqlsoup import SqlSoup
from ui_db import Ui_DbForm
class DbForm(QWidget,AVC):
def __init__(self, parent=None):
QWidget.__init__(self,parent)
self.ui = Ui_DbForm()
self.ui.setupUi(self)
# current index
self.crtIndex = 0
self.crtPk = 0
# avc variables, same names as form widgets (lineEdit, combo,
etc....)
self.edtId = 0
self.edtFirstName = ""
self.edtLastName = ""
self.edtSalary = 0.0
self.connect(self.ui.btnQuit, SIGNAL("clicked()"),
qApp, SLOT("quit()"))
self.connect(self.ui.btnFirst, SIGNAL("clicked()"),
self.goFirst)
self.connect(self.ui.btnPrior, SIGNAL("clicked()"),
self.goPrior)
self.connect(self.ui.btnNext, SIGNAL("clicked()"),
self.goNext)
self.connect(self.ui.btnLast, SIGNAL("clicked()"),
self.goLast)
self.connect(self.ui.btnSave, SIGNAL("clicked()"),
self.doSave)
self.connect(self.ui.btnAdd, SIGNAL("clicked()"), self.doAdd)
self.connect(self.ui.btnDel, SIGNAL("clicked()"),
self.doDel)
# connection: 'postgres://user

assword@address

ort/db_name'
self.db = SqlSoup('postgres://postgres

ostgres@localhost:5432/
testdb')
self.goFirst()
def goFirst(self):
self.crtIndex = 0
self.doRead(self.crtIndex)
def goPrior(self):
if self.crtIndex > 0:
self.crtIndex = self.crtIndex - 1
else:
self.crtIndex = 0
self.doRead(self.crtIndex)
def goNext(self):
maxIndex = self.db.person.count() - 1
if self.crtIndex < maxIndex:
self.crtIndex = self.crtIndex + 1
else:
self.crtIndex = maxIndex
self.doRead(self.crtIndex)
def goLast(self):
maxIndex = self.db.person.count() - 1
self.crtIndex = maxIndex
self.doRead(self.crtIndex)
def doSave(self):
if self.crtPk == 0:
# aflu pk-ul si adaug o inregistrare goala
newPk = self.db.engine.execute("select
nextval('person_id_seq')").fetchone()[0]
self.crtPk = newPk
self.db.person.insert(id=self.crtPk, firstname='',
lastname='', salary=0.0)
self.db.flush()
person = self.db.person.selectone_by(id=self.crtPk)
person.firstname = self.edtFirstName
person.lastname = self.edtLastName
person.salary = self.edtSalary
self.db.flush()
def doAdd(self):
self.crtPk = 0
self.edtId = self.crtPk
self.edtFirstName = ""
self.edtLastName = ""
self.edtSalary = 0.0
# inregistrarea trebuie salvata explicit
# prin apasarea butonului "Save"
def doDel(self):
mk = self.db.person.selectone_by(id=self.crtPk)
self.db.delete(mk)
self.db.flush()
self.goNext()
def doRead(self, index):
person = self.db.person.select()
self.edtId = person[index].id
self.edtFirstName = person[index].firstname
self.edtLastName = person[index].lastname
self.edtSalary = person[index].salary
# invariant pt. toate operatiile, mai putin adaugare
inregistrare
# pk-ul nu se poate modifica prin edtId !!!
self.crtPk = person[index].id
if __name__ == "__main__":
app = QApplication(sys.argv)
# QApplication.setStyle(QStyleFactory.create("Cleanlooks"))
QApplication.setStyle(QStyleFactory.create("Plastique"))
form = DbForm()
form.avc_init()
form.show()
sys.exit(app.exec_())