results table
This commit is contained in:
parent
d4bc4f7ce7
commit
1069b80317
@ -16,9 +16,10 @@ Including another URLconf
|
|||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
from alkatorapi.views import register
|
from alkatorapi.views import register, results
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('api/register', register),
|
path('api/register', register),
|
||||||
|
path('api/results', results),
|
||||||
]
|
]
|
||||||
|
@ -6,6 +6,11 @@ ALKATOR_CHOICES =(
|
|||||||
(3, "Nealkátor"),
|
(3, "Nealkátor"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ALKATOR_CHOICES_DICT = {
|
||||||
|
alkator_choice[0]: alkator_choice[1]
|
||||||
|
for alkator_choice in ALKATOR_CHOICES
|
||||||
|
}
|
||||||
|
|
||||||
class User(models.Model):
|
class User(models.Model):
|
||||||
first_name = models.CharField(max_length=120)
|
first_name = models.CharField(max_length=120)
|
||||||
last_name = models.CharField(max_length=120)
|
last_name = models.CharField(max_length=120)
|
||||||
|
@ -2,8 +2,9 @@ from django.shortcuts import render
|
|||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
|
import json
|
||||||
|
|
||||||
from .models import User
|
from .models import User, ALKATOR_CHOICES_DICT
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
@ -40,3 +41,21 @@ def register(request):
|
|||||||
)
|
)
|
||||||
user.save()
|
user.save()
|
||||||
return HttpResponse('{"success":"Úspěšná registrace."}', content_type='application/json')
|
return HttpResponse('{"success":"Úspěšná registrace."}', content_type='application/json')
|
||||||
|
|
||||||
|
|
||||||
|
def results(request):
|
||||||
|
results = []
|
||||||
|
n = 1
|
||||||
|
for user in User.objects.order_by('duration'):
|
||||||
|
if user.alkator_category == 1:
|
||||||
|
order = f'{n}.'
|
||||||
|
n += 1
|
||||||
|
else:
|
||||||
|
order = 'x.'
|
||||||
|
results.append({
|
||||||
|
'order': order,
|
||||||
|
'duration': user.duration,
|
||||||
|
'alkator_category': ALKATOR_CHOICES_DICT[user.alkator_category],
|
||||||
|
'starting_number': user.starting_number,
|
||||||
|
})
|
||||||
|
return HttpResponse(json.dumps(results), content_type='application/json')
|
@ -15,13 +15,17 @@ class Main extends Component {
|
|||||||
text: "",
|
text: "",
|
||||||
status: "",
|
status: "",
|
||||||
faq: false,
|
faq: false,
|
||||||
|
results: [],
|
||||||
};
|
};
|
||||||
|
fetch(addr_prefix + "/api/results").then(resp => resp.json()).then(json => {
|
||||||
|
this.setState({results: json})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
onSubmit(event){
|
onSubmit(event){
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
let form = document.getElementById("form");
|
let form = document.getElementById("form");
|
||||||
let formData = new FormData(form);
|
let formData = new FormData(form);
|
||||||
fetch("/api/register", {
|
fetch(addr_prefix + "/api/register", {
|
||||||
method:"POST",
|
method:"POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
}).then(resp => resp.json()).then(json => {
|
}).then(resp => resp.json()).then(json => {
|
||||||
@ -106,7 +110,7 @@ class Main extends Component {
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<img class="logo" src="/public/logo.svg"></img>
|
<img class="logo" src="/public/logo.svg"></img>
|
||||||
</div>
|
</div>
|
||||||
<div class="container text-center"><h1>Další ročník bude teprve oznámen!</h1></div>
|
<div class="container text text-center"><h1>Další ročník bude teprve oznámen!</h1></div>
|
||||||
{/*
|
{/*
|
||||||
<div class="container info text-center">
|
<div class="container info text-center">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -156,6 +160,26 @@ class Main extends Component {
|
|||||||
<p>Sportem ku chlastu!</p>
|
<p>Sportem ku chlastu!</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xl-6">
|
<div class="col-xl-6">
|
||||||
|
{this.state.results &&
|
||||||
|
<table class="table text">
|
||||||
|
<thead>
|
||||||
|
<th>Umístění</th>
|
||||||
|
<th>Čas</th>
|
||||||
|
<th>Kategorie</th>
|
||||||
|
<th>Startovní číslo</th>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{this.state.results.map(user =>
|
||||||
|
<tr>
|
||||||
|
<th>{user.order}</th>
|
||||||
|
<td>{user.duration}</td>
|
||||||
|
<td>{user.alkator_category}</td>
|
||||||
|
<td>{user.starting_number}</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
}
|
||||||
{/*
|
{/*
|
||||||
<img src="/public/trasa.png" style={{'width': '100%', 'height': 'auto'}}/>
|
<img src="/public/trasa.png" style={{'width': '100%', 'height': 'auto'}}/>
|
||||||
*/}
|
*/}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user