Changeset 134 in main


Ignore:
Timestamp:
07/28/10 08:12:37 (10 years ago)
Author:
pcosquer
Message:

new download function : more simple

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/openPLM/plmapp/views.py

    r133 r134  
    721721def download(request, docfile_id): 
    722722    doc_file = models.DocumentFile.objects.get(id=docfile_id) 
    723     name = doc_file.filename.encode("utf-8", "backslashreplace").decode("ascii", "ignore") 
    724     base_dir = os.path.dirname(__file__) 
    725     rep1 = os.path.join(base_dir, "..", "docs", "%s/" % docfile_id) 
    726     rep = os.path.join("docs", "%s/" % docfile_id) 
    727     dst1 = os.path.join(rep1, name) 
    728     if not os.path.exists(rep1): 
    729         os.mkdir(rep1) 
    730     if os.path.lexists(dst1): 
    731         os.unlink(dst1) 
    732     os.symlink(doc_file.file.path, dst1) 
    733     dst = os.path.join(rep, name) 
    734     return HttpResponseRedirect("/" + dst) 
     723    name = doc_file.filename.encode("utf-8", "ignore") 
     724    mimetype = guess_type(name, False)[0] 
     725    if not mimetype: 
     726        mimetype = 'application/octet-stream' 
     727    response = HttpResponse(file(doc_file.file.path), mimetype=mimetype) 
     728    response['Content-Disposition'] = 'attachment; filename="%s"' % name 
     729    return response 
    735730     
    736731########################################################################################## 
Note: See TracChangeset for help on using the changeset viewer.