Exemplo n.º 1
0
Arquivo: app.py Projeto: xaknet/tours
def tour(id):
    if id in tours.keys():
        id = tours.get(id)
    else:
        return not_found(404)

    current_country = id.get("departure")
    from_city = data.departures.get(current_country)

    output = render_template(
        "tour.html",
        id=id,
        title=id.get("title"),
        description=id.get("description"),
        departure=id.get("departure"),
        picture=id.get("picture"),
        price=id.get("price"),
        stars=int(id.get("stars")),
        country=id.get("country"),
        nights=id.get("nights"),
        date=id.get("date"),
        departures=data.departures,
        current_country=current_country,
        from_city=from_city,
    )

    return output
Exemplo n.º 2
0
 def get(self, request, id):
     if id not in tours.keys():
         raise Http404
     departure = departures[tours[id]["departure"]]
     context = {
         'tour': tours[id],
         'departure': departure
     }
     return render(request, 'tours/tour.html', context=context)
Exemplo n.º 3
0
def check_tour(id):
    ret = "<h1>Такого тура не существует</h1>"
    try:
        if int(id) not in tours.keys():
            return ret, 404
        else:
            return "OK", 200
    except Exception as e:
        return ret, 404
Exemplo n.º 4
0
    def get(self, request, id):
        if id not in tours.keys():
            raise Http404

        return render(
            request, "tour.html", {
                'tour': tours[id],
                'departure_name': departures[tours[id]['departure']]
            })
def departure_html(departure):
    ret_departure = {}
    deps_dict = []
    for i in tours.keys():
        if tours[i]["departure"] == departure:
            ret_departure[i] = tours[i]
            deps_dict.append(tours[i])
    return render_template('departure.html',
                           tour=ret_departure,
                           departures=departures[departure],
                           deps=deps_dict)
Exemplo n.º 6
0
def departure_html(departure):
    ret, status = check_departure(departure)
    if status == 200:
        ret_departure = {}
        deps_dict = []
        for i in tours.keys():
            if tours[i]["departure"] == departure:
                ret_departure[i] = tours[i]
                deps_dict.append(tours[i])
        return render_template('departure.html',
                               tour=ret_departure,
                               departures=departures[departure],
                               deps=deps_dict,
                               departures_menu=departures)
    else:
        return ret
Exemplo n.º 7
0
    def get(self, request):
        TOURS_RANDOM_COUNT = 6
        tour_id_list = []
        for key in tours.keys():
            tour_id_list.append(key)  # получили список id туров, теперь из этого списка получаем шесть случайных чисел
        if len(tour_id_list) > TOURS_RANDOM_COUNT:
            tour_id_list = random.sample(tour_id_list, TOURS_RANDOM_COUNT)

        # словарь, в котором случайные туры, если их более 6
        random_dict = {}
        for id in tour_id_list:
            random_dict[id] = tours[id]

        context = {
            'title': title,
            'subtitle': subtitle,
            'description': description,
            'random_dict': random_dict
        }
        return render(request, 'tours/index.html', context=context)
Exemplo n.º 8
0
 def get(self, request):
     random_keys = sample(tours.keys(), 6)
     random_tours = {key: tours.get(key) for key in random_keys}
     return render(request,
                   'tours/index.html',
                   context={'tours': random_tours})