def post(self): session = Session() validationErrors=[] template_values = {'validationErrors': validationErrors} for name in ('name', 'startDate'): if self.request.get(name) in (None, ''): validationErrors.extend([name + ' cannot be empty']) if self.request.get('campwiseId') not in (None, ''): try: session.campwiseId = int(self.request.get('campwiseId')) except: validationErrors.extend(['Invalid Number Format for Campwise Id']) if session.campwiseId and Session.gql("WHERE campwiseId = :1", session.campwiseId).get() is not None: validationErrors.extend(['Session already exists! (campwise id was found in database)']) session.name = self.request.get('name') if session.name and session.gql("WHERE name = :1", session.name).get() is not None: validationErrors.extend(['Session already exists! (Session Name was found in database)']) try: session.startDate = util.string2Date(self.request.get('startDate')) except: validationErrors.extend(['Invalid Date Format for Start Date']) if validationErrors: path = os.path.join(os.path.dirname(__file__), '../html/session/session_new.html') self.response.out.write(template.render(path, template_values)) else: session.put() self.redirect('/session_view?key=' + str(session.key()))
def post(self): camper = Camper() validationErrors=[] template_values = {'validationErrors': validationErrors} for name in ('campwiseId', 'firstName', 'lastName', 'birthDate'): if self.request.get(name) in (None, ''): validationErrors.extend([name + ' cannot be empty']) try: camper.campwiseId = int(self.request.get('campwiseId')) except: validationErrors.extend(['Invalid Number Format for Campwise Id']) camper.firstName = self.request.get('firstName') camper.lastName = self.request.get('lastName') camper.note = self.request.get('note') try: camper.birthDate = util.string2Date(self.request.get('birthDate')) except: validationErrors.extend(['Invalid Date Format for Birthday']) if Camper.gql("WHERE campwiseId = :1", camper.campwiseId).get() is not None: validationErrors.extend(['Camper already exists! (campwise id was found in database)']) if validationErrors: path = os.path.join(os.path.dirname(__file__), '../html/camper/camper_new.html') self.response.out.write(template.render(path, template_values)) else: camper.put() self.redirect('/camper_view?key=' + str(camper.key()))
def post(self): for camperStrings in self.request.get('raw_csv').splitlines(): camperArr = camperStrings.split('|') iCamper = IncomingCamper() iCamper.campwiseId = int(camperArr[0]) iCamper.firstName = camperArr[1] iCamper.lastName = camperArr[2] iCamper.birthDate = util.string2Date(camperArr[3]) if camperArr[4] in ('', None): iCamper.cabin = None else: iCamper.cabin = camperArr[4] found = Camper.gql('WHERE campwiseId = :1', iCamper.campwiseId).get() if found: iCamper.existingCamper = found incomingFound = IncomingCamper.gql('WHERE campwiseId = :1', iCamper.campwiseId).get() if not incomingFound: iCamper.put() self.redirect('/process_imports')
def post(self): camper = Camper.get(self.request.get('key')) validationErrors=[] template_values = {'validationErrors': validationErrors} for name in ('firstName', 'lastName', 'birthDate'): if self.request.get(name) in (None, ''): validationErrors.extend([name + ' cannot be empty']) camper.firstName = self.request.get('firstName') camper.lastName = self.request.get('lastName') camper.note = self.request.get('note') try: camper.birthDate = util.string2Date(self.request.get('birthDate')) except: validationErrors.extend(['Invalid Date Format for Birthday']) if validationErrors: path = os.path.join(os.path.dirname(__file__), '../html/camper/camper_edit.html') self.response.out.write(template.render(path, template_values)) else: camper.put() self.redirect('/camper_view?key=' + str(camper.key()))