-
-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/einvalentin/sorl-thumbnail …
…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
Showing
4 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters