diff --git a/events/models/profiles.py b/events/models/profiles.py index dee5a85..993095d 100644 --- a/events/models/profiles.py +++ b/events/models/profiles.py @@ -2,6 +2,10 @@ from django.db import models from django.contrib.sites.models import Site from django.contrib.auth.models import User, Group, AnonymousUser from django.utils.translation import ugettext_lazy as _ +from django.conf import settings + +from imagekit.models import ProcessedImageField +from imagekit.processors import ResizeToFill from .locale import * @@ -15,7 +19,10 @@ class UserProfile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) realname = models.CharField(verbose_name=_("Real Name"), max_length=150, blank=True) tz = models.CharField(max_length=32, verbose_name=_('Timezone'), default='UTC', choices=[(tz, tz) for tz in pytz.all_timezones], blank=False, null=False) - avatar = models.URLField(verbose_name=_("Photo Image"), max_length=150, blank=True, null=True) + avatar = ProcessedImageField(verbose_name=_("Photo Image"), + upload_to='avatars', + processors=[ResizeToFill(128, 128)], + format='PNG') web_url = models.URLField(verbose_name=_('Website URL'), blank=True, null=True) twitter = models.CharField(verbose_name=_('Twitter Name'), max_length=32, blank=True, null=True) @@ -37,6 +44,12 @@ class UserProfile(models.Model): except: return "Unknown Profile" + def avatar_url(self): + if self.avatar.url.startswith('http'): + return self.avatar.url + else: + return settings.MEDIA_URL + '/' + self.avatar.url + def get_timezone(self): try: return pytz.timezone(self.tz) diff --git a/get_together/settings.py b/get_together/settings.py index 232f771..8d6f090 100644 --- a/get_together/settings.py +++ b/get_together/settings.py @@ -43,6 +43,8 @@ INSTALLED_APPS = [ 'django.contrib.sites', 'rest_framework', 'social_django', + 'imagekit', + 'imagekit_cropper', 'get_together', 'events', @@ -180,3 +182,5 @@ try: except: print("WARNING: You should create a local_settings.py to store local and secret data.") +MEDIA_ROOT = './media/' +MEDIA_URL = '/media/' diff --git a/get_together/templates/get_together/base.html b/get_together/templates/get_together/base.html index 6dae17c..fd9a889 100644 --- a/get_together/templates/get_together/base.html +++ b/get_together/templates/get_together/base.html @@ -72,7 +72,7 @@ form { {% if request.user.is_authenticated %}