コード例 #1
0
ファイル: _naf_itemmodel.py プロジェクト: VCTLabs/openadams
 def submit(self):
     # read current item in database
     afId = self.submitRecord["id"]
     self.cur = nafdb.connection.cursor()
     cmd = "select * from %s where id=?" % (self.tableName,)
     self.cur.execute(cmd, (afId,))
     currentData = self.cur.fetchone()
     # compare current item to submitted item, write changes to a dictionary
     changeRecord = []
     for column, data in zip(self.columns, currentData):
         if self.submitRecord.has_key(column) and data != self.submitRecord[column]:
             if column == "image":
                 # TODO: is this nice to handle image this way
                 changeRecord.append(
                     {"table": self.tableName, "column": column, "old": "not shown", "new": "not shown"}
                 )
             else:
                 changeRecord.append(
                     {"table": self.tableName, "column": column, "old": data, "new": self.submitRecord[column]}
                 )
     # update submitted item in database
     clause = ",".join(["%s=?" % columnName for columnName in self.submitRecord.iterkeys()])
     cmd = "update %s set %s where id==?;" % (self.tableName, clause)
     values = self.submitRecord.values() + [afId]
     self.cur.execute(cmd, values)
     # save identified changes in database
     (user, timestamp) = nafdb.getUserAndDate()
     title = self._fmtChangeTitle(afId, currentData)
     (changeId, parentId, typeid, title) = nafdb.newItem("changes", title, None, makeChangeEntry=False)
     cmd = "update changes set description=?, afid=?, changetype=?, date=?, user=? where id=?"
     self.cur.execute(cmd, (json.dumps(changeRecord), afId, nafdb.CHANGETYPE_EDITED, timestamp, user, changeId))
     nafdb.connection.commit()
     self.submitRecord = {}
     logging.info(cmd)
     return True
コード例 #2
0
ファイル: _naf_itemmodel.py プロジェクト: pmzhou/openadams
 def submit(self):
     # read current item in database
     afId = self.submitRecord['id']
     self.cur = nafdb.connection.cursor()
     cmd = "select * from %s where id=?" % (self.tableName, )
     self.cur.execute(cmd, (afId, ))
     currentData = self.cur.fetchone()
     # compare current item to submitted item, write changes to a dictionary
     changeRecord = []
     for column, data in zip(self.columns, currentData):
         if self.submitRecord.has_key(column) and data != self.submitRecord[column]:
             if column == 'image':
                 # TODO: is this nice to handle image this way
                 changeRecord.append({'table':self.tableName, 'column': column, 'old': 'not shown', 'new': 'not shown'})
             else:
                 changeRecord.append({'table':self.tableName, 'column': column, 'old': data, 'new': self.submitRecord[column]})
     # update submitted item in database
     clause = ','.join(['%s=?' % columnName for columnName in self.submitRecord.iterkeys()])
     cmd = 'update %s set %s where id==?;' % (self.tableName, clause)
     values = self.submitRecord.values() + [afId, ]
     self.cur.execute(cmd, values)
     # save identified changes in database
     (user, timestamp) = nafdb.getUserAndDate()
     title = self._fmtChangeTitle(afId, currentData)
     (changeId, parentId, typeid, title) = nafdb.newItem('changes', title, None, makeChangeEntry=False)
     cmd = 'update changes set description=?, afid=?, changetype=?, date=?, user=? where id=?'
     self.cur.execute(cmd, (json.dumps(changeRecord), afId, nafdb.CHANGETYPE_EDITED, timestamp, user, changeId))        
     nafdb.connection.commit()
     self.submitRecord = {}
     logging.info(cmd)
     return True
コード例 #3
0
ファイル: _naf_tree.py プロジェクト: pmzhou/openadams
 def addItem(self, tableName, itemTitle, index):
     if self.getItemType(index) == TYPE_FOLDER:
         parent = index
     else:
         parent = self.parent(index)
     n = self.rowCount(parent)
     parentId = self.getItemId(parent)
     newItem = nafdb.newItem(tableName, itemTitle, parentId)
     self.items.addItem(newItem)
     self.insertRow(n, parent)
     return self.index(n, 0, parent)
コード例 #4
0
ファイル: _naf_tree.py プロジェクト: VCTLabs/openadams
 def addItem(self, tableName, itemTitle, index):
     if self.getItemType(index) == TYPE_FOLDER:
         parent = index
     else:
         parent = self.parent(index)
     n = self.rowCount(parent)
     parentId = self.getItemId(parent)
     newItem = nafdb.newItem(tableName, itemTitle, parentId)
     self.items.addItem(newItem)
     self.insertRow(n, parent)
     return self.index(n, 0, parent)