Ejemplo n.º 1
0
def data():
    # Создаем список случайных отелей
    list_random_items = [random.choice(list(tours.items()))]
    list_length = len(list_random_items)
    while list_length < 6:
        random_item_next = random.choice(list(tours.items()))
        count = 0
        for i in range(list_length):
            if list_random_items[i] != random_item_next:
                count += 1
        if count == list_length:
            list_random_items.append(random_item_next)
            list_length = len(list_random_items)

    list_numbers = []
    list_items = []
    for i in range(len(list_random_items)):
        lst = list(list_random_items[i])
        for j in range(len(lst)):
            if j % 2 == 0:
                list_numbers.append(lst[j])
            else:
                list_items.append(lst[j])

    # Получаем словарь случайно выбранных отелей
    random_tours = dict(zip(list_numbers, list_items))

    output = render_template('index.html',
                             tours=random_tours,
                             departure=departures)
    return output
Ejemplo n.º 2
0
def index_view():
    k = (INDEX_PAGE_TOURS_NUMBER if
         len(tours.items()) >= INDEX_PAGE_TOURS_NUMBER else len(tours.items()))
    random_tours = sample(tours.items(), k)
    return render_template(
        "index.html",
        title=title,
        subtitle=subtitle,
        description=description,
        tours=random_tours,
        navbar=departures,
    )
Ejemplo n.º 3
0
    def get(self, request, departure):
        tours_by_departure = {}
        for tour_id, tour in tours.items():
            if tour['departure'] == departure:
                tour['departure_name'] = departures[tour['departure']]
                tours_by_departure[tour_id] = tour
        count = len(tours_by_departure)
        price = []
        nights = []
        for tour_id, tour in tours_by_departure.items():
            price.append(tour['price'])
            nights.append(tour['nights'])
        price_min = min(price)
        price_max = max(price)
        nights_min = min(nights)
        nights_max = max(nights)
        try:
            departure = departures[departure]
        except KeyError:
            raise Http404

        return render(
            request, 'departure.html', {
                'departures': departures.items(),
                'departure': departure,
                'tours': tours_by_departure.items(),
                'count': count,
                'price_min': price_min,
                'price_max': price_max,
                'nights_min': nights_min,
                'nights_max': nights_max
            })
Ejemplo n.º 4
0
    def get(self, request, departure):
        if departure not in departures.keys():
            raise Http404
        # в контекст нужно передать также список туров для данного направления, можно сразу посчитать статистику
        # Туры по направлению и статистика по ним
        dep_tours = {}
        prices = set()
        nights = set()
        for id, tour in tours.items():
            if tour['departure'] == departure:
                dep_tours[id] = tours[id]
                prices.add(tour['price'])
                nights.add(tour['nights'])

        # подсчет статистики
        stats = {}
        # всего туров, цена мин, цена макс, ночей мин и ночей макс
        stats['tour_count'] = len(dep_tours)
        stats['min_price'] = min(prices)
        stats['max_price'] = max(prices)
        stats['min_nights'] = min(nights)
        stats['max_nights'] = max(nights)

        context = {
            'departure': departures[departure],
            'dep_tours': dep_tours,
            'stats': stats
        }
        return render(request, 'tours/departure.html', context=context)
Ejemplo n.º 5
0
def show_daparture(departure):
    from_town = departures.get(departure)
    # this will be a dict with tours for this departure
    tours_dict = dict()
    for key, value in tours.items():
        if value.get('departure') == departure:
            tours_dict[key] = value
    # count of tours for this departure
    counter = len(tours_dict)
    # correct typo for 'тур/ов/а'
    if counter == 1:
        counter_line = 'Найден 1 тур'
    elif counter == 11:
        counter_line = f'Найдено {counter} туров'
    elif 4 >= counter % 10 >= 1:
        counter_line = f'Найдено {counter} тура'
    else:
        counter_line = f'Найдено {counter} туров'
    return render_template('departure.html',
                           departure=departure,
                           departures=departures,
                           from_town=from_town,
                           title='Туры ' + from_town,
                           tours=tours_dict,
                           counter_line=counter_line)
Ejemplo n.º 6
0
    def get(self, request, departure):
        count = 0
        min_price = 10000000
        max_price = 0
        min_nights = 10000000
        max_nights = 0
        specific_tours = []
        for key, tour in tours.items():
            if tour["departure"] == departure:
                if tour["price"] < min_price:
                    min_price = tour["price"]
                if tour["price"] > max_price:
                    max_price = tour["price"]

                if tour["nights"] < min_nights:
                    min_nights = tour["nights"]
                if tour["nights"] > max_nights:
                    max_nights = tour["nights"]
                count += 1
                specific_tours.append(tour)
                specific_tours[-1].update({"id": key})
        context = {
            "departure_title": departures[departure][3:],
            "count": count,
            "max_price": max_price,
            "min_price": min_price,
            "min_nights": min_nights,
            "max_nights": max_nights,
            "tours": specific_tours
        }
        return render(request, 'departure.html', context=context)
Ejemplo n.º 7
0
Archivo: app.py Proyecto: vndv/travel
def departures_render(departure):
    tour_on_departure = {}
    for k, v in tours.items():
        if v["departure"] == departure:
            tour_on_departure[k] = v

    tour_price = []
    tour_nights = []
    for v in tour_on_departure.values():
        tour_price.append(v["price"])
        tour_nights.append(v["nights"])
    min_price = min(tour_price)
    max_price = max(tour_price)
    min_nights = min(tour_nights)
    max_nights = max(tour_nights)

    return render_template(
        "departure.html",
        departures=departures,
        departure=departure,
        tour_on_departure=tour_on_departure,
        title=title,
        min_price=min_price,
        max_price=max_price,
        min_nights=min_nights,
        max_nights=max_nights,
    )
Ejemplo n.º 8
0
def departures_list(departure):

    departure_tours = {
        key: value
        for key, value in tours.items() if value['departure'] == departure
    }
    list_tour = departure_tours.values()
    price_min = min(list_tour, key=lambda x: x['price'])
    price_max = max(list_tour, key=lambda x: x['price'])
    nights_min = min(list_tour, key=lambda x: x['nights'])
    nights_max = max(list_tour, key=lambda x: x['nights'])

    context = {
        'title': title,
        'page_title': title,
        'departures': departures,
        'departure': departures[departure],
        'tours': departure_tours,
        'price_min': price_min['price'],
        'price_max': price_max['price'],
        'nights_min': nights_min['nights'],
        'nights_max': nights_max['nights'],
    }

    return render_template('departure.html', **context)
Ejemplo n.º 9
0
def main():
    return render_template('index.html',
                           title=title,
                           subtitle=subtitle,
                           description=description,
                           departures=departures,
                           tours=dict(itertools.islice(tours.items(), 6)))
Ejemplo n.º 10
0
def render_departures(departure_id):
    departure_tours = {}
    for key, val in tours.items():
        if val['departure'] == departure_id:
            departure_tours.update({key: val})

    min_price_key = min(departure_tours.keys(),
                        key=(lambda k: departure_tours[k]['price']))
    max_price_key = max(departure_tours.keys(),
                        key=(lambda k: departure_tours[k]['price']))
    min_nights_key = min(departure_tours.keys(),
                         key=(lambda k: departure_tours[k]['nights']))
    max_nights_key = max(departure_tours.keys(),
                         key=(lambda k: departure_tours[k]['nights']))
    tours_info = {
        'min_price': departure_tours[min_price_key]['price'],
        'max_price': departure_tours[max_price_key]['price'],
        'min_nights': departure_tours[min_nights_key]['nights'],
        'max_nights': departure_tours[max_nights_key]['nights'],
    }

    return render_template('departure.html',
                           title=title,
                           subtitle=subtitle,
                           description=description,
                           departures=departures,
                           departure_id=departure_id,
                           tours=departure_tours,
                           tours_info=tours_info)
Ejemplo n.º 11
0
    def depart_city(self, direction):

        tour_departure = {}
        for id_tour, tour_info in tours.items():
            if tour_info["departure"] == direction:
                tour_departure[id_tour] = tour_info
        return (tour_departure)
Ejemplo n.º 12
0
 def get(self, request, departure):
     tours_dict = {}
     prices = []
     nights = []
     departure_city = set()
     for tour_id, tour_info in tours.items():
         tour_info_copy = tour_info.copy()
         if departure == tour_info_copy['departure']:
             tour_info_copy['stars'] = int(tour_info_copy['stars']) * '★'
             tours_dict.update({tour_id: tour_info_copy})
             prices.append(tour_info_copy['price'])
             nights.append(tour_info_copy['nights'])
             departure_city.add(departures[departure])
     tours_num = len(tours_dict)
     tours_min_price = min(prices)
     tours_max_price = max(prices)
     tours_min_nights = min(nights)
     tours_max_nights = max(nights)
     departure_info = {
         'tours_dict': tours_dict,
         'departure_city': departure_city.pop(),
         'tours_num': tours_num,
         'tours_min_price': tours_min_price,
         'tours_max_price': tours_max_price,
         'tours_min_nights': tours_min_nights,
         'tours_max_nights': tours_max_nights,
     }
     return render(request, 'departure.html', context=departure_info)
