def removeTranslate(self, translateWordId, silent=False): if silent == False: msgBox = QtGui.QMessageBox() msgBox.setIcon(QtGui.QMessageBox.Question) msgBox.setWindowIcon(QtGui.QIcon(":/res/images/dictionary.png")) # TODO: собрать больше информации о переводе. id явно не достаточно. Добавить: # : 1) str value # : 2) количество переводов, в которых он задействован # : 3) количество словарей, в которых он задействован msgBox.setText( u"Вы действительно хотите удалить перевод: id = {id}".format( id=translateWordId)) msgBox.setWindowTitle(u"Удаление перевода") msgBox.setStandardButtons(QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel) if msgBox.exec_() != QtGui.QMessageBox.Ok: return False return SqlQuery( self, ''' DELETE FROM rus_eng WHERE word_[eng]_id = :word_id AND word_[rus]_id = :translate_id ''', { ':word_id': self.wordId, ':translate_id': translateWordId }).execute()
def addTranslateLink(id): return SqlQuery( self, ''' INSERT INTO rus_eng (word_[rus]_id, word_[eng]_id, [rus]_order, [eng]_order) VALUES (:w[r]_id, :w[e]_id, :[r]o, :[e]o) ''', { ':w[r]_id': id, ':w[e]_id': self.wordId, ':[r]o': self.rowCount() + 1, ':[e]o': 1 }).execute()
def removeLink(): return SqlQuery( self, ''' DELETE FROM word_[eng]_dict WHERE dict_[eng]_id = :dict_id AND word_[eng]_id = :word_id ''', { ':dict_id': self.dictListModel.dictId, ':word_id': wordId } ).execute()
def addWordLink(self, wordId): return SqlQuery( self, ''' INSERT INTO word_[eng]_dict (dict_[eng]_id, word_[eng]_id) VALUES (:dict_id, :w[e]_id) ''', { ':dict_id': self.dictListModel.dictId, ':w[e]_id': wordId, } ).execute()
def changeOrder(self, row1, row2): return SqlQuery( self, ''' INSERT INTO rus_eng (word_[rus]_id, word_[eng]_id, [rus]_order) VALUES (:w[r]_id1, :w[e]_id1, :[r]o1),(:w[r]_id2, :w[e]_id2, :[r]o2) ON DUPLICATE KEY UPDATE [rus]_order=VALUES([rus]_order) ''', { ":w[r]_id1": self.wordTranslateId(row1), ":w[r]_id2": self.wordTranslateId(row2), ":[r]o1": self.wordTranslateOrder(row2), ":[r]o2": self.wordTranslateOrder(row1), ":w[e]_id1": self.wordId, ":w[e]_id2": self.wordId }).execute()
def refresh(self): query = SqlQuery( self, ''' SELECT word_[rus].id as w[r]_id, word_[rus].value as w[r]_value, rus_eng.[rus]_order as r[e]_[rus]_order, word_[rus].meaning as w[r]_meaning FROM word_[eng] JOIN rus_eng ON rus_eng.word_[eng]_id = word_[eng].id JOIN word_[rus] ON word_[rus].id = rus_eng.word_[rus]_id WHERE word_[eng].id = {word_id} ORDER BY rus_eng.[rus]_order ASC '''.format(word_id=self.wordId)).str() self.setQuery(query) for idx, field in enumerate(self.headerFields): self.setHeaderData(idx, QtCore.Qt.Horizontal, field) self.onRefresh()
def refresh(self): query = SqlQuery( self, u''' SELECT d_id, w[e]_id, w[e]_value, w[r]_value FROM ( SELECT DISTINCT word_[eng].id as w[e]_id, dict_[eng].id as d_id, word_[eng].value as w[e]_value, word_[rus].value as w[r]_value from dict_[eng] JOIN word_[eng]_dict ON word_[eng]_dict.dict_[eng]_id = dict_[eng].id JOIN word_[eng] ON word_[eng].id = word_[eng]_dict.word_[eng]_id LEFT JOIN rus_eng ON rus_eng.word_[eng]_id = word_[eng].id LEFT JOIN word_[rus] ON word_[rus].id = rus_eng.word_[rus]_id WHERE dict_[eng].id = {dict_id} ORDER BY rus_eng.[rus]_order ) as x GROUP BY d_id, w[e]_id '''.format(dict_id=self.dictListModel.dictId), ).str() self.setQuery(query) for idx, field in enumerate(self.headerFields): self.setHeaderData(idx, QtCore.Qt.Horizontal, field) self.onRefresh()
def addEmptyWord(): return SqlQuery( self, 'INSERT INTO word_[rus] (id) VALUES (NULL)').execute(True)
def wordTranslateOrder(self, recordIndex): return self.record(recordIndex).value( SqlQuery(self, 're_[rus]_order').str())
def wordTranslateId(self, recordIndex): return self.record(recordIndex).value(SqlQuery(self, 'w[r]_id').str())
def wordId(self, recordIndex): return self.record(recordIndex).value(SqlQuery(self, 'w[e]_id').str())
def translateValue(self, recordIndex): return self.record(recordIndex).value(SqlQuery(self, 'w[r]_value').str())