Skip to content

Commit

Permalink
Improving error handling when uploading images.
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaCinquini committed Feb 10, 2015
1 parent c00fe83 commit 9a85b85
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
Binary file added cog/static/cog/img/error.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion cog/templates/cog/doc/doc_upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

<script type="text/javascript" src="{{ MEDIA_URL }}ckeditor/ckeditor.js"></script>
<script type="text/javascript">
window.parent.CKEDITOR.tools.callFunction( '{{ request.REQUEST.CKEditorFuncNum }}' , '{{ url }}' );
{% if error %}
// show the error message
alert("{{error}}");
{% endif %}
window.parent.CKEDITOR.tools.callFunction( '{{ request.REQUEST.CKEditorFuncNum }}' , '{{ url }}' );
</script>

{% endblock %}
Expand Down
6 changes: 4 additions & 2 deletions cog/views/views_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def doc_upload(request, project_short_name):
# retrieve the file URL (after it has been saved!),
# pass it on to the view for use by CKeditor
url = instance.file.url
error = ''

# create thumbnail
# NOTE: already executed automatic when browsing through django-browser
Expand All @@ -53,10 +54,11 @@ def doc_upload(request, project_short_name):

else:
print 'Form errors:%s' % form.errors
form = UploadImageForm()
error = 'The file uploaded is not a valid image'
url = "%s%s" % (settings.STATIC_URL, 'cog/img/error.jpeg')

return render_to_response('cog/doc/doc_upload.html',
{ 'title': 'File Upload', 'url':url },
{ 'title': 'File Upload', 'url':url, 'error':error },
context_instance=RequestContext(request) )

@login_required
Expand Down
Binary file added site_media/img/admin/error.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9a85b85

Please sign in to comment.