Ejemplo n.º 13
0
def departure_select(departure):
    keys = []
    tours_select = {}
    for key, value in tours.items():
        if value['departure'] == departure:
            keys.append(key)
            my_tour = {key: value}
            tours_select.update(my_tour)
    return keys, tours_select
Ejemplo n.º 14
0
 def get(self, request):
     return render(
         request, 'index.html', {
             'tours': sample(tours.items(), 6),
             'title': title,
             'subtitle': subtitle,
             'description': description,
             'departures': departures.items()
         })
Ejemplo n.º 15
0
def render_departures(departure):
    tour_items = dict(filter(lambda tour: tour[1]["departure"] == departure, tours.items()))
    return flask.render_template("departure.html",
                                 subtitle=subtitle,
                                 title=title,
                                 departure=departure,
                                 tours=tour_items,
                                 departures=departures
                                 )
Ejemplo n.º 16
0
def main():
    random_dict = dict(random.sample(tours.items(), 6))
    output = render_template('index.html',
                             tours=tours,
                             title=title,
                             subtitle=subtitle,
                             description=description,
                             departures=departures,
                             r_tours=random_dict)
    return output
Ejemplo n.º 17
0
Archivo: app.py Proyecto: xaknet/tours
def departure(departure):
    keys_list = []
    tours_list = []
    tours_dict = {}
    for key, value in tours.items():
        if departure == value.get("departure"):
            tours_list.append(value)
            tours_dict[key] = value
        else:
            print("Item not found")

    return render_template("departure.html",
                           departures=data.departures,
                           title=data.title,
                           departure=departure,
                           tours_list=tours_list,
                           keys_list=keys_list,
                           tours_dict=tours_dict,
                           tours=tours.items())
Ejemplo n.º 18
0
def render_departures(departure):
    needed_tours = {}
    for tour_number, tour_info in tours.items():
        if tour_info.get('departure') == departure:
            needed_tours.update({tour_number: tour_info})

    return render_template('departure.html',
                           title=title,
                           departure=departure,
                           departures=departures,
                           tours=needed_tours)
Ejemplo n.º 19
0
def departures_view(city):
    tours_for_city = []
    for key, value in tours.items():
        if value['departure'] == city:
            value['id'] = key
            tours_for_city.append(value)
    name = departures[city].split()[1]
    return render_template('departure.html',
                           city=tours_for_city,
                           departures=departures,
                           name=name)
Ejemplo n.º 20
0
def departure(name_departure):
    tours_departure = {}
    for key, value in tours.items():
        if value["departure"] == name_departure:
            tours_departure[key] = value
            destination = departures[name_departure]
    output = render_template('departure.html',
                             destination=destination[3:],
                             departure=departures,
                             tours=tours_departure,
                             tours_list=list(tours_departure.values()))
    return output
Ejemplo n.º 21
0
def MainView(request):

    tours_list = sample(tours.items(), 6)

    context = {
        'subtitle': subtitle,
        'description': description,
        'departures': departures,
        'tours': tours_list,
    }

    return render(request, 'index.html', context=context)
Ejemplo n.º 22
0
def departure(departure):
    departure_prices = []
    departure_nights = []
    tours_for_departure = {}
    for tour_id, tour in tours.items():
        if tour['departure'] == departure:
            departure_prices.append(tour['price'])
            departure_nights.append(tour['nights'])
            tours_for_departure[tour_id] = tour
    return render_template('departure.html', departure=departure, tours=tours_for_departure, departures=departures,
                           title=title, single_departures=single_departures,
                           subtitle=subtitle, description=description,
                           departure_prices=departure_prices, departure_nights=departure_nights)
Ejemplo n.º 23
0
Archivo: app.py Proyecto: sula8/tours
def render_departures(departure):
	dep_city = departures[departure].replace("Из", "из")
	tours_from_departure = []
	for num, tour in tours.items():
		if tour["departure"] == departure:
			tour["id"] = num
			tours_from_departure.append(tour)
	return render_template(
		'departure.html',
		title=title,
		departures=departures,
		dep_city=dep_city,
		tours=tours_from_departure,
	)
