@treeio_login_required
def attachment_download(request, attachment_id):
    try:
        attachment = Attachment.objects.get(pk=attachment_id)
    except Attachment.DoesNotExist:
        raise Http404()

    filepath = join(
        getattr(settings, 'MEDIA_ROOT'), 'attachments', attachment.attached_file.name)
    try:
        data = open(filepath).read()
    except __HOLE__:
        raise Http404()

    response = HttpResponse(data, content_type=attachment.mimetype)
    response[
        'Content-Disposition'] = 'filename="%s"' % smart_unicode(attachment.filename)
    return response
dataset/ETHPy150Open treeio/treeio/treeio/core/views.py/attachment_download