Exemplo n.º 1
0
    def map_from_row(self, row):
        """
        creates model.Operator.Operator instance from list of string-s: row 
        
        :param row: list of string-s  
        :return: model.Operator.Operator
        """
        ret = None
        try:
            id = int(row[0])
            create_date = row[1]
            create_time = row[2]
            # print(row[3])
            create_userfullname = row[3]
            create_userid = row[4]
            update_date = row[5]
            update_time = row[6]
            update_userfullname = row[7]
            update_userid = row[8]
            emp_id = row[9]
            emp_name = row[10]
            is_validator = row[11]
            remark = row[12]
            ret = Operator(id, create_date, create_time, create_userfullname, create_userid, update_date, update_time, update_userfullname, update_userid, emp_id, emp_name, is_validator, remark)
        except Exception as err:
            print(err)

        return ret
    def example1(self):
        """
        
        :return: 
        """
        dao = OperatorDAOSqliteImpl()
        dao.drop_table()
        dao.create_table()
        l = [
            Operator(1, "foo", "bar", datetime.date(1991, 10, 10), "ai",
                     "*****@*****.**"),
            Operator(2, "edu", "tilos", datetime.date(1992, 10, 10), "ai",
                     "*****@*****.**"),
            Operator(3, "leo", "messi", datetime.date(1993, 10, 10), "ai",
                     "*****@*****.**")
        ]

        for s in l:
            dao.save(s)

        all = dao.find_all()
        print("<<all operators>>")
        for s in all:
            print(s)

        # update
        dao.update(
            1,
            Operator(1, "new_foo", "new_bar", datetime.date(2001, 11, 11),
                     "its", "*****@*****.**"))

        # find one
        one = dao.find_by_id(1)
        print("after update = {0}".format(one))

        # remove one
        dao.remove(1)
        all = dao.find_all()
        print("<<all operators after remove by enrolmentNumber = 1>>")
        for s in all:
            print(s)
 def map_rs_to_operator(self, props):
     """
     maps result set from mongo query into model.Operator.Operator
     
     :param props:  dict of strings 
     :return: model.Operator.Operator 
     """
     dob_str = props["dob"]
     splitted = dob_str.split("-")
     year, month, day = int(splitted[0]), int(splitted[1]), int(splitted[2])
     dob = datetime.date(year, month, day)
     return Operator(int(props["enrolmentNumber"]), props["firstName"],
                     props["lastName"], dob, props["faculty"],
                     props["email"])
Exemplo n.º 4
0
    def onBtnSaveClicked(self):
        """
        Slot for signal-slot handling .
        Gets invoked when btnSave is clicked.
        :return: 
        """
        try:
            errors = []
            code = self.editCode.text()
            name = self.editName.text()
            validation = self.editValidation.itemText(
                self.editValidation.currentIndex())
            remark = self.editRemark.text()

            if not self.validator.validateCode(code):
                errors.append("code is incorrect.")

            if not self.validator.validateName(name):
                errors.append("name is incorrect.")

            if not self.validator.validateValidation(validation):
                errors.append("Validation is incorrect.")

            if not self.validator.validateRemark(remark):
                errors.append("Remark is incorrect.")

            if len(errors) > 0:
                raise Exception("\n".join(errors))

            ret = self.dao.save(
                Operator(0, "", "", "", "", "", "", "", "", code, name,
                         validation, remark))

            if ret:
                raise Exception(ret)

            rowPosition = self.tableWidget.rowCount()
            self.tableWidget.insertRow(rowPosition)
            self.tableWidget.setItem(rowPosition, 10, QTableWidgetItem(code))
            self.tableWidget.setItem(rowPosition, 11, QTableWidgetItem(name))
            self.tableWidget.setItem(rowPosition, 12,
                                     QTableWidgetItem(validation))
            self.tableWidget.setItem(rowPosition, 13, QTableWidgetItem(remark))

            self.close()

        except Exception as err:

            QMessageBox.critical(self, "<<Error>>", str(err))
 def map_from_json(self, data):
     """
     creates model.Operator.Operator instance from json map - data
     
     :param data: json map 
     :return: model.Operator.Operator 
     """
     enrolmentNumber = int(data['enrolmentNumber'])
     firstName = data['firstName']
     lastName = data['lastName']
     dob = data['dob']
     faculty = data['faculty']
     email = data['email']
     return Operator(enrolmentNumber, firstName, lastName, dob, faculty,
                     email)
Exemplo n.º 6
0
 def map_from_xml(self, operator_xml):
     """
     creates model.Operator.Operator instance from xml content: operator_xml
     
     :param operator_xml: xml content , which was parsed by Beautifulsoup library
     :return: model.Operator.Operator
     """
     enrolmentNumber = operator_xml.attrs["enrolmentnumber"]
     firstName = operator_xml.find("firstname").contents[0]
     lastName = operator_xml.find("lastname").contents[0]
     dob = operator_xml.find("dob").contents[0]
     faculty = operator_xml.find("faculty").contents[0]
     email = operator_xml.find("email").contents[0]
     return Operator(enrolmentNumber, firstName, lastName, dob, faculty,
                     email)
    def onBtnUpdateClicked(self):
        """
        Slot for signal-slot handling .
        Gets invoked when btnUpdate is clicked.
        :return: 
        """
        try:
            errors = []
            id = self.editId.text()
            code = self.editCode.text()
            name = self.editName.text()
            validation = self.editValidation.itemText(self.editValidation.currentIndex())
            remark = self.editRemark.text()
            if not self.validator.validateId(id):
                errors.append("id is incorrect.")

            if not self.validator.validateCode(code):
                errors.append("code is incorrect.")

            if not self.validator.validateName(name):
                errors.append("name is incorrect.")

            if not self.validator.validateValidation(validation):
                errors.append("DateOfBirth is incorrect.")

            if not self.validator.validateRemark(remark):
                errors.append("Remark is incorrect.")

            if len(errors) > 0 :
                raise Exception("\n".join(errors))


            self.dao.update(id, Operator(id, "", "", "", "", "", "", "", "", code, name,
                                  validation, remark))


            self.selectedItems[0].setText(id)
            self.selectedItems[1].setText(code)
            self.selectedItems[2].setText(name)
            self.selectedItems[3].setText(validation)
            self.selectedItems[4].setText(remark)

            self.close()

        except Exception as err:
            QMessageBox.critical(self, "<<Error>>", str(err))
 def map_from_list(self, data):
     """
     create model.Operator.Operator instance from list of strings - data
     :param data: list of strings 
     :return: model.Operator.Operator
     """
     ret = Operator()
     ret.id = int(data[0])
     ret.create_date = data[1]
     ret.create_time = data[2]
     # ret.create_userfullname = datetime.datetime.strptime(data[3], '%Y-%m-%d')
     ret.create_userfullname = data[3]
     ret.create_userid = data[4]
     ret.update_date = data[5]
     ret.update_time = data[6]
     ret.update_userfullname = data[7]
     ret.update_userid = data[8]
     ret.emp_id = data[9]
     ret.emp_name = data[10]
     ret.is_validator = data[11]
     ret.remark = data[12]
     return ret