Ejemplo n.º 24
0
def data_departures(departure):

    if departure not in departures:
        return 'Такого направления не существует.'

    departure_title = departures[departure]
    departure_tours = {
        key: value
        for key, value in tours.items() if value['departure'] == departure
    }

    return render_template('data-departure.html',
                           departure=departure_title,
                           tours=departure_tours)
Ejemplo n.º 25
0
    def get(self, request, departure):

        list_tours = dict(filter(lambda tour: departure == tour[1]['departure'], tours.items()))

        context = {
            'tours': list_tours,
            'departure': departures[departure],
            'number_tours': len(list_tours),
            'max_price': get_max_value('price', list_tours),
            'min_price': get_min_value('price', list_tours),
            'max_nights': get_max_value('nights', list_tours),
            'min_nights': get_min_value('nights', list_tours),
        }

        return render(request, 'tours/departure.html', context=context)
Ejemplo n.º 26
0
def get_departure(departure):
    #фильтрация туров по направлению
    f_tours = {k: v for (k, v) in tours.items() if v['departure'] == departure}
    # костыль, чтобы первый символ в названии направления перевести в нижний регистр как в образце - "из" вместо "Из"
    new_title = str(departures[departure][0]).lower() + str(
        departures[departure][1:])
    #формируем список цен для направления
    prices = (list({k: v["price"] for (k, v) in f_tours.items()}.values()))
    #формируем список количества ночей для направления
    nights = (list({k: v["nights"] for (k, v) in f_tours.items()}.values()))
    # костыль, чтобы сделать формат вывода стоимости как в образце "ЧЧ ЧЧЧ"
    min_price = str(min(prices))[:2] + ' ' + str(min(prices))[2:]
    max_price = str(max(prices))[:2] + ' ' + str(max(prices))[2:]
    output = render_template('departure.html', f_tours = f_tours, new_title=new_title, nights=nights, prices=prices, \
            min_price= min_price, max_price=max_price, title=title, departures=departures)
    return output
Ejemplo n.º 27
0
def departure_view(departure_id):
    departure_name = departures.get(departure_id)
    if departure_name is None:
        abort(404, "The departure is not found.")
    departure_tours = {
        key: value
        for (key, value) in tours.items()
        if tours[key]["departure"] == departure_id
    }
    return render_template(
        "departure.html",
        departure={
            "name": departure_name,
            "tours": departure_tours
        },
        navbar=departures,
        title=title,
    )
Ejemplo n.º 28
0
def render_index():
    log_data_tours = {}
    amount = 1

    for d_tours_key, d_tour_value in data_tours.items():
        if amount <= 6:
            log_data_tours[d_tours_key] = d_tour_value
            amount += 1
        else:
            break

    return render_template(
        "index.html",
        title=data_title,
        subtitle=data_subtitle,
        description=data_description,
        departures=data_departures,
        tours=log_data_tours,
    )
Ejemplo n.º 29
0
def render_departures(id_departure):
    new_departure = {}
    cost_tours = []
    amount_nights = []

    for d_tour_key, d_tour_value in data_tours.items():
        if d_tour_value.get("departure") == id_departure:
            new_departure[d_tour_key] = d_tour_value
            cost_tours.append(d_tour_value.get("price"))
            amount_nights.append(d_tour_value.get("nights"))

    return render_template(
        "departure.html",
        title=data_title,
        data_tours=new_departure,
        departures=data_departures,
        cost_tours=cost_tours,
        amount_nights=amount_nights,
    )
Ejemplo n.º 30
0
 def get(self, request):
     tours_pictures = []
     tours_list = []
     for tour_id, tour_info in tours.items():
         tour_info_copy = tour_info.copy()
         tour_info_copy['stars'] = int(tour_info_copy['stars']) * '★'
         del tour_info_copy['departure']
         tours_list.append({tour_id: tour_info_copy})
         tours_pictures.append(tour_info_copy['picture'])
     tours_random = sample(tours_list, 6)
     tours_random_dicts = {}
     for tour in tours_random:
         tours_random_dicts.update(tour)
     tours_picture_random = sample(tours_pictures, 1)
     tours_info = {
         'subtitle': subtitle,
         'description': description,
         'tours_random_dicts': tours_random_dicts,
         'tours_picture_random': tours_picture_random[0],
     }
     return render(request, 'main.html', context=tours_info)