~widelands-dev/widelands-website/css-table

« back to all changes in this revision

Viewing changes to wlmaps/views.py

  • Committer: Holger Rapp
  • Date: 2013-08-09 23:13:44 UTC
  • mfrom: (363.1.1 trunk)
  • Revision ID: sirver@widelands.org-20130809231344-741j95p37d4hom9y
Various fixes to the map uploading process by shevonar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
    """
61
61
    m = get_object_or_404( models.Map, slug = map_slug )
62
62
 
63
 
    file = open(m.file.path,"rb")
 
63
    file = open(m.file.path, "rb")
64
64
    data = file.read()
65
 
 
66
 
    # We have to find the correct filename, widelands is quite
67
 
    # buggy. The Filename must be the same as the directory
68
 
    # packed in the zip.
69
 
    file.seek(0)
70
 
    zf = zipfile.ZipFile(file)
71
 
    probable_filenames = filter( len, [ i.filename.split('/')[0] for i in zf.filelist ])
72
 
    if not len(probable_filenames):
73
 
        probable_filename = os.path.basename("%s.wmf" % m.name)
74
 
    else:
75
 
        probable_filename = probable_filenames[0]
 
65
    filename = os.path.basename("%s.wmf" % m.name)
76
66
 
77
67
    # Remember that this has been downloaded
78
68
    m.nr_downloads += 1
79
69
    m.save()
80
70
 
81
71
    response =  HttpResponse( data, mimetype = "application/octet-stream")
82
 
    response['Content-Disposition'] = 'attachment; filename="%s"' % probable_filename
 
72
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
83
73
 
84
74
    return response
85
75