コード例 #1
0
 def get(self):
     #Set content type to text/html
     self.response.headers["Content-Type"] = "text/html"
     user = users.get_current_user()
     vehicle = ElectricVehicle.query(
         ElectricVehicle.vehicleName == self.request.get("vehicle")).get()
     #Get type of request
     type_of_request = self.request.get("type")
     #Fetch reviews
     reviews = Review.query(Review.vehicle == self.request.get(
         "vehicle")).order(-Review.date).fetch()
     template_values = {
         "user": user,
         "vehicle": vehicle,
         "type": type_of_request,
         "reviews": reviews
     }
     template = JINJA_ENVIRONMENT.get_template("templates/vehicleinfo.html")
     #Render template
     self.response.write(template.render(template_values))
コード例 #2
0
 def post(self):
     self.response.headers["Content-Type"] = "text/html"
     vehicle = ElectricVehicle.query(ElectricVehicle.vehicleName ==
                                     self.request.get("vehicleList")).get()
     logging.info(datetime.now())
     #Create Review object
     review = Review(user=users.get_current_user().email(),
                     vehicle=self.request.get("vehicleList"),
                     review=self.request.get("review"),
                     rating=int(self.request.get("rating")),
                     date=datetime.now())
     #Store Review object to database
     review.put()
     #Logic to calculate average rating of vehicle
     reviews = Review.query(
         Review.vehicle == self.request.get("vehicleList")).fetch()
     rating = review.rating
     for rev in reviews:
         rating += rev.rating
     logging.info(reviews)
     logging.info(rating)
     vehicle.averageRating = round(float(rating) / (len(reviews) + 1), 2)
     vehicle.put()
     self.redirect("/")
コード例 #3
0
    def post(self):
        #Set content type to text/html
        self.response.headers["Content-Type"] = "text/html"
        #Fetch all vehicles
        vehicles = ElectricVehicle.query()
        #Logic for filtering
        if self.request.get("vehicle_name"):
            vehicles = vehicles.filter(ElectricVehicle.vehicleName ==
                                       self.request.get("vehicle_name"))
        if self.request.get("vehicle_manufacturer"):
            vehicles = vehicles.filter(
                ElectricVehicle.vehicleManufacturer == self.request.get(
                    "vehicle_manufacturer"))

        list_of_values = []
        if self.request.get("lyear") and self.request.get("hyear"):
            list_of_values.append("year")
        if self.request.get("lbatterySize") and self.request.get(
                "hbatterySize"):
            list_of_values.append("batterySize")
        if self.request.get("lwltpRange") and self.request.get("hwltpRange"):
            list_of_values.append("wltpRange")
        if self.request.get("lcost") and self.request.get("hcost"):
            list_of_values.append("cost")
        if self.request.get("lpower") and self.request.get("hpower"):
            list_of_values.append("power")

        return_list = vehicles.fetch()

        for vehicle in return_list:
            counter = 0
            for value in list_of_values:
                if value != "cost":
                    if getattr(vehicle, value) >= int(
                            self.request.get("l" + value)) and getattr(
                                vehicle, value) <= int(
                                    self.request.get("h" + value)):
                        counter += 1
                elif getattr(vehicle, value) >= float(
                        self.request.get("l" + value)) and getattr(
                            vehicle, value) <= float(
                                self.request.get("h" + value)):
                    counter += 1

            if counter != len(list_of_values):
                return_list.remove(vehicle)

        messages = []
        if return_list:
            for vehicle in return_list:
                if users.get_current_user():
                    messages.append(
                        "<div class=\"text-center\"><h3>Click for more info &nbsp<a href='/details?vehicle="
                        + vehicle.vehicleName + "'>" + vehicle.vehicleName +
                        "</a></h3></div>")
                else:
                    messages.append(
                        "<div class=\"text-center\"><h3>Click for more info </p>&nbsp<a href='/details?vehicle="
                        + vehicle.vehicleName + "&type=info'>" +
                        vehicle.vehicleName + "</a></h3></div>")
        else:
            messages.append(
                "<div class=\"text-center\"><h3>No vehicles found</h3></div>")
        template_values = {"messages": messages}
        template = JINJA_ENVIRONMENT.get_template("templates/filter.html")
        self.response.write(template.render(template_values))
コード例 #4
0
    def post(self):
        self.response.headers["Content-Type"] = "text/html"
        #Get all vehicles to compare
        vehicles_name = self.request.get_all("vehicles")
        vehicles = []
        #Logic to compare vehicles
        for name in vehicles_name:
            vehicles.append(
                ElectricVehicle.query(
                    ElectricVehicle.vehicleName == name).get())

        table = "<br><br><table class=\"table table-bordered\" style=\"color:white;\">"

        headings = [
            "vehicleName", "vehicleManufacturer", "year", "batterySize",
            "wltpRange", "cost", "power", "averageRating"
        ]
        headings_to_display = [
            "Vehicle Name", "Vehicle Manufacturer", "Year", "Battery Size",
            "Wltp Range", "Cost", "Power", "Average Rating"
        ]
        for heading in headings:
            table += "<tr>"
            table += "<td>" + headings_to_display[headings.index(
                heading)] + "</td>"
            values = []
            max_value = None
            min_value = None
            for vehicle in vehicles:
                values.append(getattr(vehicle, heading))
            if heading not in ["vehicleName", "vehicleManufacturer"]:
                max_value = max(values)
                min_value = min(values)

            for value in values:
                color1 = "green"
                color2 = "red"
                if heading == "cost":
                    color1 = "red"
                    color2 = "green"
                if max_value != min_value:
                    if max_value == value:
                        table += "<td style=\"background:" + color1 + "\">" + str(
                            value) + "</td>"
                    elif min_value == value:
                        table += "<td style=\"background:" + color2 + "\">" + str(
                            value) + "</td>"
                    else:
                        if heading == "vehicleName":
                            table += "<td><a href=\"/details?vehicle=" + str(
                                value) + "&type=info\">" + str(
                                    value) + "</a></td>"
                        else:
                            table += "<td>" + str(value) + "</td>"
                else:
                    if heading == "vehicleName":
                        table += "<td><a href=\"/details?vehicle=" + str(
                            value) + "&type=info\">" + str(value) + "</a></td>"
                    else:
                        table += "<td>" + str(value) + "</td>"
            table += "</tr>"
        table += "</table>"
        vehicles = ElectricVehicle.query().fetch()
        template_values = {"table": table, "vehicles": vehicles}
        template = JINJA_ENVIRONMENT.get_template(
            "templates/comparevehicle.html")
        self.response.write(template.render(template_values))