예제 #1
0
    def perform_create(self, serializer):

        item = serializer.save()
        auth_user = self.request.user

        if 'arrival_loc' in self.request.data:
            arrival_loc   = self.request.data['arrival_loc']
            departure_loc = self.request.data['departure_loc']

            # First check User arrival information against our geocoded DB cache
            location_a = build_geocode_location(arrival_loc[0])

            # Next check User departure information
            location_b = build_geocode_location(departure_loc[0])

            # Update the Itinerary object with Location details
            item.arrival   = location_a
            item.departure = location_b
            # item.save()

        else:
            print "Location attributes not provided"

        item.user = auth_user
        item.save()
예제 #2
0
    def perform_create(self, serializer):

        auth_user = self.request.user
        # print serializer.data
        # We need to save this to accomodate the file uploads
        item = serializer.save()
        # Update with the proper user
        item.requester = auth_user
        item.save()

        if 'loc' in self.request.data:
            # Slightly different from our check inside the Itinerary and User 
            # ViewSets as the Angualr $uploads method is returning JSON
            if 'photo' in self.request.data:
                req_loc = json.loads(self.request.data['loc'])
            else:
                req_loc = self.request.data['loc']

            location = build_geocode_location(req_loc[0])

            # Update the Request object with Location details
            item.location = location
            item.save()

        else:
            print "Location attributes not provided"
예제 #3
0
    def perform_create(self, serializer):

        serializer.save()

        """
        Fine tune this when we expand on the Mailchimp API
        """
        # try:
        #     mcManager = get_mailchimp_api()
        #     mcManager.lists.subscribe(MAILCHIMP_LISTS['General'], {'email':self.request.data['email']})
        #     print "Email saved"

        # except mailchimp.ListAlreadySubscribedError:
        #     print "That email is already subscribed to the list"

        # except mailchimp.Error, e:
        #     print "Could not save email"

        # Update the Profile if additional information was passed
        if 'location' in self.request.data:
            profile_location = self.request.data['location']
            profile_phone    = self.request.data['phone']
            # mailings         = self.request.data['mailings']
            profile          = Profile.objects.get(user_id=serializer.data['id'])

            location = build_geocode_location(profile_location[0])

            # Set the Profile.attributes
            profile.phone      = profile_phone
            profile.location   = location
            # profile.mailings   = mailings
            
            profile.save()

        else:
            print "Attributes not provided"