Ejemplo n.º 1
0
    def update(self, entry):
        if entry is None:
            return self.getResult(None, False, "Provider cannot be empty.")

        if "id" in entry and int(entry["id"]) < 0:
            return self.update(entry)

        validator = DictValidator([
            KeyValidator(entry, "id").existsPositiveInteger(),
            KeyValidator(entry, "providerTypeId").existsPositiveInteger(),
            KeyValidator(entry, "name").existsNotNullShorterThan(256),
            KeyValidator(entry, "address").existsNullableShorterThan(256)
        ])

        isValid, msg = validator.validate()
        if not isValid:
            return self.getResult(None, msg)

        try:
            c = self.conn.cursor()
            c.execute(
                "update providers set providerTypeId = ?, name = ?, address = ? where id = ?",
                (entry["providerTypeId"], entry["name"], entry["address"],
                 entry["id"]))
            self.conn.commit()
            return self.getResult(c.lastrowid, c.rowcount == 1, None)
        except sqlite3.Error, e:
            return self.getResult(entry["id"], False, e)
Ejemplo n.º 2
0
    def update(self, entry):
        if entry is None:
            return self.getResult(None, False, "Event cannot be empty.")

        if "id" in entry and int(entry["id"]) < 0:
            return self.add(entry)

        validator = DictValidator([
            KeyValidator(entry, "id").existsPositiveInteger(),
            KeyValidator(entry, "vehicleId").existsPositiveInteger(),
            KeyValidator(entry, "at").exists().isNotNone(),
            KeyValidator(entry, "odometer").exists(),
            KeyValidator(entry, "description").existsNullableShorterThan(256)
        ])

        isValid, msg = validator.validate()
        if not isValid:
            return self.getResult(None, False, msg)

        try:
            c = self.conn.cursor()
            c.execute(
                "update eventEntries set vehicleId = ?, at = ?, odometer = ?, description = ? where id = ?",
                (entry["vehicleId"], entry["at"], entry["odometer"],
                 entry["description"], entry["id"]))
            self.conn.commit()
            return self.getResult(c.lastrowid, c.rowcount == 1, None)
        except sqlite3.Error, e:
            return self.getResult(None, False, e)
Ejemplo n.º 3
0
    def add(self, entry):
        if entry is None:
            return self.getResult(None, False, "Entry cannot be empty.")

        if "id" in entry and int(entry["id"]) > 0:
            return self.update(entry)

        validator = DictValidator([
            KeyValidator(entry, "vehicleId").existsPositiveInteger(),
            KeyValidator(entry, "providerId").existsPositiveInteger(),
            KeyValidator(entry, "at").exists().isNotNone(),
            KeyValidator(entry,
                         "primaryContact").existsNullableShorterThan(256),
            KeyValidator(entry, "phoneNumber").existsNullableShorterThan(256),
            KeyValidator(entry, "description").existsNotNullShorterThan(256),
            KeyValidator(entry, "cost").existsPositiveInteger()
        ])

        isValid, msg = validator.validate()
        if not isValid:
            return self.getResult(None, False, msg)

        try:
            c = self.conn.cursor()
            c.execute(
                "insert into maintenanceEntries (vehicleId, providerId, at, primaryContact, phoneNumber, description, cost) values (?, ?, ?, ?, ?, ?, ?)",
                (entry["vehicleId"], entry["providerId"], entry["at"],
                 entry["primaryContact"], entry["phoneNumber"],
                 entry["description"], entry["cost"]))
            self.conn.commit()
            return self.getResult(c.lastrowid, c.rowcount == 1, None)
        except sqlite3.Error, e:
            return self.getResult(None, False, e)
