Advertisement
12311k

Untitled

Feb 9th, 2021
564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. from django.shortcuts import render
  2. from icecream.models import icecream_db
  3. from anfisa.models import friends_db
  4. from anfisa.services import what_weather, what_temperature, what_conclusion
  5.  
  6.  
  7. def index(request):
  8. icecreams = ''
  9. friends = ''
  10. city_weather = ''
  11. friend_output = ''
  12. selected_icecream = ''
  13. # подготовили к выводу рекомендацию
  14. conclusion = ''
  15.  
  16.  
  17. for friend in friends_db:
  18. friends += (f'<input type="radio" name="friend"'
  19. f' required value="{friend}">{friend}<br>')
  20.  
  21. for i in range(len(icecream_db)):
  22. ice_form = (f'<input type="radio" name="icecream" required'
  23. f' value="{icecream_db[i]["name"]}">{icecream_db[i]["name"]}')
  24.  
  25. ice_link = f'<a href="icecream/{i}/">узнать состав</a>'
  26. icecreams += f'{ice_form} | {ice_link} <br>'
  27.  
  28.  
  29.  
  30. if request.method == 'POST':
  31. selected_friend = request.POST['friend']
  32. selected_icecream = request.POST['icecream']
  33.  
  34. city = friends_db[selected_friend]
  35. weather = what_weather(city)
  36.  
  37.  
  38. # запишите в conclusion
  39. # результат вызова функции what_conclusion() с аргументом parsed_temperature
  40. conclusion = what_conclusion(what_temperature(weather))
  41.  
  42. friend_output = f'{selected_friend}, тебе прислали {selected_icecream}!'
  43.  
  44. city_weather = f'В городе {city} погода: {weather}'
  45.  
  46. context = {
  47. 'icecreams': icecreams,
  48. 'friends': friends,
  49. 'friend_output': friend_output,
  50. 'city_weather': city_weather,
  51. # передайте значение conclusion в шаблон
  52. 'conclusion': conclusion,
  53. }
  54. return render(request, 'homepage/index.html', context)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement