Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Places/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
path('save-complaints',views.Save_Complaints, name='report_complaint'),
path('rate_and_review/<int:pk>/',views.Rate_Review,name='rate_review'),
path('save_review/<int:pk>/',views.Review,name='save_review'),
path('',views.all_places, name="all_places"),
]
9 changes: 8 additions & 1 deletion Places/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,11 @@ def Review(request,pk):
place = PlacesDetails.objects.get(pk=pk)
rating_review = RatingReview.objects.create(safety=safety,sanitization=sanitization,security=security,overall_fun=overallfun,place=place,user=user,review=desc)
rating_review.save()
return redirect('/')
return redirect('/')

def all_places(request):
places = PlacesDetails.objects.all()
context = {
"places" : places
}
return render(request, "Places/all_places.html", context)
25 changes: 21 additions & 4 deletions home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from blog.models import Post

def homepage(request):
all_places = PlacesDetails.objects.all()
all_places = get_top_places()
top_posts = get_top_posts()
if request.user.is_authenticated:
d = request.user
Expand All @@ -22,8 +22,8 @@ def homepage(request):
all_reviews.append(reviews)
latitude = places.position.latitude
longitude = places.position.longitude
#weather_info=get_weather_data(latitude,longitude)
#places.weather_info=weather_info #adding weather info to place object
weather_info=get_weather_data(latitude,longitude)
places.weather_info=weather_info #adding weather info to place object
for reviews_qs in all_reviews:
rating = 0
count = 0
Expand Down Expand Up @@ -169,6 +169,23 @@ def get_weather_data(latitude,longitude):
weather_info['precipitation in mm']=city_weather['current']['precip_mm']
weather_info['last updated time']=city_weather['current']['last_updated']
return weather_info

def get_top_places():
top_places = []
places = []
ratings = RatingReview.objects.all()
for r in ratings:
places.append(r)

places.sort(key=lambda x: (int(x.safety) + int(x.sanitization) + int(x.security)), reverse=True)
places = places[:6]
for p in places:
top_places.append(p.place)
all_places = PlacesDetails.objects.all()
for p in all_places:
top_places.append(p)
res = [i for n, i in enumerate(top_places) if i not in top_places[:n]]
return res

def get_ratio(x):
if x.dislikes == 0:
Expand All @@ -182,4 +199,4 @@ def get_top_posts():
top_posts.append(post)
top_posts.sort(key=lambda x: get_ratio(x), reverse=True)
top_posts = top_posts[:6]
return top_posts
return top_posts
Loading