コード例 #1
0
    def post(self, ride_id):
        self.auth()
        json_str = self.request.body
        data = json.loads(json_str)

        user = self.current_user()

        ride_validator = Schema({
            Required('passengers_max', default=1): Coerce(int),
            Required('date'): create_date(),
            'time': unicode,
            'details': unicode
        })

        try:
            data = ride_validator(data)
        except MultipleInvalid as e:
            print str(e)
            return self.json_resp(500, {
                'error': True,
                'message': 'Invalid data'
            })

        ride = Ride.get_by_id(int(ride_id))

        ride.passengers_max = data['passengers_max']
        ride.driver = user.key()
        ride.time = data['time']
        ride.details = data['details']
        ride.put()

        check_requester = Requester.all().filter('user ='******'ride =', ride).fetch(None)

        if check_requester:
            for cr in check_requester:
                cr.delete()

        passengers = Passenger.all().filter('ride =', ride.key()).fetch(None)
        for passenger in passengers:
            # NEW NOTIFICATION
            n = Noti()
            n.relation = ride.key()
            n.type = 'driver_joined'
            n.user = passenger.user.key()
            n.status = 'new'
            n.put()

        return self.json_resp(200, {
            'message': 'Success'
        })
コード例 #2
0
ファイル: events.py プロジェクト: ysubtle/rideshare
    def post(self, event_id):
        self.auth()

        json_str = self.request.body
        data = json.loads(json_str)

        event_validator = Schema(
            {
                Required('name'): unicode,
                'location': unicode,
                'ql_lat': Coerce(float),
                'ql_lng': Coerce(float),
                'ql_add': unicode,
                Required('date'): toolbox.create_date(),
                'time': unicode,
                'details': unicode
            },
            extra=True)

        try:
            data = event_validator(data)
        except MultipleInvalid as e:
            print str(e)
            return self.json_resp(500, {
                'error': True,
                'message': 'Invalid data'
            })

        user = self.current_user()

        event = Event.get_by_id(int(event_id))

        event.name = data['name']
        event.location = data['location']
        event.data = data['date']
        event.time = data['time']
        event.details = data['details']
        event.address = data['ql_add']
        event.lat = data['ql_lat']
        event.lng = data['ql_lng']
        event.put()

        self.json_resp(200, {
            'message': 'Event edited',
            'id': event.key().id()
        })
コード例 #3
0
ファイル: events.py プロジェクト: AparnaPonguru/rideshare-1
    def post(self, event_id):
        self.auth()

        json_str = self.request.body
        data = json.loads(json_str)


        event_validator = Schema({
            Required('name'): unicode,
            'location': unicode,
            'ql_lat': Coerce(float),
            'ql_lng': Coerce(float),
            'ql_add': unicode,
            Required('date'): toolbox.create_date(),
            'time': unicode,
            'details': unicode
        }, extra = True)

        try:
            data = event_validator(data)
        except MultipleInvalid as e:
            print str(e)
            return self.json_resp(500, {
                'error': True,
                'message': 'Invalid data'
            })

        user = self.current_user()

        event = Event.get_by_id(int(event_id))

        event.name = data['name']
        event.location = data['location']
        event.data = data['date']
        event.time = data['time']
        event.details = data['details']
        event.address = data['ql_add']
        event.lat = data['ql_lat']
        event.lng = data['ql_lng']
        event.put()

        self.json_resp(200, {
            'message': 'Event edited',
            'id': event.key().id()
        })
