Ejemplo n.º 1
0
    def do_add(self, line):
        """
        Add a new entry of data
        :param line: (String) [EMPID] [Age] [Gender] [Sales]
                    [BMI] [Salary] [Birthday]
        :return: None
        :Author: Zhiming Liu
        """
        # Split the input argument to obtain the data
        raw_data = list(arg.lower() for arg in str(line).split())

        try:
            # Check if input data has 7 data fields
            if not len(raw_data) == len(Data):
                raise AttributeError("Please input correct data.")
            else:
                # Check and wash data by check_all() of DataValidator
                result = self._vld.check_all(raw_data)
                # Check if there is any None which stands for invalid input
                if None in result:
                    key = 0
                    # build a list of name list
                    items = list(map(lambda i: i.name, Data))
                    e_str = ""
                    while key < len(result):
                        if result[key] is None:
                            # Left alignment
                            e_str += "{:<10}".format(items[key])
                        key += 1
                    raise ValueError("The following field(s) "
                                     "is invalid:\n%s" % e_str)
                else:
                    self._std.add_data(result)
        except (AttributeError, ValueError) as e:
            View.error(str(e) + "\n")
            View.help_add()
        except CSVError as e:
            View.error(e)
        except Exception as e:
            View.error(e)
        else:
            View.success("Add data")
Ejemplo n.º 2
0
 def help_add():
     View.help_add()
Ejemplo n.º 3
0
 def help_add():
     View.display("This command adds a new staff data to the system.\n")
     View.help_add()