def main_view(request): rand_list = list(tours.keys()) random.shuffle(rand_list) rand_tours = {i: tours[i] for i in rand_list[:6]} return render(request, 'index.html', { 'tours': rand_tours, 'departures': departures })
def get(self, request, *args, **kwargs): random_tours_id = sample(tours.keys(), 6) tour = {tour_id: tours[tour_id] for tour_id in random_tours_id} return render(request, 'tours/index.html', context={ 'tours': tour, 'departures': departures })
def get(self, request): random_tours = {} number_of_tours_on_page = 6 tours_keys = sample(tours.keys(), number_of_tours_on_page) for key in tours_keys: random_tours[key] = tours[key] max_stars = "★★★★★" context = {"tours": random_tours, "stars": max_stars} return render(request, 'index.html', context=context)
def get(self, request, id: int): if id not in tours.keys(): raise Http404('Страница не найдена') departure = tours[id]['departure'] return render( request, 'tour.html', { 'tour': tours[id], 'departure': departures[departure], 'departures': departures })
def get(self, request, *args, **kwargs): random_tours = dict() while True: el = random.choice(list(tours.keys())) if el not in random_tours: random_tours[el] = tours[el] if len(random_tours) == 6: break return render(request, 'index.html', { 'departures': departures, 'random_tours': random_tours })
def get(self, request, id, *args, **kwargs): city = "" for k, v in tour.items(): if id == k: for k1, v1 in v.items(): if k1 == "departure": for key, value in dep.items(): if key == v1: city = value if id not in tour.keys(): raise Http404 context = {'tours': tour[id], 'city': city} return render(request, 'tours/tour.html', context=context)
def get(self, request): r = [i for i in tours.keys()] shuffle(r) r = r[:6] tours_copy = {} for x in r: tours_copy[x] = tours[x] return render( request, self.template_name, { "title": title, "departures": departures, "subtitle": subtitle, "description": description, "tours": tours_copy })
def get(self, request, id): if id not in tours.keys(): raise Http404 context = { 'site_title': title, 'tour_title': tours[id]['title'] + ' ' + tours[id]['stars'] + ' ★', 'country': tours[id]['country'], 'departure': departures[tours[id]['departure']], 'nights': tours[id]['nights'], 'picture': tours[id]['picture'], 'description': tours[id]['description'], 'price': tours[id]['price'], 'departures': departures, 'active': 'msk', } return render(request, 'tour.html', context=context)
def get(self, request): random_keys = sample(tours.keys(), MAIN_PAGE_TOURS_COUNT) random_tours = {key: tours.get(key) for key in random_keys} return render(request, 'tours/index.html', context={'tours': random_tours})
def get(self, request, id): departure = departures.get(tours[id]['departure']) context = {'tour': tours[id], 'departure': departure, 'title': title} if id not in tours.keys(): raise Http404 return render(request, "tour.html", context=context)