コード例 #4
0
ファイル: events.py プロジェクト: ysubtle/rideshare
    def post(self):
        self.auth()
        event = Event()

        json_str = self.request.body
        data = json.loads(json_str)

        user = self.current_user()

        event_validator = Schema(
            {
                Required('name'): unicode,
                Required('lat'): Coerce(float),
                Required('lng'): Coerce(float),
                Required('address'): unicode,
                Required('date'): toolbox.create_date(),
                'time': unicode,
                'details': unicode,
                'location': unicode
            },
            extra=True)

        try:
            data = event_validator(data)
        except MultipleInvalid as e:
            print str(e)
            return self.json_resp(500, {
                'error': True,
                'message': 'Invalid data'
            })

        # Refer to model.py for structure of data
        # class Event
        event.name = data['name']
        event.location = data['location']
        event.lat = data['lat']
        event.lng = data['lng']
        event.address = data['address']
        event.date = data['date']
        event.time = data['time']
        event.details = data['details']
        event.creator = user.key()
        event.user = user.key()

        if data['circle']:
            circle = Circle.get_by_id(int(data['circle']))
            if circle:
                event.circle = circle
        else:
            event.circle = None

        event.put()

        # NEW NOTIFICATION
        n = Noti()
        n.relation = event.key()
        n.type = 'new_event'
        n.user = user.key()
        n.status = 'new'
        n.put()

        # EMAIL NOTIFICATION
        if event.circle:
            c_members = User.all().filter('circles =',
                                          event.circle.key()).fetch(None)
            d = {
                'template':
                'event_created',
                'data': {
                    'circle_name': event.circle.name,
                    'circle_id': event.circle.key().id(),
                    'event_name': event.name,
                    'event_id': event.key().id()
                },
                'subject':
                'Ridecircles - An event was created in ' + event.circle.name,
                'users':
                c_members
            }

            sender(d)

        return self.json_resp(200, {
            'message': 'Event added!',
            'id': event.key().id()
        })
コード例 #5
0
    def post(self):
        self.auth()

        user = self.current_user()

        json_str = self.request.body
        data = json.loads(json_str)

        ride_validator = Schema({
            'passengers_max': Coerce(int),
            Required('date'): create_date(),
            'time': unicode,
            'details': unicode,
            'driver': bool,
            'driven_by': unicode,
            'dest_lat': Coerce(float),
            'dest_lng': Coerce(float),
            'dest_address': unicode,
            'ql_lat': Coerce(float),
            'ql_lng': Coerce(float),
            'ql_add': unicode,
            'recurring': unicode,
            'circle': Coerce(long),
            'event': unicode
        })

        try:
            data = ride_validator(data)
        except MultipleInvalid as e:
            return self.json_resp(500, {
                'error': True,
                'message': str(e)
            })

        ride = Ride()

        if data['event'] != '':
            event = Event.get_by_id(int(data['event']))
            if event:
                ride.dest_add = event.address
                ride.dest_lat = event.lat
                ride.dest_lng = event.lng
                ride.event = event.key()
            else:
                return self.json_resp(500, {
                    'message': 'Event does not exist'
                })
        else:
            event = None
            ride.dest_add = data['dest_address']
            ride.dest_lat = data['dest_lat']
            ride.dest_lng = data['dest_lng']

        ride.origin_add = data['ql_add']
        ride.origin_lat = data['ql_lat']
        ride.origin_lng = data['ql_lng']
        ride.date = data['date']
        ride.time = data['time']
        ride.creator = user

        if data['driver'] == True:
            ride.passengers_max = int(data['passengers_max'])
            ride.driver = user.key()
            if ride.recurring == 'false' or ride.recurring == 'none':
                ride.recurring = None
            else:
                ride.recurring = data['recurring']
            ride.driven_by = data['driven_by']

        if data['circle'] != '':
            circle = Circle.get_by_id(int(data['circle']))
            if circle:
                ride.circle = circle.key()
            else:
                return self.json_resp(500, {
                    'message': 'Circle does not exist'
                })
        else:
            circle = None
            ride.circle = None

        ride.put()

        if data['driver'] != True:
            p = Passenger()
            p.ride = ride.key()
            p.user = user
            p.seats = 1
            p.message = data['details']
            p.put()

        if event and circle:
            self.alert_requesters(event, circle, ride)

        return self.json_resp(200, {
            'message': 'Ride added!',
            'id': ride.key().id()
        })
