Solves #536 Image upload possible directly in Manual
This commit is contained in:
@@ -22,12 +22,12 @@ $( document ).ready(function() {
|
||||
|| $(this).val() == 'churchboat'
|
||||
) {
|
||||
$('#id_boattype').toggle(true);
|
||||
} else {
|
||||
} else {
|
||||
$('#id_boattype').toggle(false);
|
||||
$('#id_boattype').val('1x');
|
||||
$('#id_boattype').val('1x');
|
||||
}
|
||||
});
|
||||
$('#id_workouttype').change();
|
||||
$('#id_workouttype').change();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -41,13 +41,17 @@ $('#id_workouttype').change();
|
||||
Please correct the error{{ form.errors|pluralize }} below.
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<form id="importantform"
|
||||
enctype="multipart/form-data" action="" method="post">
|
||||
<table width=100%>
|
||||
{{ form.as_table }}
|
||||
{{ metricsform.as_table }}
|
||||
</table>
|
||||
Optional, add image (PM screenshot):
|
||||
<table>
|
||||
{{ iform.as_table }}
|
||||
</table>
|
||||
{% csrf_token %}
|
||||
<p>
|
||||
<input class="button green" type="submit" value="Save">
|
||||
@@ -56,7 +60,7 @@ $('#id_workouttype').change();
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
||||
@@ -665,6 +665,25 @@ def addmanual_view(request,raceid=0):
|
||||
|
||||
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:
|
||||
try:
|
||||
race = VirtualRace.objects.get(id=raceid)
|
||||
@@ -727,6 +746,7 @@ def addmanual_view(request,raceid=0):
|
||||
else:
|
||||
return render(request,'manualadd.html',
|
||||
{'form':form,
|
||||
'iform':iform,
|
||||
'metricsform':metricsform,
|
||||
'breadcrumbs':breadcrumbs,
|
||||
'active':'nav-workouts',
|
||||
@@ -742,10 +762,12 @@ def addmanual_view(request,raceid=0):
|
||||
|
||||
}
|
||||
form = WorkoutForm(initial=initial)
|
||||
iform = ImageForm()
|
||||
metricsform = MetricsForm()
|
||||
|
||||
return render(request,'manualadd.html',
|
||||
{'form':form,
|
||||
'iform':iform,
|
||||
'metricsform':metricsform,
|
||||
'breadcrumbs':breadcrumbs,
|
||||
'active':'nav-workouts',
|
||||
|
||||
Reference in New Issue
Block a user