Skip to content

Commit

Permalink
patch: resolve indentation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tinashechiraya authored May 6, 2024
1 parent 103d0e6 commit df2fab4
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions django_project/monitor/site_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,25 @@ def create(self, request, *args, **kwargs):

# Check if the 'images' field is present in the request.FILES
if 'images' in request.FILES:
images = request.FILES.getlist('images', [])
images = request.FILES.getlist('images', [])
else:
# fallback to using request.FILES directly
images = request.FILES.values()
# fallback to using request.FILES directly
images = request.FILES.values()

site_images = []

for image in images:
try:
# Check if the image is a tuple (field name, file)
if isinstance(image, tuple):
image = image[1]
try:
# Check if the image is a tuple (field name, file)
if isinstance(image, tuple):
image = image[1]

site_image = SiteImage(site=site, image=image)
site_image.full_clean() # Validate model fields before saving
site_image.save()
site_images.append(site_image)
except Exception as e:
return Response({'error': f'Error saving image: {str(e)}'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
site_image = SiteImage(site=site, image=image)
site_image.full_clean() # Validate model fields before saving
site_image.save()
site_images.append(site_image)
except Exception as e:
return Response({'error': f'Error saving image: {str(e)}'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)


return Response({'success': 'Images saved successfully'}, status=status.HTTP_201_CREATED)
Expand All @@ -114,9 +114,9 @@ def list(self, request):

def create(self, request, *args, **kwargs):
# Get the highest gid value
highest_gid = Sites.objects.latest('gid').gid if Sites.objects.exists() else 0
# Increment the gid value
new_gid = highest_gid + 1
highest_gid = Sites.objects.latest('gid').gid if Sites.objects.exists() else 0
# Increment the gid value
new_gid = highest_gid + 1

# Extract data from the request payload
site_data = request.data.get('site_data', {})
Expand Down Expand Up @@ -191,4 +191,3 @@ def get(self, request, latitude, longitude):
return Response([], status=status.HTTP_404_NOT_FOUND)
except Sites.DoesNotExist:
return Response([], status=status.HTTP_404_NOT_FOUND)

0 comments on commit df2fab4

Please sign in to comment.