示例#1
0
    def verify(self):
        problems = []
        v = self.vars

        if not v.name.get():
            problems.append("You must enter a name.")
        elif self.client.rate_get(name=v.name.get()):
            problems.append("A rate with that name already exists.")
        if not v.rateid.get():
            problems.append("You must enter a rate ID.")
        elif self.client.rate_get(rateid=v.rateid.get()):
            problems.append("A rate with that ID already exists.")
        if not v.lengthrate.get():
            problems.append("You must enter a $ ammount per meter.")
        elif not isfloat(v.lengthrate.get()):
            problems.append("The $ ammount per m is not numerical.")
        elif float(v.lengthrate.get()) < 0:
            problems.append("The $ ammount per m must be greater than 0.")
        if not v.timerate.get():
            problems.append("You must enter a $ ammount per hr.")
        elif not isfloat(v.timerate.get()):
            problems.append("The $ ammount per hr is not numerical.")
        elif float(v.timerate.get()) < 0:
            problems.append("The $ ammount per hr must be greater than 0.")

        if not problems:
            return True
        else:
            msg = "The follwing errors were found in your input:\n\n"
            for s in problems:
                msg += s + "\n"
            messagebox.showerror("Bad Input", msg)
            return False
示例#2
0
    def verify(self):
        msgBase = "The following errors were found while parsing your filter criteria:\n\n"
        msg = msgBase
        v = self.vars

        if not isfloat(v.f_lengthMin.get()) or float(v.f_lengthMin.get()) < 0:
            msg += "Min. length must be a number greater than 0.\n"
        if not isfloat(v.f_lengthMax.get()) or float(v.f_lengthMax.get()) < 0:
            msg += "Max. length must be a number greater than 0.\n"
        if not isint(v.f_durationMin.get()) or int(v.f_durationMin.get()) < 0:
            msg += "Min. duration must be an integer greater than 0.\n"
        if not isint(v.f_durationMax.get()) or int(v.f_durationMax.get()) < 0:
            msg += "Max. duration must be an integer greater than 0.\n"
        if v.f_dateMin.get():
            try:
                datetime.fromisoformat(v.f_dateMin.get())
            except ValueError:
                msg += "Min. date must be formatted as 'YYYY-MM-DD'.\n"
        if v.f_dateMax.get():
            try:
                datetime.fromisoformat(v.f_dateMax.get())
            except ValueError:
                msg += "Max. date must be formatted as 'YYYY-MM-DD'.\n"

        if msg != msgBase:
            msg.showerror("Bad Input", msg)
            return False
        else:
            return True
示例#3
0
    def submit(self):
        # Validate
        userid = self.vars.userid.get()
        payment = self.vars.payment.get()

        errmsg = []

        userids = self.client.user_get(userid=userid)
        if not userid:
            errmsg.append("No userid was provided.")
        elif not userids or userid not in [u.userid for u in userids]:
            errmsg.append("No user exists with that ID.")
        if not payment:
            errmsg.append("No payment amount was provided.")
        elif not isfloat(payment):
            errmsg.payment("Payment amount specified is not a number.")
        payment = float(payment)

        if errmsg:
            errmsg = "\n".join(errmsg)
            messagebox.showerror("Error",
                                 "Unable to log payment:\n\n" + errmsg)
            return

        u = [user for user in userids if user.userid == userid][0]
        s1, s2, s3 = u.firstname, u.lastname, payment
        msg = "You are registering a payment by {} {} for ${:.2f}. Is this correct?".format(
            s1, s2, s3)
        if messagebox.askyesno("Confirm", msg):
            self.client.payment_log(userid, payment, self.auth_userid,
                                    self.auth_passwd)

        # Reset fields
        self.vars.userid.set("")
        self.vars.payment.set("")
示例#4
0
    def verify(self):
        problems = []  # List to hold info about any formatting errors

        v = self.vars
        if not v.userid.get():
            problems.append("You must enter a User ID.")
        elif not self.client.user_get(userid=v.userid.get()):
            problems.append("No user ecists with the specified ID.")
        if not v.printid.get():
            problems.append("You must choose a printid.")
        elif not self.client.print_get(printid=v.printid.get()):
            problems.append("No print exists with that Print ID.")
        if not isfloat(v.completion.get()) or not 0 <= float(
                v.completion.get()) <= 100:
            problems.append(
                "The % completion must be a number between 0 and 100.")

        # Display a helpful message if there were any formatting errors
        if problems:
            m = ""
            for s in ["The following formatting errors were found.:"
                      ] + problems:
                m += s + "\n"
            msg.showerror("Bad Input", m)

        # Return whether or not there were errors
        return not problems
示例#5
0
    def validate(self):
        f = self.filter
        errmsg = []
        if f.invid.get() and not isint(f.invid.get()):
            errmsg.append("Invoice ID must be an integer.")
        if f.dateMin.get() and not isdate(f.dateMin.get()):
            errmsg.append("Min. Date is not a valid format.")
        if f.dateMax.get() and not isdate(f.dateMax.get()):
            errmsg.append("MAx. Date is not a valid format.")
        if f.costMin.get() and not isfloat(f.costMin.get()):
            errmsg.append("Min. cost must be a float.")
        if f.costMax.get() and not isfloat(f.costMax.get()):
            errmsg.append("Max. cost must be a float.")

        if errmsg:
            msg = "There are errors in your filter input.\n\n" + "\n".join(
                errmsg)
            messagebox.showerror("Validation Error", msg)
            return False
        else:
            return True
示例#6
0
    def validate(self):
        # Let's make a list, problems, which we add to every time we find something wrong with the
        # input.
        problems = []

        v = self.vars

        # -- Check Formatting -----
        # Check if User ID is empty
        if not v.userid.get():
            problems.append("Your User ID must be given.")
        # Check if Password is empty
        if not v.passwd.get():
            problems.append("You must provide your password.")
        # Check if userid of payer is provided
        if v.isPayer.get() and not v.payer.get():
            problems.append(
                "You indicated that someone else is paying, but didn't provide their User ID."
            )

        # Check that the length is given and that it is formatted correctly
        if not v.length.get():
            problems.append(
                "You must specify how much fillament the print will use.")
        elif not isfloat(v.length.get()):
            problems.append(
                "You must enter a numerical value for the approx. length of fillament."
            )
        elif float(v.length.get()) <= 0:
            problems.append(
                "The approx. length of fillament must be greater tha zero.")
        # Check that the duration is given and formatted properly
        if not v.durationHr.get():
            problems.append(
                "You must specify the approx. number of hours needed for the print (use 0 for times less than 1 hour)."
            )
        elif not isint(v.durationHr.get()) or int(v.durationHr.get()) < 0:
            problems.append(
                "The approx. number of hours needed for the print must be a positive integer."
            )
        if not v.durationMin.get():
            problems.append(
                "You must specify the approx. number of minutes needed for the print."
            )
        elif not isint(v.durationMin.get()) or int(
                v.durationMin.get()) < 0 or int(v.durationMin.get()) > 59:
            problems.append(
                "The approx. number of minutes must be an integer value between 0 and 59."
            )

        # Check Printer and Rate
        if not v.printer.get():
            problems.append("You must specify a printer.")
        elif v.printer.get() not in self.client.printer_get():
            problems.append("Invalid printer choice.")
        if not v.rate.get():
            problems.append("You must specify a pricing rate for your print.")
        elif v.rate.get() not in [r.rateid for r in self.client.rate_get()]:
            problems.append("Invalid pricing rate choice.")

        # Now, if we encountered any formatting errors, return False and display the problems.
        # Otherwise, move on.
        if problems:
            s = "The following formatting errors were found:\n\n"
            for p in problems:
                s += p + "\n"
            msg.showerror("Bad Input", s)
            return False

        # -- Check if the actual values are valid -----
        # User ID and Password
        if not self.client.user_verify(v.userid.get(), v.passwd.get()):
            msg.showerror("Bad Login",
                          "Your User ID and password are invalid.")
            return False
        if v.isPayer.get() and not self.client.user_get(userid=v.payer.get()):
            msg.showerror(
                "Bad User ID",
                "No user exists with the ID '{}'.".format(v.payer.get()))
            return False

        # Make sure the duration isn't too short
        if int(v.durationHr.get()) * 60 + int(v.durationMin.get()) < 1:
            msg.showerror(
                "Bad Input",
                "The specified duration is impossibly short. C'mon, be reasonable."
            )
            return False

        # -- Return True if nothing has been caught -----
        return True