Exemplo n.º 1
0
      def get(self):
        city = self.request.get('city')
        street = self.request.get('street')
        streetNum = self.request.get('streetNum')
        dateDD = self.request.get('dateDD')
        dateMM = self.request.get('dateMM')
        dateYYYY = self.request.get('dateYYYY')
        time = self.request.get('time')
        basis = self.request.get('basis')
        sun = self.request.get('sun')
        mon = self.request.get('mon')
        tues = self.request.get('tues')
        wednes = self.request.get('wednes')
        thurs = self.request.get('thurs')
        fri = self.request.get('fri')
        satur = self.request.get('satur')
 
        if city != 'Driving To My City' and (street == "" or streetNum == ""):
            self.error(403)
            self.response.write('Please Fill street and streetNum')
            return
			
        if basis != 'once' and basis != 'weekly':
            self.error(403)
            self.response.write('Please choose basis by the radio box.')
            return

        if basis == 'once':
            if dateDD == 'DD' or dateMM == 'MM' or dateYYYY == 'Select A Year':
                self.error(403)
                self.response.write('Please insert full date')
                return

        if basis == 'weekly':
            if sun == 'false' and mon == 'false' and tues == 'false' and wednes == 'false' and thurs == 'false' and fri == 'false' and satur == 'false':
                self.error(403)
                self.response.write('Please select at least one day.')
                return

        if time == 'Select A Time':
            self.error(403)
            self.response.write('Please insert a time')
            return

        user = None
        if self.request.cookies.get('our_token'):    #the cookie that should contain the access token!
            user = User.checkToken(self.request.cookies.get('our_token'))
        else:
            self.redirect('/')
	
        newRide = Ride()
        if city == 'Driving To My City':
            newRide.city = user.homeCity
            newRide.street = user.homeStreet
            newRide.streetNum = user.homeStreetNum
        else:
            newRide.city = city
            newRide.street = street
            newRide.streetNum = streetNum
			
        if basis == 'once':
            newRide.dateDD = int(dateDD)
            newRide.dateMM = int(dateMM)
            newRide.dateYYYY = int(dateYYYY)
#            self.error(403)
#            self.response.write(newRide.dateMM)
#            return
            date = datetime.date(int(dateYYYY), int(dateMM), int(dateDD))
            newRide.date = date
            weekDay = ['mon', 'tues', 'wednes', 'thurs', 'fri', 'satur', 'sun']
            newRide.weeklyDays.append(weekDay[date.weekday()])

        if basis == 'weekly':
            if sun == 'true':
                newRide.weeklyDays.append('sun')

            if mon == 'true':
                newRide.weeklyDays.append('mon')

            if tues == 'true':
                newRide.weeklyDays.append('tues')

            if wednes == 'true':
                newRide.weeklyDays.append('wednes')

            if thurs == 'true':
                newRide.weeklyDays.append('thurs')

            if fri == 'true':
                newRide.weeklyDays.append('fri')

            if satur == 'true':
                newRide.weeklyDays.append('satur')

        newRide.time = time
        rideKey = newRide.put()
        user.rideKeys.append(rideKey)
        user.put()
        self.response.write(json.dumps({'status':'OK'}))