diff --git a/Places/urls.py b/Places/urls.py index f63f0d53..6155ac7a 100755 --- a/Places/urls.py +++ b/Places/urls.py @@ -5,4 +5,5 @@ path('save-complaints',views.Save_Complaints, name='report_complaint'), path('rate_and_review//',views.Rate_Review,name='rate_review'), path('save_review//',views.Review,name='save_review'), + path('',views.all_places, name="all_places"), ] diff --git a/Places/views.py b/Places/views.py index 2b7180bc..585b0214 100755 --- a/Places/views.py +++ b/Places/views.py @@ -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('/') \ No newline at end of file + return redirect('/') + +def all_places(request): + places = PlacesDetails.objects.all() + context = { + "places" : places + } + return render(request, "Places/all_places.html", context) \ No newline at end of file diff --git a/home/views.py b/home/views.py index 1d3afac2..e444ad82 100644 --- a/home/views.py +++ b/home/views.py @@ -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 @@ -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 @@ -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: @@ -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 \ No newline at end of file + return top_posts diff --git a/templates/Places/all_places.html b/templates/Places/all_places.html new file mode 100644 index 00000000..bd27bf5f --- /dev/null +++ b/templates/Places/all_places.html @@ -0,0 +1,503 @@ +{% load static %} +{% load index %} + + + + + + + + + Home + {% include "../scripts.html" with is_index=1 is_profile=0 is_register=0 is_complaints=0 is_rating_review=0 is_edit_profile=0 %} + + + + + + {% include "../navbar.html" with is_search=0 is_home=1 is_navbar_responsive=1 is_home_nav=1 is_services=1 is_places=1 is_team=0 is_contributors=0 is_report=1 is_report_page=0 %} + + + +
+
+ +
+
+

All Places

+ +
+
+ {% for p in places %} +
+ +
+ +
+ + +
+
+
{{ p.name }}
+
{{ p.city }}
+
+
+
+ {% endfor %} +
+
+ {% if user.is_authenticated %} + {% for p in places %} + + + {% endfor %} + {% endif %} +
+
+ + + + + + + + + + + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 39e44255..dcc148af 100644 --- a/templates/index.html +++ b/templates/index.html @@ -239,7 +239,7 @@

Rating And Review

-

Places

+

Top Places

Varanasi a city of Ghosts and Temples !

diff --git a/templates/navbar.html b/templates/navbar.html index 44c97b34..5e22f891 100644 --- a/templates/navbar.html +++ b/templates/navbar.html @@ -83,7 +83,7 @@

No places to show

{% endif %} {% if is_places %} - + {% endif %} {% if is_team %}