diff --git a/dbfilestorage/storage.py b/dbfilestorage/storage.py index ab95411..16669dd 100644 --- a/dbfilestorage/storage.py +++ b/dbfilestorage/storage.py @@ -4,6 +4,7 @@ import hashlib import os from django.db.transaction import atomic +from django.db.models import Q from django.core.files.base import ContentFile from django.core.files.storage import Storage from django.core.urlresolvers import reverse @@ -13,6 +14,10 @@ from .models import DBFile L = logging.getLogger(__name__) +def _get_object(param): + return DBFile.objects.filter(Q(name=param)|Q(filehash=param)).first() + + class DBFileStorage(Storage): """ This is the Test Database file upload storage backend. @@ -67,7 +72,8 @@ class DBFileStorage(Storage): return name def path(self, name): - return name + dbf = _get_object(name) + return dbf.name def delete(self, name): assert name, "The name argument is not allowed to be empty." diff --git a/tests/tests.py b/tests/tests.py index 0b00f22..89386dd 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -75,10 +75,10 @@ class DBFileTest(TestCase): default_storage.delete("Nothing") def test_path(self): - """ Test the path is just the md5 name """ + """ Test the path is just the filename, when passed md5 and name """ path = default_storage.path(self.md5) - self.assertEqual(self.md5, path) - self.assertNotIn(self.filename, path) + self.assertNotEqual(self.md5, path) + self.assertEqual(self.filename, path) def test_size(self): """ Ensure we can get the proper size """