auto refresh using ajax in virtualevents_view
This commit is contained in:
@@ -763,6 +763,7 @@ class VirtualRaceSelectForm(forms.Form):
|
|||||||
choices = get_countries()
|
choices = get_countries()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(VirtualRaceSelectForm, self).__init__(*args, **kwargs)
|
super(VirtualRaceSelectForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['country'] = forms.ChoiceField(
|
self.fields['country'] = forms.ChoiceField(
|
||||||
|
|||||||
22
rowers/templates/racelist.html
Normal file
22
rowers/templates/racelist.html
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<p>
|
||||||
|
<table width="100%" class="listtable shortpadded">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Date</th>
|
||||||
|
<th>Event</th>
|
||||||
|
<th>Country</th>
|
||||||
|
<th>Course</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for race in races %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ race.startdate }}</td>
|
||||||
|
<td><a href="/rowers/virtualevent/{{ race.id }}">{{ race.name }}</a></td>
|
||||||
|
<td>{{ race.course.country }}</td>
|
||||||
|
<td>{{ race.course.name }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</p>
|
||||||
@@ -5,6 +5,55 @@
|
|||||||
{% block title %}Rowsandall Virtual Racing{% endblock %}
|
{% block title %}Rowsandall Virtual Racing{% endblock %}
|
||||||
|
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
|
<script type='text/javascript'
|
||||||
|
src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'>
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
function submit_form() {
|
||||||
|
console.log("form changed");
|
||||||
|
var frm = $("#raceform");
|
||||||
|
|
||||||
|
var data = new FormData(frm[0]);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "/rowers/virtualevents",
|
||||||
|
type: "POST",
|
||||||
|
contentType: false,
|
||||||
|
processData: false,
|
||||||
|
data: data,
|
||||||
|
|
||||||
|
success: function(data) {
|
||||||
|
console.log("got something back");
|
||||||
|
console.log(data)
|
||||||
|
|
||||||
|
$('#racelist').html(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();
|
||||||
|
console.log("CSRF token",csrftoken);
|
||||||
|
|
||||||
|
function csrfSafeMethod(method) {
|
||||||
|
// these HTTP methods do not require CSRF protection
|
||||||
|
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
|
||||||
|
}
|
||||||
|
$.ajaxSetup({
|
||||||
|
beforeSend: function(xhr, settings) {
|
||||||
|
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
|
||||||
|
xhr.setRequestHeader("X-CSRFToken", csrftoken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$("#raceform").on('change', function(evt) {
|
||||||
|
submit_form();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
@@ -19,7 +68,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid_12 alpha">
|
<div class="grid_12 alpha">
|
||||||
<form enctype="multipart/form-data" method="post">
|
<form id="raceform" enctype="multipart/form-data" method="post">
|
||||||
<div class="grid_8 alpha">
|
<div class="grid_8 alpha">
|
||||||
{{ form.as_table }}
|
{{ form.as_table }}
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
@@ -30,29 +79,8 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid_12 alpha">
|
<div class="grid_12 alpha" id="racelist">
|
||||||
<p>
|
{% include 'racelist.html' %}
|
||||||
<table width="100%" class="listtable shortpadded">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Date</th>
|
|
||||||
<th>Event</th>
|
|
||||||
<th>Country</th>
|
|
||||||
<th>Course</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for race in races %}
|
|
||||||
<tr>
|
|
||||||
<td>{{ race.startdate }}</td>
|
|
||||||
<td><a href="/rowers/virtualevent/{{ race.id }}">{{ race.name }}</a></td>
|
|
||||||
<td>{{ race.course.country }}</td>
|
|
||||||
<td>{{ race.course.name }}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13317,13 +13317,17 @@ def plannedsession_deleteconfirm_view(request,id=0):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def virtualevents_view(request):
|
def virtualevents_view(request):
|
||||||
|
is_ajax = False
|
||||||
|
if request.is_ajax():
|
||||||
|
is_ajax = True
|
||||||
|
|
||||||
# default races
|
# default races
|
||||||
races = VirtualRace.objects.filter(
|
races = VirtualRace.objects.filter(
|
||||||
startdate__gte=datetime.date.today()
|
startdate__gte=datetime.date.today()
|
||||||
).order_by("startdate","start_time")
|
).order_by("startdate","start_time")
|
||||||
|
|
||||||
r = getrower(request.user)
|
if not request.user.is_anonymous():
|
||||||
|
r = getrower(request.user)
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
# process form
|
# process form
|
||||||
@@ -13367,11 +13371,15 @@ def virtualevents_view(request):
|
|||||||
|
|
||||||
form = VirtualRaceSelectForm()
|
form = VirtualRaceSelectForm()
|
||||||
|
|
||||||
|
if is_ajax:
|
||||||
|
return render(request,'racelist.html',
|
||||||
|
{ 'races':races,
|
||||||
|
})
|
||||||
|
|
||||||
return render(request,'virtualevents.html',
|
return render(request,'virtualevents.html',
|
||||||
{ 'races':races,
|
{ 'races':races,
|
||||||
'form':form,
|
'form':form,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
def virtualevent_view(request,id=0):
|
def virtualevent_view(request,id=0):
|
||||||
@@ -13417,7 +13425,7 @@ def virtualevent_view(request,id=0):
|
|||||||
race=race,
|
race=race,
|
||||||
workoutid__isnull=True,
|
workoutid__isnull=True,
|
||||||
)
|
)
|
||||||
print dns[0].username,"noot"
|
|
||||||
|
|
||||||
|
|
||||||
records = VirtualRaceResult.objects.filter(
|
records = VirtualRaceResult.objects.filter(
|
||||||
|
|||||||
Reference in New Issue
Block a user