Beispiel #1
0
    def clean(self):
        super(Event, self).clean()

        if not self.parent or (
                isinstance(self.parent.get_content_model(), EventContainer)
                and self.parent.get_content_model().hide_children):
            self.in_navigation = False

        if self.lat and not self.lon:
            raise ValidationError("Longitude required if specifying latitude.")

        if self.lon and not self.lat:
            raise ValidationError("Latitude required if specifying longitude.")

        if not (self.lat and self.lon) and not self.mappable_location:
            self.mappable_location = self.location.replace("\n", ", ")

        if self.mappable_location:  #location should always override lat/long if set
            g = GoogleMaps(domain=settings.MZEVENTS_GOOGLE_MAPS_DOMAIN)
            try:
                location, (lat, lon) = g.geocode(self.mappable_location)
            except GQueryError as e:
                raise ValidationError(
                    "The mappable location you specified could not be found on {service}: \"{error}\" Try changing the mappable location, removing any business names, or leaving mappable location blank and using coordinates from getlatlon.com."
                    .format(service="Google Maps", error=e.message))
            self.mappable_location = location
            self.lat = lat
            self.lon = lon
Beispiel #2
0
    def clean(self):
        """
        Validate set/validate mappable_location, longitude and latitude.
        """
        super(EventLocation, self).clean()

        if self.lat and not self.lon:
            raise ValidationError("Longitude required if specifying latitude.")

        if self.lon and not self.lat:
            raise ValidationError("Latitude required if specifying longitude.")

        if not (self.lat and self.lon) and not self.mappable_location:
            self.mappable_location = self.address.replace("\n",", ")

        if self.mappable_location and not (self.lat and self.lon): #location should always override lat/long if set
            g = GoogleMaps(domain=settings.EVENT_GOOGLE_MAPS_DOMAIN)
            try:
                mappable_location, (lat, lon) = g.geocode(self.mappable_location.encode('utf-8'))
            except GQueryError as e:
                raise ValidationError("The mappable location you specified could not be found on {service}: \"{error}\" Try changing the mappable location, removing any business names, or leaving mappable location blank and using coordinates from getlatlon.com.".format(service="Google Maps", error=e.message))
            except ValueError as e:
                raise ValidationError("The mappable location you specified could not be found on {service}: \"{error}\" Try changing the mappable location, removing any business names, or leaving mappable location blank and using coordinates from getlatlon.com.".format(service="Google Maps", error=e.message))
            self.mappable_location = mappable_location
            self.lat = lat
            self.lon = lon
Beispiel #3
0
    def clean(self):
        super(Event, self).clean()

        if not self.end_date:
            self.end_date = self.date

        if self.date > self.end_date:
            raise ValidationError("Start date must be sooner than end date.")

        if self.date == self.end_date and self.start_time > self.end_time:
            raise ValidationError("Start time must be sooner than end time.")

        if self.lat and not self.lon:
            raise ValidationError("Longitude required if specifying latitude.")

        if self.lon and not self.lat:
            raise ValidationError("Latitude required if specifying longitude.")

        if not (self.lat and self.lon) and not self.mappable_location:
            self.mappable_location = self.location.replace("\n",", ")

        if self.mappable_location: #location should always override lat/long if set
            g = GoogleMaps(domain=settings.MZEVENTS_GOOGLE_MAPS_DOMAIN)
            try:
                location, (lat, lon) = g.geocode(self.mappable_location.encode('utf-8'))
            except GQueryError as e:
                raise ValidationError("The mappable location you specified could not be found on {service}: \"{error}\" Try changing the mappable location, removing any business names, or leaving mappable location blank and using coordinates from getlatlon.com.".format(service="Google Maps", error=e.message))
            except ValueError as e:
                raise ValidationError("The mappable location you specified could not be found on {service}: \"{error}\" Try changing the mappable location, removing any business names, or leaving mappable location blank and using coordinates from getlatlon.com.".format(service="Google Maps", error=e.message))
            self.mappable_location = location
            self.lat = lat
            self.lon = lon