Commit 7fbba5d0 authored by Gijs Hendriksen's avatar Gijs Hendriksen
Browse files

Resize profile images on upload

parent dc9cf187
......@@ -17,6 +17,8 @@ from activemembers.models import Committee
from utils.snippets import datetime_to_lectureyear
from utils.validators import validate_file_extension
from PIL import Image
class ActiveMemberManager(models.Manager):
"""Get all active members"""
......@@ -373,6 +375,13 @@ class Member(models.Model):
def get_absolute_url(self):
return reverse('members:profile', args=[str(])
def __init__(self, *args, **kwargs):
super(Member, self).__init__(*args, **kwargs)
self._orig_image =
self._orig_image = ""
def clean(self):
errors = {}
......@@ -384,6 +393,16 @@ class Member(models.Model):
'display name')})
raise ValidationError(errors)
def save(self, *args, **kwargs):
super(Member, self).save(args, kwargs)
if and self._orig_image !=
image_path =
image =
# Image.thumbnail does not upscale an image that is smaller
image.thumbnail(settings.PHOTO_UPLOAD_SIZE, Image.ANTIALIAS), "JPEG")
self._orig_image =
def __str__(self):
return '{} ({})'.format(self.get_full_name(), self.user.username)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment