~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to images/views.py

  • Committer: Holger Rapp
  • Date: 2009-03-01 20:47:48 UTC
  • Revision ID: sirver@kallisto.local-20090301204748-h3ouqkp8zhv10ydq
First (working) commit of wlimages app, the app that will handle image uploading and managing. Uploading works now; images can only be uploaded once (with the same filename). Much stil missing. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from django.shortcuts import get_object_or_404
2
 
from django.http import HttpResponse
3
 
 
4
 
from models import Image
5
 
from settings import MEDIA_ROOT
6
 
 
7
 
def display( request, image, revision ):
8
 
    print "revision:", revision
9
 
    print "image:", image
10
 
 
11
 
    
12
 
    revision = int(revision)
13
 
 
14
 
    img = get_object_or_404( Image, name = image, revision = revision )
15
 
    
16
 
    extension = img.image.path[-3:].lower()
17
 
    if extension not in ("png","gif","jpg","bmp"):
18
 
        extension = "png"
19
 
 
20
 
    r = HttpResponse()
21
 
    r['Content-Type'] = 'image/%s' % extension
22
 
    r.write(img.image.read())
23
 
 
24
 
    return r
25
 
 
26