Example #1
0
	def get(self):
		self.response.headers['Content-Type'] = 'text/html'
		url = ''
		url_string = ''
		welcome = 'Welcome back'
		myuser = None
		user = users.get_current_user()
		ev=ElecVel.query().fetch()
		if user:
			url = users.create_logout_url(self.request.uri)
			url_string = 'logout'
			myuser_key = ndb.Key('MyUser', user.user_id())
			myuser = myuser_key.get()
			if myuser == None:
				welcome = 'Welcome to the application'
				myuser = MyUser(id=user.user_id())
				myuser.put()

		else:
			url = users.create_login_url(self.request.uri)
			url_string = 'login'

		template_values = {
			'url' : url,
			'url_string' : url_string,
			'user' : user,
			'welcome' : welcome,
			'myuser' : myuser,
			'ev' : ev

		}
		template = JINJA_ENVIRONMENT.get_template('main.html')
		self.response.write(template.render(template_values))
    def post(self):
        self.response.headers['Content-Type'] = 'text/html'
        user = users.get_current_user()
        ev_key = ndb.Key('ElecVel', user.user_id())
        ev = ev_key.get()
        car = []
        if self.request.get('button') == 'Search':
            search_str = self.request.get('vechSearch')
            search_cat = self.request.get('category')
            if search_cat in (
                    "Battery", "Wltp", "Cost", "Power") and self.request.get(
                        'min') != "" and self.request.get('max') != "":
                min = float(self.request.get('min'))
                max = float(self.request.get('max'))
            elif search_cat in ("Year") and self.request.get(
                    'min') != "" and self.request.get('max') != "":
                min = int(self.request.get('min'))
                max = int(self.request.get('max'))
            if search_str != "" and search_cat != "" and self.request.get(
                    'min') != "" and self.request.get('max') != "":
                car = ElecVel.query(
                    ndb.AND(
                        ndb.OR(ElecVel.name == search_str,
                               ElecVel.manufacturer == search_str),
                        ndb.AND(
                            getattr(ElecVel, search_cat) >= min,
                            getattr(ElecVel, search_cat) <= max))).fetch()
            elif search_str != "":
                car = ElecVel.query(
                    ndb.OR(
                        ndb.OR(ElecVel.name == search_str,
                               ElecVel.manufacturer == search_str))).fetch()
            elif search_cat != "" and self.request.get(
                    'min') != "" and self.request.get('max') != "":
                car = ElecVel.query(
                    ndb.AND(
                        getattr(ElecVel, search_cat) >= min,
                        getattr(ElecVel, search_cat) <= max)).fetch()
            else:
                car = ElecVel.query().fetch()

        elif self.request.get('button') == 'Cancel':
            self.redirect('/')
        template_values = {}
        template_values["cars"] = car
        template = JINJA_ENVIRONMENT.get_template('evsearch.html')
        self.response.write(template.render(template_values))
Example #3
0
 def get(self):
     self.response.headers['Content-Type'] = 'text/html'
     user = users.get_current_user()
     reviews = EvReview.query().fetch()
     ev = ElecVel.query().fetch()
     template_values = {
     "reviews" : reviews,
     "ev" : ev,
     "user" : user
     }
     template = JINJA_ENVIRONMENT.get_template("review.html")
     self.response.write(template.render(template_values))
