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 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)