Exemple #1
0
 def perform_create(self, serializer):
     municipality = Municipality.get_current_municipality_for_moderator(self.request.user)
     if settings.GOOGLE_GEOCODING_API_KEY and 'coordinates' not in self.request.data:
         address = self.request.data.get('address', '')
         zip_code = self.request.data.get('zip_code', '')
         city = self.request.data.get('city', '')
         formatted_address = f'{address},+{zip_code}+{city}'
         try:
             coordinates = get_coordinates_from_address(formatted_address)
         except APIException:
             raise serializers.ValidationError('This address could not be geocoded. Please confirm your address is right, or try again later.')
         serializer.save(created_by=self.request.user, municipality=municipality, coordinates=coordinates)
     else:
         serializer.save(created_by=self.request.user, municipality=municipality)
Exemple #2
0
 def perform_create(self, serializer):
     municipality = Municipality.get_current_municipality_for_moderator(
         self.request.user)
     serializer.save(municipality=municipality)