Skip to content

Commit

Permalink
Merge pull request #8 from fng3r/rc
Browse files Browse the repository at this point in the history
rc 2 master
  • Loading branch information
fng3r authored Jan 30, 2024
2 parents 403494b + 930e1bb commit cf07089
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 38 deletions.
35 changes: 17 additions & 18 deletions haxball_site/reservation/templatetags/reservation_extras.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from datetime import timedelta
from datetime import time

from django import template
from django.contrib.auth.models import AnonymousUser
from django.db.models import Q
from django.db.models.functions import datetime
from django.utils import timezone
from tournament.models import Player, Team, League, TourNumber, Match
from ..models import ReservationEntry
from reservation.models import ReservationHost

register = template.Library()

Expand Down Expand Up @@ -43,7 +41,7 @@ def reservation_form(user):
t = teams_can_reserv(user)
actual_tour = TourNumber.objects.filter(league__championship__is_active=True, is_actual=True,
league__teams__in=t).distinct()
print(actual_tour)

if actual_tour is None:
return {
'matches': []
Expand All @@ -54,27 +52,28 @@ def reservation_form(user):

# Просматриваем все активные туры и смотрим матчи, которые не сыграны и на которых нету брони
for tour in actual_tour:
matches_unplayed = Match.objects.filter((Q(team_home__in=t) | Q(team_guest__in=t)), is_played=False,
numb_tour__number__lte=tour.number, league=tour.league,
match_reservation=None
).order_by('-numb_tour__number').distinct()
matches_unplayed = \
(Match.objects
.filter((Q(team_home__in=t) | Q(team_guest__in=t)), is_played=False,
numb_tour__number=tour.number, league=tour.league,
match_reservation=None)
.distinct()
.order_by('-numb_tour__number'))
matches_to_choose.extend(matches_unplayed)

date_today = datetime.datetime.today()
"""
Было нужно, когда можно было бронить матчи до какого-то времени.
time_end = datetime.datetime(year=actual_tour.date_to.year, month=actual_tour.date_to.month,
day=actual_tour.date_to.day, hour=23, minute=30, second=0)
"""
hosts = ReservationHost.objects.filter(is_active=True)
today = datetime.datetime.today().date()
tomorrow = today + timedelta(days=1)
hours_list = list(range(18, 24))
minutes_list = [0, 15, 30, 45]
return {
'matches': matches_to_choose,
'user': user,
"date_today": date_today.date(),
"date_tomorrow": date_today.date() + timedelta(days=1),
"hours_list": hours_list,
"minutes_list": minutes_list
'date_today': today,
'date_tomorrow': tomorrow,
'hours_list': hours_list,
'minutes_list': minutes_list,
'hosts': hosts
}


Expand Down
25 changes: 11 additions & 14 deletions haxball_site/reservation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,17 @@ def get_context_data(self, *, object_list=None, **kwargs):
def post(self, request):
data = request.POST

# date_time_obj = datetime.strptime(data['time_date'], '%Y-%m-%dT%H:%M')
date_time_obj = datetime.combine(datetime.strptime(data["match_date"], '%Y-%m-%d').date(),
time(hour=int(data["match_hour"]), minute=int(data["match_minute"])))
d1 = date_time_obj - timedelta(minutes=29)
d2 = date_time_obj + timedelta(minutes=29)
reserved = ReservationEntry.objects.filter(time_date__range=[d1, d2])
active_hosts = ReservationHost.objects.filter(is_active=True)
if reserved.count() < active_hosts.count():
hosts = set(active_hosts)
for i in reserved:
hosts.remove(i.host)
h = hosts.pop()
ReservationEntry.objects.create(author=request.user, time_date=date_time_obj,
match_id=int(data['match']), host=h)
match_id = int(data['match'])
host_id = int(data['match_host'])
match_date = datetime.combine(datetime.strptime(data['match_date'], '%Y-%m-%d').date(),
time(hour=int(data['match_hour']), minute=int(data['match_minute'])))
prev_match_date = match_date - timedelta(minutes=29)
next_match_date = match_date + timedelta(minutes=29)

reserved = ReservationEntry.objects.filter(time_date__range=[prev_match_date, next_match_date], host_id=host_id)
if reserved.count() == 0:
ReservationEntry.objects.create(author=request.user, time_date=match_date,
match_id=match_id, host_id=host_id)
return redirect('reservation:host_reservation')
else:
return render(request, 'reservation/reservation_list.html', {
Expand Down
4 changes: 2 additions & 2 deletions haxball_site/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
})
(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");

ym(66548209, "init", {
ym(96287121, "init", {
clickmap: true,
trackLinks: true,
accurateTrackBounce: true,
webvisor: true
});
</script>
<noscript>
<div><img src="https://mc.yandex.ru/watch/66548209" style="position:absolute; left:-9999px;" alt=""/></div>
<div><img src="https://mc.yandex.ru/watch/96287121" style="position:absolute; left:-9999px;" alt=""/></div>
</noscript>
<!-- /Yandex.Metrika counter -->
<meta charset="UTF-8">
Expand Down
2 changes: 1 addition & 1 deletion haxball_site/templates/core/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h6 style="text-decoration: underline">Смотрите нас тут</h6>


<div class="card mb-1 mr-0 mt-2 text-right">
<iframe src="https://yoomoney.ru/quickpay/shop-widget?writer=seller&default-sum=500&button-text=12&payment-type-choice=on&successURL=https%3A%2F%2Fwww.cis-haxball.com%2F&quickpay=shop&account=410013109672833&targets=%D0%9F%D0%B5%D1%80%D0%B5%D0%B2%D0%BE%D0%B4%20%D0%BF%D0%BE%20%D0%BA%D0%BD%D0%BE%D0%BF%D0%BA%D0%B5&"
<iframe src="https://yoomoney.ru/quickpay/shop-widget?writer=seller&default-sum=500&button-text=12&payment-type-choice=on&successURL=https%3A%2F%2Fwww.cis-haxball.com%2F&quickpay=shop&account=4100118530893229&targets=%D0%9F%D0%B5%D1%80%D0%B5%D0%B2%D0%BE%D0%B4%20%D0%BF%D0%BE%20%D0%BA%D0%BD%D0%BE%D0%BF%D0%BA%D0%B5&"
width="100%" height="250" frameborder="0" allowtransparency="true" scrolling="no"></iframe>
</div>

Expand Down
18 changes: 15 additions & 3 deletions haxball_site/templates/reservation/reservation_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<form method="POST" class="row p-3">
{% csrf_token %}
<input type="hidden" name="author" value="{{ user.id }}">
<div class="form-group text-center col-7">
<div class="form-group text-center col-5">
<label for="match" class="h6 mb-1">Матч</label>
<select id="match" class="form-control" name="match">
{% for m in matches %}
Expand All @@ -24,7 +24,7 @@
</select>

</div>
<div class="form-group col-3 mb-1 text-center">
<div class="form-group col-2 mb-1 text-center">

<label for="match_time" class="mb-1 h6">Время матча</label>
<div class="row">
Expand Down Expand Up @@ -52,9 +52,21 @@

</div>

<div class="form-group col-3 mb-1 px-2 text-center">

<label for="match_host" class="mb-1 h6">Хост</label>
<select class="match_host custom-select" name="match_host">
{% for host in hosts %}
<option {% if forloop.first %}selected{% endif %} value="{{ host.id }}">
{{host.name}}
</option>
{% endfor %}
</select>

</div>

<div class="d-flex justify-content-end w-100">
<button type="submit" class="btn btn-primary mr-3">Забронировать хост</button>
<button type="submit" class="btn btn-primary mr-2 col-2">Забронировать хост</button>
</div>

</form>
Expand Down

0 comments on commit cf07089

Please sign in to comment.