Пример #1
0
def download_jsonp(request,data_id):
    '''
    Helper to download a file as JSONP (for use in a <SCRIPT></SCRIPT> block for mapping)
    Might want a different response if there is no data to format (e.g. just return text "{}")
    '''
    contents = addPadding(use_api.getDatafileContents(data_id,format="json"))
    if contents["data"]:
        return HttpResponse(contents["data"])
    else:
        return HttpResponse("{}")
Пример #2
0
def download_file(request,data_id):
    '''
    Download a file
    '''
    contents = use_api.getDatafileContents(data_id,format="json")
    if contents["data"]:
        response = HttpResponse(contents["data"],mimetype=contents["type"])
        response['Content-Disposition'] = 'attachment; filename='+contents["name"]
        return response
    else:
        return HttpResponseRedirect(reverse('dashboard'))