def post(self): user = users.get_current_user() if user: params = self.request # ev_key = ndb.Key(EV, params.get('name')) ev_obj = EV.query(EV.name == params.get('name')).fetch() if not ev_obj: ev_obj = EV() ev_obj.name = params.get('name') ev_obj.manufacturer = params.get('manufacturer') ev_obj.year = int(params.get('year')) ev_obj.battery = int(params.get('battery')) ev_obj.wltp = int(params.get('wltp')) ev_obj.power = int(params.get('power')) ev_obj.cost = float(params.get('cost')) ev_obj.put() template_values = { 'user': user, 'report': '1', 'params': { 'name': '', 'manufacturer': '' } } else: template_values = { 'user': user, 'report': '2', 'params': self.request } template = JINJA_ENVIRONMENT.get_template('add.html') self.response.write(template.render(template_values)) else: self.redirect('/')
def get(self): self.response.headers['Content-Type'] = 'text/html' # URL that will contain a login or logout link # and also a string to represent this url = '' url_string = '' # pull the current user from the request user = users.get_current_user() # determine if we have a user logged in or not if user: url = users.create_logout_url(self.request.uri) url_string = 'logout' else: url = users.create_login_url(self.request.uri) url_string = 'login' # generate a map that contains everything that we need to pass to the template template_values = { 'url': url, 'url_string': url_string, 'user': user, 'evs': EV.query() } # pull the template file and ask jinja to render # it with the given template values template = JINJA_ENVIRONMENT.get_template('main.html') self.response.write(template.render(template_values))
def post(self): self.response.headers['Content-Type'] = 'text/html' action=self.request.get('button') query_list = EV.query(EV.evReview.rvRating>1).fetch() if action=='Retrive': query_list = EV.query().fetch() #max_review = max(EV.evReview.rvRating) #rv_Avg=Sum(query_list)/len(query_list) #for ev in query_list: #self.response.write(ev.rvName + '<br/>') template_values ={ 'all_rv_keys':query_list #'all_rv_keys':ev.evReview } template = JINJA_ENVIRONMENT.get_template('info.html') self.response.write(template.render(template_values))
def post(self): self.response.headers['Content-Type'] = 'text/html' # gets current user user = users.get_current_user() # get value of button clicked action = self.request.get('button') # selection statement for button if action == 'Edit': # generates ev id = self.request.get('id') key = ndb.Key('EV', int(id)) ev = key.get() # assigns form values to the ev ev.name = self.request.get('ev_name') ev.manufacturer = self.request.get('ev_manufacturer') ev.year = int(self.request.get('ev_year')) ev.battery_size = float(self.request.get('ev_battery_size')) ev.WLTP_range = float(self.request.get('ev_WLTP_range')) ev.cost = float(self.request.get('ev_cost')) ev.power = float(self.request.get('ev_power')) # querys ev to find duplicate ev query = EV.query( ndb.AND(EV.manufacturer == ev.manufacturer, EV.name == ev.name, EV.year == ev.year)) # selection statement for if query count is above 0 if query.count() > 0: error = 'Error: EV already exists!' template_values = {'user': user, 'error': error, 'ev': ev} template = JINJA_ENVIRONMENT.get_template('details.html') self.response.write(template.render(template_values)) else: # adds ev to datastore ev.put() self.redirect('/') elif action == 'Delete': id = self.request.get('id') key = ndb.Key('EV', int(id)) ev = key.get() # deletes ev ev.key.delete() self.redirect('/') elif action == 'Cancel': self.redirect('/')
def get(self): self.response.headers['Content-Type'] = 'text/html' # gets current user user = users.get_current_user() # query the datastore for ev q = EV.query() # values to be rendered to the compare.html page template_values = {'user': user, 'q': q} template = JINJA_ENVIRONMENT.get_template('compare.html') self.response.write(template.render(template_values))
def post(self): params = self.request name = params.get('name') manufacturer = params.get('manufacturer') year_lc = int(params.get('year-lc-t')) year_uc = int(params.get('year-uc-t')) battery_lc = int(params.get('battery-lc-t')) battery_uc = int(params.get('battery-uc-t')) wltp_lc = int(params.get('wltp-lc-t')) wltp_uc = int(params.get('wltp-uc-t')) power_lc = int(params.get('power-lc-t')) power_uc = int(params.get('power-uc-t')) cost_lc = int(params.get('cost-lc-t')) cost_uc = int(params.get('cost-uc-t')) query = EV.query().fetch(keys_only=True) if len(name.strip()) > 0: query = set(query).intersection( EV.query(EV.name == name.strip()).fetch(keys_only=True)) if len(manufacturer.strip()) > 0: query = set(query).intersection( EV.query(EV.manufacturer == manufacturer.strip()).fetch( keys_only=True)) query = set(query).intersection( EV.query(EV.year >= year_lc, EV.year <= year_uc).fetch(keys_only=True)) query = set(query).intersection( EV.query(EV.battery >= battery_lc, EV.battery <= battery_uc).fetch(keys_only=True)) query = set(query).intersection( EV.query(EV.wltp >= wltp_lc, EV.wltp <= wltp_uc).fetch(keys_only=True)) query = set(query).intersection( EV.query(EV.power >= power_lc, EV.power <= power_uc).fetch(keys_only=True)) query = set(query).intersection( EV.query(EV.cost >= cost_lc, EV.cost <= cost_uc).fetch(keys_only=True)) result = ndb.get_multi(query) if not result: result = None else: result.sort(key=lambda x: x.name, reverse=False) template_values = {'result': result} template = JINJA_ENVIRONMENT.get_template('query.html') self.response.write(template.render(template_values))
def get(self): self.response.headers['Content-Type'] = 'text/html' ev_key = ndb.Key('EV', str(self.request.params.items()[0][1])) #ev_key = ndb.Key('EV',id) ev = ev_key.get() all_keys = EV.query().fetch(keys_only=True) #all_rv_keys = RV.query().fetch(keys_only=True) user = users.get_current_user() #query_list = EV.query() template_values = { 'all_keys': all_keys, 'Current_user': user, 'ev': ev } template = JINJA_ENVIRONMENT.get_template('review.html') self.response.write(template.render(template_values))
def post(self): self.response.headers['Content-Type'] = 'text/html' # gets current user user = users.get_current_user() # get value of button clicked action = self.request.get('button') # create a new ev object ev = EV() # selection statement for button if action == 'Add': # adds form values to the ev object ev.name = self.request.get('ev_name') ev.manufacturer = self.request.get('ev_manufacturer') ev.year = int(self.request.get('ev_year')) ev.battery_size = float(self.request.get('ev_battery_size')) ev.WLTP_range = float(self.request.get('ev_WLTP_Range')) ev.cost = float(self.request.get('ev_cost')) ev.power = float(self.request.get('ev_power')) # querys ev to find duplicate ev query = EV.query( ndb.AND(EV.manufacturer == ev.manufacturer, EV.name == ev.name, EV.year == ev.year)) # selection statement for if query count is above 0 if query.count() > 0: error = 'Error: EV already exists!' template_values = {'error': error, 'user': user} template = JINJA_ENVIRONMENT.get_template('addev.html') self.response.write(template.render(template_values)) else: # adds ev to datastore ev.put() self.redirect('/') elif action == 'Cancel': self.redirect('/')
def post(self): evs = [] for p in self.request.params: evs.append(ndb.Key(urlsafe=p).get()) maxs = {} mins = {} for ev in evs: try: maxs['rating'] = max( float(sum(ev.ratings)) / len(ev.ratings), maxs.get('rating', 0)) except: pass maxs['battery'] = max(ev.battery, maxs.get('battery', 0)) maxs['wltp'] = max(ev.wltp, maxs.get('wltp', 0)) maxs['power'] = max(ev.power, maxs.get('power', 0)) maxs['cost'] = max(ev.cost, maxs.get('cost', 0)) try: mins['rating'] = min( float(sum(ev.ratings)) / len(ev.ratings), float(mins.get('rating', sys.maxint))) except: pass mins['battery'] = min(ev.battery, mins.get('battery', sys.maxint)) mins['wltp'] = min(ev.wltp, mins.get('wltp', sys.maxint)) mins['power'] = min(ev.power, mins.get('power', sys.maxint)) mins['cost'] = min(ev.cost, mins.get('cost', sys.maxint)) print maxs print mins template_values = { "evs": EV.query().order(EV.name), "compare": evs, 'maxs': maxs, 'mins': mins } template = JINJA_ENVIRONMENT.get_template('compare.html') self.response.write(template.render(template_values))
def post(self): self.response.headers['Content-Type'] = 'text/html' action = self.request.get('button') if action == 'Add EV': evName = self.request.get('evName') evManufacturer = self.request.get('evManufacturer') #evDateIssued = datetime.strptime(self.request.get('evDateIssued'),'%Y') evDateIssued = self.request.get('evDateIssued') evBatterysize = self.request.get('evBatterysize') evWLTPrange = self.request.get('evWLTPrange') #evWLTPrangemax = self.request.get('evWLTPrangemax') evCost = self.request.get('evCost') evPower = self.request.get('evPower') myev_key = ndb.Key('EV', evName) myev = myev_key.get() if myev == None: #,id=evName new_ev = EV(evName=evName, id=evName, evManufacturer=evManufacturer, evDateIssued=evDateIssued, evBatterysize=evBatterysize, evWLTPrange=evWLTPrange, evCost=evCost, evPower=evPower) new_ev.put() message = "EV Added!!" else: message = "EV already exists!!" template_values = { 'message': message, 'all_keys': EV.query().fetch(keys_only=True) } template = JINJA_ENVIRONMENT.get_template('main.html') self.response.write(template.render(template_values))
def post(self): self.response.headers['Content-Type'] = 'text/html' # gets current user user = users.get_current_user() # get value of button clicked action = self.request.get('button') # selection statement for button if action == 'Search': name = self.request.get('ev_name') manufacturer = self.request.get('ev_manufacturer') year_upper = self.request.get('ev_year_upper') year_lower = self.request.get('ev_year_lower') battery_size_upper = self.request.get('ev_battery_size_upper') battery_size_lower = self.request.get('ev_battery_size_lower') WLTP_range_upper = self.request.get('ev_WLTP_Range_upper') WLTP_range_lower = self.request.get('ev_WLTP_Range_lower') cost_upper = self.request.get('ev_cost_upper') cost_lower = self.request.get('ev_cost_lower') power_upper = self.request.get('ev_power_upper') power_lower = self.request.get('ev_power_lower') # querys ev query1 = EV.query().fetch(keys_only=True) query = EV.query().fetch(keys_only=True) # selection statement values from form if name: query2 = EV.query(EV.name == name).fetch(keys_only=True) query1 = (set(query1).intersection(query2)) if manufacturer: query2 = EV.query(EV.manufacturer == manufacturer).fetch(keys_only=True) query1 = (set(query1).intersection(query2)) if year_upper: query2 = EV.query(EV.year <= int(year_upper)).fetch(keys_only=True) query1 = (set(query1).intersection(query2)) if year_lower: query2 = EV.query(EV.year >= int(year_lower)).fetch(keys_only=True) query1 = (set(query1).intersection(query2)) if battery_size_upper: query2 = EV.query(EV.battery_size <= float(battery_size_upper)).fetch(keys_only=True) query1 = (set(query1).intersection(query2)) if battery_size_lower: query2 = EV.query(EV.battery_size >= float(battery_size_lower)).fetch(keys_only=True) query1 = (set(query1).intersection(query2)) if WLTP_range_upper: query2 = EV.query(EV.WLTP_range <= float(WLTP_range_upper)).fetch(keys_only=True) query1 = (set(query1).intersection(query2)) if WLTP_range_lower: query2 = EV.query(EV.WLTP_range >= float(WLTP_range_lower)).fetch(keys_only=True) query1 = (set(query1).intersection(query2)) if cost_upper: query2 = EV.query(EV.cost <= float(cost_upper)).fetch(keys_only=True) query1 = (set(query1).intersection(query2)) if cost_lower: query2 = EV.query(EV.cost >= float(cost_lower)).fetch(keys_only=True) query1 = (set(query1).intersection(query2)) if power_upper: query2 = EV.query(EV.power <= float(power_upper)).fetch(keys_only=True) query1 = (set(query1).intersection(query2)) if power_lower: query2 = EV.query(EV.power >= float(power_lower)).fetch(keys_only=True) query1 = (set(query1).intersection(query2)) # query returns a list containing entity objects total_query = ndb.get_multi(set(query).intersection(query1)) # values to be rendered to the search.html page template_values = { 'user': user, 'total_query' : total_query } template = JINJA_ENVIRONMENT.get_template('search.html') self.response.write(template.render(template_values)) elif action == 'Cancel': self.redirect('/')
def get(self): self.response.headers['Content-Type'] = 'text/html' all_keys = EV.query().fetch(keys_only=True) template_values = {'all_keys': all_keys} template = JINJA_ENVIRONMENT.get_template('compare.html') self.response.write(template.render(template_values))
def get(self): template_values = {"evs": EV.query().order(EV.name)} template = JINJA_ENVIRONMENT.get_template('compare.html') self.response.write(template.render(template_values))
def post(self): self.response.headers['Content-Type'] = 'text/html' action = self.request.get('button') query_list = EV.query() #check=EV.query() if action == 'Search': name_search = self.request.get('name_search') man_search = self.request.get('man_search') #datetime.strptime(self.request.get('evDateIssued'),'%Y') yr_min_search = self.request.get('yr_min_search') yr_max_search = self.request.get('yr_max_search') Bat_min_search = self.request.get('Bat_min_search') Bat_max_search = self.request.get('Bat_max_search') Wltp_min_search = self.request.get('Wltp_min_search') Wltp_max_search = self.request.get('Wltp_max_search') Cost_min_search = self.request.get('Cost_min_search') Cost_max_search = self.request.get('Cost_max_search') Power_min_search = self.request.get('Power_min_search') Power_max_search = self.request.get('Power_max_search') query_list = EV.query() if name_search: query_list = query_list.filter(EV.evName == name_search) if man_search: query_list = query_list.filter(EV.evManufacturer == man_search) if yr_min_search and yr_max_search: query_list = query_list.filter( EV.evDateIssued >= yr_min_search and EV.evDateIssued < yr_max_search) if Bat_min_search and Bat_max_search: query_list = query_list.filter( EV.evBatterysize >= Bat_min_search and EV.evBatterysize < Bat_max_search) #if Bat_search: # query_list=query_list.filter(EV.evManufacturer == Bat_search).fetch(keys_only=True) if Wltp_min_search and Wltp_max_search: query_list = query_list.filter( EV.evWLTPrange >= Wltp_min_search and EV.evWLTPrange < Wltp_max_search) if Cost_min_search and Cost_max_search: query_list = query_list.filter(EV.evCost >= Cost_min_search and EV.evCost < Cost_max_search) if Power_min_search and Power_max_search: query_list = query_list.filter( EV.evPower >= Power_min_search and EV.evPower < Power_max_search) template_values = {'all_keys': query_list} template = JINJA_ENVIRONMENT.get_template('refinedSearch.html') self.response.write(template.render(template_values)) elif action == 'Cancel': self.redirect('/') else: message = "fail" template_values = {'message': message} template = JINJA_ENVIRONMENT.get_template('refinedSearch.html') self.response.write(template.render(template_values))
def post(self): self.response.headers['Content-Type'] = 'text/html' # gets current user user = users.get_current_user() # query the datastore for ev q = EV.query() error = '' # get value of button clicked action = self.request.get('button') # selection statement for button if action == 'Compare': # gets the ids of evs selected ev_ids = self.request.get_all('evs') if len(ev_ids) < 2: error = 'Error: Choose at least two evs' template_values = {'error': error, 'q': q, 'user': user} template = JINJA_ENVIRONMENT.get_template('compare.html') self.response.write(template.render(template_values)) return # python list of evs EVs = [] for id in ev_ids: key = ndb.Key('EV', int(id)) ev = key.get() EVs.append(ev) max_battery_size = 0 min_battery_size = 9223372036854775807 max_WLTP_range = 0 min_WLTP_range = 9223372036854775807 max_cost = 0 min_cost = 9223372036854775807 max_power = 0 min_power = 9223372036854775807 max_rating = 0 min_rating = 9223372036854775807 # loop through the list of evs to find max and min values for ev in EVs: if max_battery_size < ev.battery_size: max_battery_size = ev.battery_size if min_battery_size > ev.battery_size: min_battery_size = ev.battery_size if max_WLTP_range < ev.WLTP_range: max_WLTP_range = ev.WLTP_range if min_WLTP_range > ev.WLTP_range: min_WLTP_range = ev.WLTP_range if max_cost < ev.cost: max_cost = ev.cost if min_cost > ev.cost: min_cost = ev.cost if max_power < ev.power: max_power = ev.power if min_power > ev.power: min_power = ev.power if ev.rating: if max_rating < ev.rating: max_rating = ev.rating if min_rating > ev.rating: min_rating = ev.rating # values to be rendered to the compare.html page template_values = { 'user': user, 'q': q, 'EVs': EVs, 'error': error, 'max_battery_size': max_battery_size, 'min_battery_size': min_battery_size, 'max_WLTP_range': max_WLTP_range, 'min_WLTP_range': min_WLTP_range, 'max_cost': max_cost, 'min_cost': min_cost, 'max_power': max_power, 'min_power': min_power, 'max_rating': max_rating, 'min_rating': min_rating } template = JINJA_ENVIRONMENT.get_template('compare.html') self.response.write(template.render(template_values)) elif action == 'Cancel': self.redirect('/')