Skip to content

Commit

Permalink
second iteration done
Browse files Browse the repository at this point in the history
  • Loading branch information
thehighestmath committed Nov 29, 2020
1 parent e7da24a commit 1d34a5d
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 79 deletions.
2 changes: 1 addition & 1 deletion stepik_tours/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['localhost']
ALLOWED_HOSTS = ['localhost', '127.0.0.1']


# Application definition
Expand Down
4 changes: 2 additions & 2 deletions templates/tours/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<body>
<header class="container mt-3">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Stepik Travel</a>
<a class="navbar-brand" href="/">Stepik Travel</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
Expand All @@ -27,7 +27,7 @@
</div>
</nav>
</header>
{{ request.path }}
{#{{ request.path }}#}

<main class="container mt-3">
{% block main %}
Expand Down
78 changes: 16 additions & 62 deletions templates/tours/departure.html
Original file line number Diff line number Diff line change
@@ -1,68 +1,22 @@
{% extends 'tours/base.html' %}
{% block main %}
<h1 class="display-5 mt-4">Летим из Новосибирска</h1>
<p class="mb-4">Найдено 15 туров, от 26 000 до 84 600 и от 4 ночей до 15 ночей</p>
<h1 class="display-5 mt-4">Летим {{ departure }}</h1>
<p class="mb-4">Найдено {{ tours_info.count }} туров,
от {{ tours_info.start_price }} до {{ tours_info.end_price }}
и от {{ tours_info.start_night }} ночей до {{ tours_info.end_night }} ночей</p>
<!-- CARDS -->
<div class="row mt-5">
<div class="col-4">
<div class="card mb-4">
<img src="https://place-hold.it/300x200" class="card-img-top img-fluid" alt="">
<div class="card-body">
<h2 class="h5 card-title">Hotel title</h2>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-sm btn-primary">Подробнее</a>
</div>
</div>
</div>
<div class="col-4">
<div class="card mb-4">
<img src="https://place-hold.it/300x200" class="card-img-top img-fluid" alt="">
<div class="card-body">
<h2 class="h5 card-title">Hotel title</h2>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-sm btn-primary">Подробнее</a>
</div>
</div>
</div>
<div class="col-4">
<div class="card mb-4">
<img src="https://place-hold.it/300x200" class="card-img-top img-fluid" alt="">
<div class="card-body">
<h2 class="h5 card-title">Hotel title</h2>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-sm btn-primary">Подробнее</a>
</div>
</div>
</div>
<div class="col-4">
<div class="card mb-4">
<img src="https://place-hold.it/300x200" class="card-img-top img-fluid" alt="">
<div class="card-body">
<h2 class="h5 card-title">Hotel title</h2>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-sm btn-primary">Подробнее</a>
</div>
</div>
</div>
<div class="col-4">
<div class="card mb-4">
<img src="https://place-hold.it/300x200" class="card-img-top img-fluid" alt="">
<div class="card-body">
<h2 class="h5 card-title">Hotel title</h2>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-sm btn-primary">Подробнее</a>
</div>
</div>
</div>
<div class="col-4">
<div class="card mb-4">
<img src="https://place-hold.it/300x200" class="card-img-top img-fluid" alt="">
<div class="card-body">
<h2 class="h5 card-title">Hotel title</h2>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-sm btn-primary">Подробнее</a>
</div>
</div>
</div>
{% for tour in tours %}
<div class="col-4">
<div class="card mb-4">
<img src="{{ tour.picture }}" class="card-img-top img-fluid" alt="">
<div class="card-body">
<h2 class="h5 card-title">{{ tour.title }}</h2>
<p class="card-text">{{ tour.description }}</p>
<a href="/tour/{{ tour.id }}" class="btn btn-sm btn-primary">Подробнее</a>
</div>
</div>
</div>
{% endfor %}
</div>
{% endblock %}
12 changes: 3 additions & 9 deletions templates/tours/index.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
{% extends 'tours/base.html' %}
{% block main %}
<!-- HERO -->
<style>
.stroke {
-webkit-text-stroke-width: 1px;
-webkit-text-stroke-color: #f800ff;
}
</style>
<section class="jumbotron text-center mt-4"
{# previous background 'https://place-hold.it/1600x300' #}
style="
background: url({{ tours.0.picture }}) no-repeat;
background: url('https://place-hold.it/1600x300') no-repeat;
background-position: center center;
">
<h1 class="display-4 stroke">Всякие туры</h1>
<p class="lead stroke">Для тех, кого отвлекают дома</p>
<h1 class="display-4">Всякие туры</h1>
<p class="lead">Для тех, кого отвлекают дома</p>
<p class="mt-5 w-50 mx-auto stroke">Лучшие направления,где никто не будет вам мешать сидеть на берегу и изучать
программирование, дизайн, разработку игр и управление продуктами</p>
</section>
Expand Down
5 changes: 3 additions & 2 deletions templates/tours/tour.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{% extends 'tours/base.html' %}
{% load multiply %}
{% block main %}
<section class="mt-3 pb-5">
<h1 class="display-3 mt-4">{{ tour.title }} {{ tour.stars }}</h1>
<h1 class="display-3 mt-4">{{ tour.title }} {{ tour.stars|multiply:'★' }}</h1>
<!-- HERO -->
<p class="lead">Индия Из Новосибирска 5 ночей</p>
<p class="lead">{{ tour.country }} {{ departure }} {{ tour.nights }} ночей</p>
<img src="{{ tour.picture }}" class="w-75" alt="">
<p class="my-4 w-75">{{ tour.description }}</p>
<a href="#" class="btn btn-success btn-lg">Купить тур за {{ tour.price }}</a>
Expand Down
Empty file added tours/templatetags/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions tours/templatetags/multiply.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django import template

register = template.Library()


@register.filter(name='multiply')
def multiply(value, arg):
return arg * int(value)
26 changes: 23 additions & 3 deletions tours/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# Create your views here.
def main_view(request):
seed()
tours = []
while len(tours) != 6:
index = randint(1, len(dataset.tours))
Expand All @@ -17,16 +18,35 @@ def main_view(request):


def departure_view(request, departure):
tours = []
price = []
nights = []
for i in dataset.tours:
tour = dataset.tours[i]
if tour['departure'] == departure:
tours.append(tour)
price.append(tour['price'])
nights.append(tour['nights'])
return render(request, 'tours/departure.html', {
'departures': dataset.departures
'departures': dataset.departures,
'departure': dataset.departures[departure],
'tours': tours,
'tours_info': {
'count': len(tours),
'start_price': min(price),
'end_price': max(price),
'start_night': min(nights),
'end_night': max(nights),
}
})


def tour_view(request, id):
tour = dataset.tours.get(id)
print(tour)
tour['stars'] = '★' * int(tour['stars'])
# tour['stars'] = '★' * int(tour['stars'])
return render(request, 'tours/tour.html', {
'departures': dataset.departures,
'tour': tour
'tour': tour,
'departure': dataset.departures[tour['departure']],
})

0 comments on commit 1d34a5d

Please sign in to comment.