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 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): 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))