@login_required
def upload(request):
    """
    Upload images for embedding in articles.
    """
    js = 'js' in request.GET
    if request.method == 'POST':
        form = ImageUploadForm(data=request.POST, files=request.FILES)
        if form.is_valid():
            image = form.save()
            if js:
                return HttpResponse('<script>window.opener.editor.insertImage("[image:%d]");window.close();</script>' % image.id)
            else:
                return redirect(image)
    else:
        form = ImageUploadForm()
    return render(request, 'images/upload.html', {
        'title': 'Upload',
        'form': form,
        'description': "Use this form to upload an image.",
        'action': 'Upload',
        'js': js,
    })
dataset/ETHPy150Open 2buntu/2buntu-blog/twobuntu/images/views.py/upload/original