Ejemplo n.º 1
0
    def add_location(self, latitude, longitude, lot_type, address=None, pictures=None, description=None):
        """
        Adds a new Location object to the database

        Returns the newly created Location object
        """
        new_location = Location()
        new_location.latitude = latitude
        new_location.longitude = longitude
        new_location.address = address
        new_location.lot_type = lot_type
        new_location.description = description

        # Validate the picture to make sure it's not a malicious file
        try:
            if pictures:
                i = 1
                for picture in pictures[:3]:
                    setattr(new_location, "picture%i" % i, ImageField().clean(picture))
                    i += 1
        except ValidationError as ve:
            e = Exception(self)
            e.message = '; '.join(ve.messages)
            raise e

        new_location.save()

        return new_location
Ejemplo n.º 2
0
    def add_location(self, latitude, longitude, name, location_type=None, picture=None, description=None, safety=None, ease_of_use=None, capacity_type=None):
        """
        Adds a new Location object to the database

        Returns the newly created Location object
        """
        new_location = Location()
        new_location.latitude = latitude
        new_location.longitude = longitude
        new_location.name = name
        new_location.location_type = location_type
        new_location.picture = picture
        new_location.description = description
        new_location.safety = safety
        new_location.ease_of_use = ease_of_use
        new_location.capacity_type = capacity_type

        new_location.save()

        return new_location