Exemplo n.º 1
0
    def save(self):
        q = QSqlQuery()

        try:
            if not self.txtAlbum.hasAcceptableInput():
                raise UnacceptableInputException
            if not self.txtYear.hasAcceptableInput():
                raise UnacceptableInputException
            if not self.txtTracks.hasAcceptableInput():
                raise UnacceptableInputException
            if not self.txtLength.hasAcceptableInput():
                raise UnacceptableInputException
        except UnacceptableInputException:
            print tr(self, "Erreur: Les cases sont mal remplies")
        except:
            print tr(self, "Erreur inconnue")
        else:
            duree = db.formatterDuree(self.txtLength.text())

            q.prepare("INSERT INTO albums (artist, album, year, genre, tracks, length) " + \
                "VALUES (?,?,?,?,?,?)")
            q.addBindValue(QVariant(self.cmbArtist.currentText()))
            q.addBindValue(QVariant(self.txtAlbum.text()))
            q.addBindValue(QVariant(self.txtYear.text()))
            q.addBindValue(QVariant(self.cmbGenre.currentText()))
            q.addBindValue(QVariant(self.txtTracks.text()))
            q.addBindValue(QVariant(duree))

            q.exec_()
            self.accept()
Exemplo n.º 2
0
    def setValue(self, col, id, value):
        if (col == 1 or col == 2 or col == 4):  #Artist, album, genre
            pattern = "^[a-zA-Z0-9.,':!?()&\- ]+$"
        elif (col == 3):    #year
            pattern = "^[0-9]{4}$"
        elif (col == 5):    #tracks
            pattern = "^[0-9]{1,2}$"
        elif (col == 6):    #length
            pattern = "^([0-9]{1,2}[:-])?[0-9]{1,2}[:-][0-9]{1,2}$"

        m = re.search(pattern, value.__str__())
        print value
        if not m:
            return False

        q = QSqlQuery()
        q.prepare("UPDATE albums SET " + self.columns[col] + " = ? WHERE id = ?")
        if (col == 6):
            q.addBindValue(db.formatterDuree(value))
        else:
            q.addBindValue(value)
        q.addBindValue(id)
        return q.exec_()
Exemplo n.º 3
0
    def setValue(self, col, id, value):
        if (col == 1 or col == 2 or col == 4):  #Artist, album, genre
            pattern = "^[a-zA-Z0-9.,':!?()&\- ]+$"
        elif (col == 3):  #year
            pattern = "^[0-9]{4}$"
        elif (col == 5):  #tracks
            pattern = "^[0-9]{1,2}$"
        elif (col == 6):  #length
            pattern = "^([0-9]{1,2}[:-])?[0-9]{1,2}[:-][0-9]{1,2}$"

        m = re.search(pattern, value.__str__())
        print value
        if not m:
            return False

        q = QSqlQuery()
        q.prepare("UPDATE albums SET " + self.columns[col] +
                  " = ? WHERE id = ?")
        if (col == 6):
            q.addBindValue(db.formatterDuree(value))
        else:
            q.addBindValue(value)
        q.addBindValue(id)
        return q.exec_()