Exemplo n.º 1
0
 def setup_model(self):
     db = Db_Instance("edit_associate").get_instance()
     if not db.open():
         self.log.error(db.lastError().text())
         message = unicode("Erro de conexão\n\n""Banco de dados indisponível".decode('utf-8'))
         QMessageBox.critical(self, unicode("Seareiros - Edição de Associado".decode('utf-8')), message)
     else:
         self._model = QSqlRelationalTableModel(self, db=db)
         self._model.setTable("associate")
         self._act_model = QSqlRelationalTableModel(self, db=db)
         self._act_model.setTable("associate_in_activity")
         # TODO: Maybe I should validate these
         # associate
         self._model.setFilter("id = " + str(self._record_id))
         self._model.select()
         self._record = self._model.record(0)
         # activities
         self._activity_records = []
         sql_statement = """SELECT id, description, room, weekday, weektime FROM activity a,
                            associate_in_activity a_a WHERE
                            a.id = a_a.id_activity AND a_a.id_associate = %s
                         """ % str(self._record_id)
         model_activities = QSqlQueryModel()
         model_activities.setQuery(sql_statement, db)
         # checking query validity
         if not model_activities.lastError().isValid():
             self._activity_records = iterate_model(model_activities)
Exemplo n.º 2
0
 def check_barcode(self, txt):
     if len(txt) == self.edBarcode.maxLength():
         db = Db_Instance("obook_barcode_search").get_instance()
         try:
             if db.open():
                 query = QSqlQuery(db)
                 query.prepare("SELECT * FROM book WHERE barcode = :barcode")
                 query.bindValue(":barcode", txt)
                 query.exec_()
                 if query.next():
                     self.add_book_from_record(query.record())
                     self.edBarcode.clear()
                 else:
                     raise RecordNotFoundException
             else:
                 raise DbUnavailableException
         except RecordNotFoundException:
             message = unicode("Código de barra inválido!\n\n"""
                           "O código informado não corresponde a nenhum livro cadastrado".decode('utf-8'))
             QMessageBox.critical(self, "Seareiros - Livraria", message)
         except DbUnavailableException:
             self.log.error(db.lastError().text())
             message = unicode("Erro de conexão\n\n""Banco de dados indisponível".decode('utf-8'))
             QMessageBox.critical(self, "Seareiros - Livraria", message)
         self.edBarcode.setFocus()
Exemplo n.º 3
0
 def setup_model(self):
     db = Db_Instance("form_book").get_instance()
     if not db.open():
         self.log.error(db.lastError().text())
         message = unicode("Erro de conexão\n\n" "Banco de dados indisponível".decode("utf-8"))
         QMessageBox.critical(self, "Seareiros - Cadastro de Livro", message)
     else:
         # book
         self._model = QSqlTableModel(self, db=db)
         self._model.setTable("book")
         # subject
         self._subject_model = QSqlTableModel(self, db=db)
         self._subject_model.setTable("subject")
         self._subject_model.select()
         # author
         self._author_model = QSqlTableModel(self, db=db)
         self._author_model.setTable("author")
         self._author_model.select()
         # sauthor
         self._s_author_model = QSqlTableModel(self, db=db)
         self._s_author_model.setTable("s_author")
         self._s_author_model.select()
         # publisher
         self._publisher_model = QSqlTableModel(self, db=db)
         self._publisher_model.setTable("publisher")
         self._publisher_model.select()
         # book subjects
         self._book_in_subj_model = QSqlTableModel(self, db=db)
         self._book_in_subj_model.setTable("book_in_subject")
Exemplo n.º 4
0
 def setup_model(self):
     db = Db_Instance("form_associate").get_instance()
     if not db.open():
         self.log.error(db.lastError().text())
         message = unicode("Erro de conexão\n\n""Banco de dados indisponível".decode('utf-8'))
         QMessageBox.critical(self, "Seareiros - Cadastro de Associado", message)
     else:
         self._model = QSqlRelationalTableModel(self, db=db)
         self._model.setTable("associate")
         self._act_model = QSqlRelationalTableModel(self, db=db)
         self._act_model.setTable("associate_in_activity")
Exemplo n.º 5
0
 def setup_model(self):
     db = Db_Instance("oform_book").get_instance()
     if not db.open():
         self.log.error(db.lastError().text())
         message = unicode("Erro de conexão\n\n""Banco de dados indisponível".decode('utf-8'))
         QMessageBox.critical(self, "Seareiros - Livraria", message)
     else:
         # book order
         self._model = QSqlTableModel(self, db=db)
         self._model.setTable("order_request")
         # book order items
         self._items_model = QSqlTableModel(self, db=db)
         self._items_model.setTable("book_order_item")
