def save_model(self, request, obj, form, change): if 'pic' in request.FILES: pic = request.FILES['pic'] picname = format_filename(pic.name, obj.date) picpath = "edito/%s" % picname imgobj = ImageFile(name=picpath, blob=pic.read()) imgobj.put() obj.picname = picpath obj.save() if not obj.numid: obj.numid = obj.key().id() obj.save()
def save_model(self, request, obj, form, change): if 'pic' in request.FILES: pic = request.FILES['pic'] blob = pic.read() obj.picname = format_filename(pic.name, obj.date) if obj.haslargepic: largepath = "event/large/%s" % obj.picname largeobj = ImageFile(name=largepath, blob=blob) largeobj.put() thumb = images.Image(blob) if thumb.width > 200: thumb.resize(width=200) blob = thumb.execute_transforms() thumbpath = "event/thumb/%s" % obj.picname thumbobj = ImageFile(name=thumbpath, blob=blob) thumbobj.put() obj.save() if not obj.numid: obj.numid = obj.key().id() obj.save() if obj.date <= datetime.now().date(): msg = Message( user=request.user, message="WARNING: date for %s is today or older! Please make sure the date is ok." % obj.title) msg.save()
def image(request, name): mime = mimetypes.guess_type(name)[0] bfiles = ImageFile.gql("WHERE name = :1", name).fetch(1) response = HttpResponse(bfiles[0].blob, mimetype=mime) response['Last-Modified'] = defaultdate.strftime("%a, %d %b %Y %H:%M:%S GMT") return response