Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/einvalentin/sorl-thumbnail
Browse files Browse the repository at this point in the history
…into einvalentin-master

* 'master' of https://github.com/einvalentin/sorl-thumbnail:
  codestyle -> pep8
  overwriting on save() to make sure there are no problems with the expects() call
  added dynamodb backend for AWS deployments without redis

Conflicts:
	tox.ini
  • Loading branch information
mariocesar committed Jan 18, 2016
2 parents 0050a1c + e9983a3 commit 43098cb
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ The PRIMARY AUTHORS are (and/or have been):
* Mikko Hellsing
* M. César Señoranis
* Rolf Erik Lekang
* Frankie Robertson
* Frankie Robertson
* Valentin v. Seggern (Support for AWS Dynamo DB)
38 changes: 38 additions & 0 deletions sorl/thumbnail/kvstores/dynamodb_kvstore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from __future__ import unicode_literals

from boto.dynamodb2.table import Table
import boto
from sorl.thumbnail.kvstores.base import KVStoreBase
from sorl.thumbnail.conf import settings


class KVStore(KVStoreBase):
def __init__(self):
super(KVStore, self).__init__()
region = settings.AWS_REGION_NAME
access_key = settings.AWS_ACCESS_KEY_ID
secret = settings.AWS_SECRET_ACCESS_KEY
conn = boto.dynamodb2.connect_to_region(region, aws_access_key_id=access_key,
aws_secret_access_key=secret)
self.table = Table(settings.THUMBNAIL_DYNAMODB_NAME, connection=conn)

def _get_raw(self, key):
try:
return self.table.get_item(key=key)['value']
except boto.dynamodb2.exceptions.ItemNotFound:
pass

def _set_raw(self, key, value):
try:
item = self.table.get_item(key=key)
except boto.dynamodb2.exceptions.ItemNotFound:
item = self.table.new_item()
item['key'] = key
item['value'] = value
item.save(overwrite=True)

def _delete_raw(self, *keys):
[self.table.delete_item(key=k) for k in keys]

def _find_keys_raw(self, prefix):
return [i['key'] for i in self.table.scan(key__beginswith=prefix)]
8 changes: 8 additions & 0 deletions tests/settings/dynamodb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .default import *


THUMBNAIL_KVSTORE = 'sorl.thumbnail.kvstores.dynamodb_kvstore.KVStore'
THUMBNAIL_DYNAMODB_NAME = 'test'
AWS_REGION_NAME = 'eu-central-1'
AWS_ACCESS_KEY_ID = 'use'
AWS_SECRET_ACCESS_KEY = 'yours'
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ django_find_project = false
skipsdist = True
envlist =
{py27}-django14-{pil,imagemagick,graphicsmagick,redis,wand,pgmagick,dbm},
{py27,py34}-django{15,16,17,18,19}-{pil,imagemagick,graphicsmagick,redis,wand,pgmagick,dbm}
{py27,py34}-django{15,16,17,18,19}-{pil,imagemagick,graphicsmagick,redis,dynamodb,wand,pgmagick,dbm}

[testenv]
changedir = {toxinidir}/tests
Expand All @@ -20,6 +20,7 @@ deps =
pytest-django
Pillow
redis: redis
dynamodb: boto
pgmagick: pgmagick
wand: wand
django14: Django>=1.4,<1.5
Expand All @@ -35,6 +36,7 @@ setenv =
imagemagick: DJANGO_SETTINGS_MODULE=tests.settings.imagemagick
graphicsmagick: DJANGO_SETTINGS_MODULE=tests.settings.graphicsmagick
redis: DJANGO_SETTINGS_MODULE=tests.settings.redis
dynamodb: DJANGO_SETTINGS_MODULE=tests.settings.dynamodb
wand: DJANGO_SETTINGS_MODULE=tests.settings.wand
pgmagick: DJANGO_SETTINGS_MODULE=tests.settings.pgmagick
dbm: DJANGO_SETTINGS_MODULE=tests.settings.dbm
Expand Down

0 comments on commit 43098cb

Please sign in to comment.