Exemplo n.º 6
0
 def _get_name_from_id(self, table, id):
     db = Db_Instance(table + "_fetch_" + str(id) + "_name").get_instance()
     if not db.open():
         return None
     else:
         query = QSqlQuery(db)
         query.prepare("SELECT name FROM %s WHERE id = :id" % table)
         query.bindValue(":name", id)
         query.exec_()
         if query.next():
             return query.record().value("name")
         else:
             return None
Exemplo n.º 7
0
 def _get_id_from_name(self, table, name):
     db = Db_Instance(table + "_fetch_" + name + "_id").get_instance()
     if not db.open():
         return None
     else:
         query = QSqlQuery(db)
         query.prepare("SELECT id FROM %s WHERE name = :name" % table)
         query.bindValue(":name", name)
         query.exec_()
         if query.next():
             return query.record().value("id")
         else:
             return None
Exemplo n.º 8
0
 def get_added_record(self):
     db = Db_Instance("added_book_record").get_instance()
     if db.open() and self._book_id:
         query = QSqlQuery(db)
         query.prepare("SELECT * FROM book WHERE id = :id")
         query.bindValue(":id", self._book_id)
         query.exec_()
         if query.next():
             return query.record()
         else:
             return None
     else:
         return None
Exemplo n.º 9
0
 def setup_model(self):
     db = Db_Instance("oform_product").get_instance()
     if not db.open():
         self.log.error(db.lastError().text())
         message = unicode("Erro de conexão\n\n" "Banco de dados indisponível".decode("utf-8"))
         QMessageBox.critical(self, "Seareiros - Vendas do Bazar", message)
     else:
         # product order
         self._model = QSqlTableModel(self, db=db)
         self._model.setTable("order_request")
         # product order items
         self._items_model = QSqlTableModel(self, db=db)
         self._items_model.setTable("product_order_item")
Exemplo n.º 10
0
 def get_added_record(self):
     """ My workaround to get the last inserted id without any postgres specific queries """
     db = Db_Instance("add_associate_last_id").get_instance()
     if not db.open():
         return None
     else:
         query = QSqlQuery(db)
         query.prepare("SELECT * FROM associate WHERE fullname = :fullname")
         query.bindValue(":fullname", self.edFullName.text())
         query.exec_()
         if query.next():
             return query.record()
         else:
             return None
Exemplo n.º 11
0
    def setup_model(self):
        db = Db_Instance("edit_book").get_instance()
        if not db.open():
            self.log.error(db.lastError().text())
            message = unicode("Erro de conexão\n\n""Banco de dados indisponível".decode('utf-8'))
            QMessageBox.critical(self, unicode("Seareiros - Edição de Livro".decode('utf-8')), message)
        else:
            # book
            self._model = QSqlRelationalTableModel(self, db=db)
            self._model.setTable("book")
            self._model.setFilter("id = " + str(self._record_id))
            # self._model.setRelation(self.column["author"], QSqlRelation("author", "id", "name"))
            # self._model.setRelation(self.column["s_author"], QSqlRelation("s_author", "id", "name"))
            # self._model.setRelation(self.column["publisher"], QSqlRelation("publisher", "id", "name"))
            self._model.select()
            self._record = self._model.record(0)
            # models for setting up qcompleters:
            # book_in_subject
            self._book_in_subj_model = QSqlTableModel(self, db=db)
            self._book_in_subj_model.setTable("book_in_subject")
            # subject
            self._subject_model = QSqlTableModel(self, db=db)
            self._subject_model.setTable("subject")
            self._subject_model.select()
            # author
            self._author_model = QSqlTableModel(self, db=db)
            self._author_model.setTable("author")
            self._author_model.select()
            # s_author
            self._s_author_model = QSqlTableModel(self, db=db)
            self._s_author_model.setTable("s_author")
            self._s_author_model.select()
            # publisher
            self._publisher_model = QSqlTableModel(self, db=db)
            self._publisher_model.setTable("publisher")
            self._publisher_model.select()

            # retrieving current subjects, should probably place this elsewhere but it's related to models
            self._subject_records = []
            sql_statement = """SELECT id, name FROM subject s, book_in_subject b_s
                               WHERE s.id = b_s.subject_id AND b_s.book_id = %s
                            """ % str(self._record_id)
            read_only_subject_model = QSqlQueryModel()
            read_only_subject_model.setQuery(sql_statement, db)
            # checking query validity
            if not read_only_subject_model.lastError().isValid():
                self._subj_records = iterate_model(read_only_subject_model)