Example #4
0
    def post(self):
        if self.request.get('button') == 'Cancel':
            self.redirect('/')
        elif self.request.get('button') == 'Compare':
            Car1 = self.request.get("car1")
            Car2 = self.request.get("car2")
            if Car1 == Car2:
                template = JINJA_ENVIRONMENT.get_template("error.html")
                template_values = {
                    "error": "Cannot compare same ev!",
                    "url": "evcompare"
                }
                self.response.write(template.render(template_values))
            elif Car1 != "" and Car2 != "":
                ev = ElecVel.query().fetch()
                car1 = ndb.Key(ElecVel, int(Car1)).get()
                car2 = ndb.Key(ElecVel, int(Car2)).get()
                reviewsC1 = EvReview.query(EvReview.car == int(Car1)).fetch()
                reviewsC2 = EvReview.query(EvReview.car == int(Car2)).fetch()
                Car1_Avg = 0
                for rev in reviewsC1:
                    Car1_Avg += rev.rating
                if len(reviewsC1) != 0:
                    Car1_Avg = float(Car1_Avg) / len(reviewsC1)
                else:
                    Car1_Avg = 0

                Car2_Avg = 0
                for rev in reviewsC2:
                    Car2_Avg += rev.rating
                if len(reviewsC2) != 0:
                    Car2_Avg = float(Car2_Avg) / len(reviewsC2)
                else:
                    Car2_avg = 0
                template_values = {
                    "ev": ev,
                    "car1": car1,
                    "car2": car2,
                    "Car1_Avg": Car1_Avg,
                    "Car2_Avg": Car2_Avg
                }
                template = JINJA_ENVIRONMENT.get_template("evcompare.html")
                self.response.write(template.render(template_values))
            else:
                template = JINJA_ENVIRONMENT.get_template("error.html")
                template_values = {
                    "error": "Vehicle already exist!",
                    "url": "evadd"
                }
                self.response.write(template.render(template_values))
 def get(self):
     self.response.headers['Content-Type'] = 'text/html'
     user = users.get_current_user()
     ev_key = ndb.Key('ElecVel', user.user_id())
     ev = ev_key.get()
     table = ElecVel.query()
     a = table.fetch()
     keyno = int(time.time() * 1000) + int(user.user_id(
     )) - 18580476580402176403 - 167224289223619601419 + 99999999
     template_values = {
         'ev': ev,
         'a': a,
         'keyno': keyno,
         'table': table,
     }
     template = JINJA_ENVIRONMENT.get_template('evadd.html')
     self.response.write(template.render(template_values))
    def post(self):
        self.response.headers['Content-Type'] = 'text/html'
        #date = int(time.time()*1000)
        #ev_key = ndb.Key('ElecVel', 123)
        user = users.get_current_user()
        table = ElecVel.query()
        #keyno = table.count()
        #ev = None
        #keyno = date+int(user.user_id())-185804765802701624389
        if user:
            if self.request.get('button') == 'Cancel':
                self.redirect('/')
            #185804765802701624389  111111111111111111111
            # name, manufacturer, year, battery size (Kwh), WLTP range (Km), cost, power (Kw).
            elif self.request.get('button') == 'add':
                id = int(self.request.get('ID'))
                ev = ElecVel(id=id)
                ev.name = self.request.get('car_name')
                ev.manufacturer = self.request.get('car_mfc')
                ev.year = int(self.request.get('car_year'))
                ev.battery_size = float(self.request.get('car_btr_sz'))
                ev.WLTP = float(self.request.get('car_WLTP'))
                ev.power = float(self.request.get('car_power'))
                ev.cost = float(self.request.get('car_cost'))
                #temp2 = ElecVel.name
                #temp3 = ElecVel.query().filter(ndb.GenericProperty(temp2)).get()
                query = ElecVel.query(
                    ndb.AND(ElecVel.name == ev.name,
                            ElecVel.manufacturer == ev.manufacturer,
                            ElecVel.year == ev.year))
                if query.count() == 0:
                    ev.put()
                    self.redirect('/evadd')

                else:
                    template = JINJA_ENVIRONMENT.get_template("error.html")
                    template_values = {
                        "error": "Vehicle already exist!",
                        "url": "evadd"
                    }
                    self.response.write(template.render(template_values))
Example #7
0
 def get(self):
     self.response.headers['Content-Type'] = 'text/html'
     ev = ElecVel.query().fetch()
     template_values = {"ev": ev}
     template = JINJA_ENVIRONMENT.get_template("evcompare.html")
     self.response.write(template.render(template_values))