Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Update views.py
Browse files Browse the repository at this point in the history
  • Loading branch information
DeyanVNikolov committed Feb 21, 2024
1 parent abdea0d commit 8a8d8d7
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions website/home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import uuid
from pathlib import Path

import requests
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect
Expand Down Expand Up @@ -69,20 +70,13 @@ def hotels(request):
# select ONE random image from hotel.photos
photos = str(hotel.photos).split('|PHOTO|')
if len(photos) > 0:
print("MORE THAN 0")
print(photos)
# select first image, if not os.exists, select second, if not os.exists, select third, if not os.exists, select fourth, if not os.exists, select fifth
img = None
for photo in photos:
print("CURRENT PHOTO: " + photo)
if os.path.exists(f'static/cover/hotel/{hotel.id}/{photo}'):
print("FOUND IMAGE: " + photo)
r = requests.get(f'/static/cover/hotel/{hotel.id}/{photo}')
if r.status_code == 200:
img = photo
break
print("IMG: " + str(img))
path = f'static/cover/hotel/{hotel.id}/{img}'
print("PATH: " + path)
if img and os.path.exists(path):
if img:
print("SELECTED IMAGE: " + img)
hotel.main_img = img
else:
Expand Down

0 comments on commit 8a8d8d7

Please sign in to comment.