Compare commits

..

No commits in common. "e94a856a081cfe1c59e9288c96a1b5edcba3edca" and "0860f37ac02141a2fdf19923be7fda34ba25974a" have entirely different histories.

2 changed files with 5 additions and 24 deletions

View file

@ -1,24 +1,11 @@
import msgpack import msgpack
import pickle
from django_redis.serializers.base import BaseSerializer from django_redis.serializers.base import BaseSerializer
def default(obj):
# Pickle anything that MessagePack can't handle itself.
return msgpack.ExtType(69, pickle.dumps(obj, protocol=4))
def ext_hook(code, data):
# Unpickle if we pickled - otherwise do nothing.
if code == 69:
return pickle.loads(data)
return msgpack.ExtType(code, data)
class MSGPackModernSerializer(BaseSerializer): class MSGPackModernSerializer(BaseSerializer):
def dumps(self, value): def dumps(self, value):
return msgpack.packb(value, default=default, use_bin_type=True) return msgpack.packb(value, use_bin_type=True)
def loads(self, value): def loads(self, value):
return msgpack.unpackb(value, ext_hook=ext_hook, raw=False) return msgpack.unpackb(value, raw=False)

View file

@ -1,5 +1,4 @@
from django.http import HttpResponse, HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
from django.views.decorators.cache import cache_page
from PIL import Image from PIL import Image
from lemoncurry import utils from lemoncurry import utils
@ -13,7 +12,6 @@ def try_libravatar_org(hash, get):
return HttpResponseRedirect(url) return HttpResponseRedirect(url)
@cache_page(60 * 15)
def libravatar(request, hash): def libravatar(request, hash):
g = request.GET g = request.GET
size = g.get('s', g.get('size', 80)) size = g.get('s', g.get('size', 80))
@ -44,12 +42,8 @@ def libravatar(request, hash):
return try_libravatar_org(hash, g) return try_libravatar_org(hash, g)
im = Image.open(user.avatar) im = Image.open(user.avatar)
image_type = im.format im_resized = im.resize((size, size))
natural_size = min(im.size)
im = im.crop((0, 0, natural_size, natural_size)) response = HttpResponse(content_type='image/'+im.format.lower())
im = im.resize((size, size), resample=Image.HAMMING) im_resized.save(response, im.format)
response = HttpResponse(content_type='image/'+image_type.lower())
im.save(response, image_type)
return response return response