コード例 #6
0
    def post(self, ride_id):
        self.auth()

        user = self.current_user()

        ride = Ride.get_by_id(int(ride_id))

        if not ride or ride.driver == None:
             return self.json_resp(500, {
                'error': 'Message'
            })

        json_str = self.request.body
        data = json.loads(json_str)

        ride_validator = Schema({
            Required('passengers_max', default=1): Coerce(int),
            Required('date'): create_date(),
            Required('time'): unicode,
            'details': unicode,
            'driven_by': unicode,
            'ql_add': unicode,
            'ql_lat': Coerce(float),
            'ql_lng': Coerce(float)
        })

        try:
            data = ride_validator(data)
        except MultipleInvalid as e:
            return self.json_resp(500, {
                'error': True,
                'message': str(e)
            })

        set_properties(ride, self.properties, data)

        ride.origin_add = data['ql_add']
        ride.origin_lat = data['ql_lat']
        ride.origin_lng = data['ql_lng']

        ride.put()

        # EMAIL NOTIFICATION
        passengers = Passenger.all().filter('ride =', ride.key()).fetch(None)

        notifications = Noti.all().filter('relation =', ride.key()).fetch(None)
        for n in notifications:
            n.status = 'new'
            n.put()

        user_have_noti = [n.user for n in notifications]
        for p in passengers:
            if p.user.key() not in user_have_noti:
                n = Noti()
                n.relation = ride.key()
                n.type = 'ride_updated'
                n.user = p.user.key()
                n.status = 'new'
                n.put()

        if passengers and ride.event and ride.event.circle:
            
            d = {
                'template': 'ride_edited',
                'data': {
                    'driver_name': ride.driver.name_x,
                    'driver_id': ride.driver.key().id(),
                    'circle_name': ride.event.circle.name,
                    'circle_id': ride.event.circle.key().id(),
                    'event_name': ride.event.name,
                    'event_id': ride.event.key().id(),
                    'ride_id': ride.key().id()
                },
                'subject': 'Ridecircles - Ride details updated',
                'users': [r.user for r in passengers]
            }

            sender(d)

        return self.json_resp(200, {
            'message': 'Edited.',
            'id': ride.key().id()
        })
コード例 #7
0
ファイル: events.py プロジェクト: AparnaPonguru/rideshare-1
    def post(self):
        self.auth()
        event = Event()

        json_str = self.request.body
        data = json.loads(json_str)

        user = self.current_user()

        event_validator = Schema({
            Required('name'): unicode,
            Required('lat'): Coerce(float),
            Required('lng'): Coerce(float),
            Required('address'): unicode,
            Required('date'): toolbox.create_date(),
            'time': unicode,
            'details': unicode,
            'location': unicode
        }, extra = True)

        try:
            data = event_validator(data)
        except MultipleInvalid as e:
            print str(e)
            return self.json_resp(500, {
                'error': True,
                'message': 'Invalid data'
            })

        # Refer to model.py for structure of data
        # class Event
        event.name = data['name']
        event.location = data['location']
        event.lat = data['lat']
        event.lng = data['lng']
        event.address = data['address']
        event.date = data['date']
        event.time = data['time']
        event.details = data['details']
        event.creator = user.key()
        event.user = user.key()

        if data['circle']:
            circle = Circle.get_by_id(int(data['circle']))
            if circle:
                event.circle = circle
        else:
            event.circle = None

        event.put()

        # NEW NOTIFICATION
        n = Noti()
        n.relation = event.key()
        n.type = 'new_event'
        n.user = user.key()
        n.status = 'new'
        n.put()

        # EMAIL NOTIFICATION
        if event.circle:
            c_members = User.all().filter('circles =', event.circle.key()).fetch(None)
            d = {
                'template': 'event_created',
                'data': {
                    'circle_name': event.circle.name,
                    'circle_id': event.circle.key().id(),
                    'event_name': event.name,
                    'event_id': event.key().id()
                },
                'subject': 'Ridecircles - An event was created in ' + event.circle.name,
                'users': c_members
            }

            sender(d)

        return self.json_resp(200, {
            'message': 'Event added!',
            'id': event.key().id()
        })