add in stdimage to scale the images

This commit is contained in:
Oliver Marks 2017-01-07 21:52:03 +00:00
parent a6ba1f984b
commit 0a2ad28b7c
6 changed files with 32 additions and 6 deletions

View File

@ -28,6 +28,7 @@ DJANGO_APPS = (
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'stdimage',
# Useful template tags:
# 'django.contrib.humanize',

View File

@ -35,12 +35,26 @@ EMAIL_HOST = env("EMAIL_HOST", default='mailhog')
# CACHING
# ------------------------------------------------------------------------------
REDIS_LOCATION = '{0}/{1}'.format(env('REDIS_URL', default='redis://redis:6379'), 0)
# Heroku URL does not pass the DB number, so we parse it in
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': ''
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': REDIS_LOCATION,
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
'IGNORE_EXCEPTIONS': True, # mimics memcache behavior.
# http://niwinz.github.io/django-redis/latest/#_memcached_exceptions_behavior
}
}
}
# CACHES = {
# 'default': {
# 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
# 'LOCATION': ''
# }
# }
# django-debug-toolbar
# ------------------------------------------------------------------------------

View File

@ -26,7 +26,7 @@ services:
volumes:
- .:/app
ports:
- "8000:8000"
- "8180:8000"
links:
- postgres
- mailhog
@ -36,3 +36,5 @@ services:
ports:
- "8125:8025"
redis:
image: redis:latest

View File

@ -9,7 +9,7 @@
<h2>Profile</h2>
<div class="row">
<div class="col-md-6">
<img src="{{ MEDIA_URL }}{{ user.image }}" alt="Profile image"/>
<img src="{{ user.image.profile.url }}" alt="Profile image"/>
<p>{{ user.username }}</p>
<p>{{ user.name }}</p>

View File

@ -7,12 +7,20 @@ from django.core.urlresolvers import reverse
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from stdimage.models import StdImageField
@python_2_unicode_compatible
class User(AbstractUser):
name = models.CharField(_('Name of User'), blank=True, max_length=255)
image = models.ImageField(upload_to='avatars/', blank=True, null=True)
image = StdImageField(
upload_to='avatars/',
blank=True,
null=True,
variations={
'profile': {
"width": 256,
"height": 256,
"crop": True}})
def __str__(self):
return self.username

View File

@ -17,6 +17,7 @@ django-braces==1.10.0
django-crispy-forms==1.6.1
# Models
django-stdimage
django-model-utils==2.6
# Images