Source

django-profiles / profiles / models.py

The default branch has multiple heads

# -*- Mode: python; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*-

from django.db import models
from django.contrib.auth.models import User
from django.conf import settings

try:

  from imagekit.models import ImageSpec
  from imagekit.processors import *
  from imagekit.processors.crop import *
  from imagekit.processors.resize import *

  PROFILE_PHOTO_BIG = [Transpose(Transpose.AUTO), Crop(width=128, height=128, anchor=Anchor.CENTER)]
  PROFILE_PHOTO_MEDIUM = [Transpose(Transpose.AUTO), Crop(width=64, height=64, anchor=Anchor.CENTER)]
  PROFILE_PHOTO_SMALL = [Transpose(Transpose.AUTO), Crop(width=32, height=32, anchor=Anchor.CENTER)]

  class PhotoProfile(models.Model):
    class Meta:
      abstract = True

    user = models.OneToOneField(User)

    profile_photo = models.ImageField(upload_to=getattr(settings, 'PROFILE_PHOTO_DIRECTORY', 'profile'), blank=True)
    profile_photo_big = ImageSpec(getattr(settings, 'PROFILE_PHOTO_BIG', PROFILE_PHOTO_BIG), image_field='profile_photo', options={'quality': 90})
    profile_photo_medium = ImageSpec(getattr(settings, 'PROFILE_PHOTO_MEDIUM', PROFILE_PHOTO_MEDIUM), image_field='profile_photo', options={'quality': 90})
    profile_photo_small = ImageSpec(getattr(settings, 'PROFILE_PHOTO_SMALL', PROFILE_PHOTO_SMALL), image_field='profile_photo', options={'quality': 90})

except ImportError, e: 
  print e