Ejemplo n.º 4
0
    def add(self, entry):
        if entry is None:
            return self.getResult(None, None, "Entry cannot be empty.")

        if "id" in entry and int(entry["id"]) > 0:
            return self.update(entry)

        validator = DictValidator([
            KeyValidator(entry, "vehicleId").existsPositiveInteger(),
            KeyValidator(entry, "providerId").existsPositiveInteger(),
            KeyValidator(entry, "destinationId").existsPositiveInteger(),
            KeyValidator(entry, "fromDate").exists().isNotNone(),
            KeyValidator(entry, "toDate").exists().isNotNone(),
            KeyValidator(entry, "tripMileage").existsPositiveInteger(),
            KeyValidator(entry, "odometer").existsPositiveInteger(),
            KeyValidator(entry, "gallons").existsPositiveInteger(),
            KeyValidator(entry, "pricePerGallon").existsPositiveInteger()
        ])

        isValid, msg = validator.validate()
        if not isValid:
            return self.getResult(None, None, msg)

        try:
            c = self.conn.cursor()
            c.execute(
                "insert into mileageEntries (vehicleId, providerId, destinationId, fromDate, toDate, tripMileage, odometer, gallons, pricePerGallon) values (?, ?, ?, ?, ?, ?, ?, ?, ?)",
                (entry["vehicleId"], entry["providerId"],
                 entry["destinationId"], entry["fromDate"], entry["toDate"],
                 entry["tripMileage"], entry["odometer"], entry["gallons"],
                 entry["pricePerGallon"]))
            self.conn.commit()
            return self.getResult(c.lastrowid, c.rowcount == 1, None)
        except sqlite3.Error, e:
            return self.getResult(None, None, e)
Ejemplo n.º 5
0
    def update(self, entry):
        if entry is None:
            return self.getResult(None, False, "Vehicle cannot be empty.")

        if "id" in entry and int(entry["id"]) < 0:
            return self.update(entry)

        if "stillOwn" not in entry:
            entry["stillOwn"] = False

        if "nhtsa" not in entry:
            entry["nhtsa"] = ""
        else:
            entry["nhtsa"] = json.dumps(entry["nhtsa"])

        print entry

        validator = DictValidator([
            KeyValidator(entry, "id").existsPositiveInteger(),
            KeyValidator(entry, "driverId").existsPositiveInteger(),
            KeyValidator(entry, "vin").existsNotNullShorterThan(256),
            KeyValidator(entry, "make").existsNotNullShorterThan(256),
            KeyValidator(entry, "model").existsNotNullShorterThan(256),
            KeyValidator(entry, "year").existsPositiveInteger(),
            KeyValidator(entry, "stillOwn").existsZeroOneBoolean()
        ])

        isValid, msg = validator.validate()
        if not isValid:
            return self.getResult(None, False, msg)

        try:
            c = self.conn.cursor()
            c.execute(
                "update vehicles set driverId = ?, vin = ?, make = ?, model = ?, year = ?, stillOwn = ?, nhtsa = ? where id = ?",
                (entry["driverId"], entry["vin"], entry["make"],
                 entry["model"], entry["year"], entry["stillOwn"],
                 entry["nhtsa"], entry["id"]))
            self.conn.commit()
            return self.getResult(c.lastrowid, c.rowcount == 1, None)
        except sqlite3.Error, e:
            return self.getResult(None, False, e)
Ejemplo n.º 6
0
    def add(self, entry):
        if entry is None:
            return self.getResult(None, "Destination cannot be empty.")

        if "id" in entry and int(entry["id"]) > 0:
            return self.update(entry)

        validator = DictValidator([
            KeyValidator(entry, "name").existsNotNullShorterThan(256),
        ])

        isValid, msg = validator.validate()
        if not isValid:
            return self.getResult(None, False, msg)

        try:
            c = self.conn.cursor()
            c.execute("insert into destinations (name) values (?)",
                      (entry["name"], ))
            self.conn.commit()
            return self.getResult(c.lastrowid, c.rowcount == 1, None)
        except sqlite3.Error, e:
            return self.getResult(None, False, e)
Ejemplo n.º 7
0
    def update(self, entry):
        if entry is None:
            return self.getResult(None, "Destination cannot be empty.")

        if "id" in entry and int(entry["id"]) < 0:
            return self.add(entry)

        validator = DictValidator([
            KeyValidator(entry, "id").existsPositiveInteger(),
            KeyValidator(entry, "name").existsNotNullShorterThan(256),
        ])

        isValid, msg = validator.validate()
        if not isValid:
            return self.getResult(None, False, msg)

        try:
            c = self.conn.cursor()
            c.execute("update destinations set name = ? where id = ?",
                      (entry["name"], entry["id"]))
            self.conn.commit()
            return self.getResult(c.lastrowid, c.rowcount == 1, None)
        except sqlite3.Error, e:
            return self.getResult(None, False, e)