Solves #536 Image upload possible directly in Manual
This commit is contained in:
@@ -22,12 +22,12 @@ $( document ).ready(function() {
|
|||||||
|| $(this).val() == 'churchboat'
|
|| $(this).val() == 'churchboat'
|
||||||
) {
|
) {
|
||||||
$('#id_boattype').toggle(true);
|
$('#id_boattype').toggle(true);
|
||||||
} else {
|
} else {
|
||||||
$('#id_boattype').toggle(false);
|
$('#id_boattype').toggle(false);
|
||||||
$('#id_boattype').val('1x');
|
$('#id_boattype').val('1x');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('#id_workouttype').change();
|
$('#id_workouttype').change();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -41,13 +41,17 @@ $('#id_workouttype').change();
|
|||||||
Please correct the error{{ form.errors|pluralize }} below.
|
Please correct the error{{ form.errors|pluralize }} below.
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<form id="importantform"
|
<form id="importantform"
|
||||||
enctype="multipart/form-data" action="" method="post">
|
enctype="multipart/form-data" action="" method="post">
|
||||||
<table width=100%>
|
<table width=100%>
|
||||||
{{ form.as_table }}
|
{{ form.as_table }}
|
||||||
{{ metricsform.as_table }}
|
{{ metricsform.as_table }}
|
||||||
</table>
|
</table>
|
||||||
|
Optional, add image (PM screenshot):
|
||||||
|
<table>
|
||||||
|
{{ iform.as_table }}
|
||||||
|
</table>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<p>
|
<p>
|
||||||
<input class="button green" type="submit" value="Save">
|
<input class="button green" type="submit" value="Save">
|
||||||
@@ -56,7 +60,7 @@ $('#id_workouttype').change();
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
@@ -665,6 +665,25 @@ def addmanual_view(request,raceid=0):
|
|||||||
|
|
||||||
messages.info(request,'New workout created')
|
messages.info(request,'New workout created')
|
||||||
|
|
||||||
|
iform = ImageForm(request.POST,request.FILES)
|
||||||
|
if iform.is_valid():
|
||||||
|
f = iform.cleaned_data['file']
|
||||||
|
|
||||||
|
if f is not None:
|
||||||
|
filename,path_and_filename = handle_uploaded_image(f)
|
||||||
|
try:
|
||||||
|
width, height = Image.open(path_and_filename).size
|
||||||
|
except:
|
||||||
|
message = "Not a valid image"
|
||||||
|
messages.error(request,message)
|
||||||
|
os.remove(path_and_filename)
|
||||||
|
|
||||||
|
i = GraphImage(workout=w,
|
||||||
|
creationdatetime=timezone.now(),
|
||||||
|
filename = path_and_filename,
|
||||||
|
width=width,height=height)
|
||||||
|
i.save()
|
||||||
|
|
||||||
if raceid != 0:
|
if raceid != 0:
|
||||||
try:
|
try:
|
||||||
race = VirtualRace.objects.get(id=raceid)
|
race = VirtualRace.objects.get(id=raceid)
|
||||||
@@ -727,6 +746,7 @@ def addmanual_view(request,raceid=0):
|
|||||||
else:
|
else:
|
||||||
return render(request,'manualadd.html',
|
return render(request,'manualadd.html',
|
||||||
{'form':form,
|
{'form':form,
|
||||||
|
'iform':iform,
|
||||||
'metricsform':metricsform,
|
'metricsform':metricsform,
|
||||||
'breadcrumbs':breadcrumbs,
|
'breadcrumbs':breadcrumbs,
|
||||||
'active':'nav-workouts',
|
'active':'nav-workouts',
|
||||||
@@ -742,10 +762,12 @@ def addmanual_view(request,raceid=0):
|
|||||||
|
|
||||||
}
|
}
|
||||||
form = WorkoutForm(initial=initial)
|
form = WorkoutForm(initial=initial)
|
||||||
|
iform = ImageForm()
|
||||||
metricsform = MetricsForm()
|
metricsform = MetricsForm()
|
||||||
|
|
||||||
return render(request,'manualadd.html',
|
return render(request,'manualadd.html',
|
||||||
{'form':form,
|
{'form':form,
|
||||||
|
'iform':iform,
|
||||||
'metricsform':metricsform,
|
'metricsform':metricsform,
|
||||||
'breadcrumbs':breadcrumbs,
|
'breadcrumbs':breadcrumbs,
|
||||||
'active':'nav-workouts',
|
'active':'nav-workouts',
|
||||||
|
|||||||
Reference in New Issue
Block a user