Allow filename to stay. dont hash the name, this will honor the upload_to (#31)
* Allow filename to stay. dont hash the name, this will honor the upload_to setting * Version bump and changelog
This commit is contained in:
parent
1561754feb
commit
6df5f1c674
|
@ -54,6 +54,7 @@ I will sign everything with 0x769A1BC78A2DDEE2
|
||||||
|
|
||||||
## CHANGELOG
|
## CHANGELOG
|
||||||
|
|
||||||
|
- 2017-01-25 [Tyrel Souza] Keeping Filename on upload.
|
||||||
- 2017-01-23 [Tyrel Souza] Add Modified Time to storage support
|
- 2017-01-23 [Tyrel Souza] Add Modified Time to storage support
|
||||||
- 2017-01-23 [Tyrel Souza] Everything should return a "filename" even if it's generated. Make the filename be the hash + ext. (fall back to .txt)
|
- 2017-01-23 [Tyrel Souza] Everything should return a "filename" even if it's generated. Make the filename be the hash + ext. (fall back to .txt)
|
||||||
- 2017-01-20 [Tyrel Souza] Make path return None if no file
|
- 2017-01-20 [Tyrel Souza] Make path return None if no file
|
||||||
|
|
|
@ -61,7 +61,6 @@ class DBFileStorage(Storage):
|
||||||
file_ext = os.path.splitext(name)[1]
|
file_ext = os.path.splitext(name)[1]
|
||||||
if not file_ext:
|
if not file_ext:
|
||||||
file_ext = ".txt"
|
file_ext = ".txt"
|
||||||
name = "".join((filehash, file_ext))
|
|
||||||
|
|
||||||
# create the file, or just return name if the exact file already exists
|
# create the file, or just return name if the exact file already exists
|
||||||
if not DBFile.objects.filter(pk=filehash).exists():
|
if not DBFile.objects.filter(pk=filehash).exists():
|
||||||
|
|
|
@ -54,9 +54,9 @@ author = u'Tyrel Souza'
|
||||||
# built documents.
|
# built documents.
|
||||||
#
|
#
|
||||||
# The short X.Y version.
|
# The short X.Y version.
|
||||||
version = u'0.5.0'
|
version = u'0.5.1'
|
||||||
# The full version, including alpha/beta/rc tags.
|
# The full version, including alpha/beta/rc tags.
|
||||||
release = u'0.5.0'
|
release = u'0.5.1'
|
||||||
|
|
||||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||||
# for a list of supported languages.
|
# for a list of supported languages.
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -24,7 +24,7 @@ class CleanCommand(Command):
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="django-dbfilestorage",
|
name="django-dbfilestorage",
|
||||||
version="0.5.0",
|
version="0.5.1",
|
||||||
description="Database backed file storage for testing.",
|
description="Database backed file storage for testing.",
|
||||||
long_description="Database backed file storage for testing. Stores files as base64 encoded textfields.",
|
long_description="Database backed file storage for testing. Stores files as base64 encoded textfields.",
|
||||||
author="Tyrel Souza",
|
author="Tyrel Souza",
|
||||||
|
|
|
@ -22,7 +22,6 @@ class DBFileTest(TestCase):
|
||||||
self.filename = "kris.jpg"
|
self.filename = "kris.jpg"
|
||||||
self.filepath = os.path.join(PROJECT_ROOT, "test_files", self.filename)
|
self.filepath = os.path.join(PROJECT_ROOT, "test_files", self.filename)
|
||||||
self.md5 = hashlib.md5(open(self.filepath, 'rb').read()).hexdigest()
|
self.md5 = hashlib.md5(open(self.filepath, 'rb').read()).hexdigest()
|
||||||
self.filehash_ext = self.md5 + ".jpg"
|
|
||||||
|
|
||||||
self._upload()
|
self._upload()
|
||||||
|
|
||||||
|
@ -47,7 +46,7 @@ class DBFileTest(TestCase):
|
||||||
""" Test that it won't make a new file if it already exists """
|
""" Test that it won't make a new file if it already exists """
|
||||||
# uploads once in setup already
|
# uploads once in setup already
|
||||||
name2 = self._upload()
|
name2 = self._upload()
|
||||||
self.assertEqual(self.filehash_ext, name2)
|
self.assertEqual(self.filepath, name2)
|
||||||
|
|
||||||
def test_equality(self):
|
def test_equality(self):
|
||||||
""" Test that the DB entry matches what is expected from the file """
|
""" Test that the DB entry matches what is expected from the file """
|
||||||
|
@ -83,12 +82,12 @@ class DBFileTest(TestCase):
|
||||||
|
|
||||||
def test_url(self):
|
def test_url(self):
|
||||||
""" Test that the url returned is the md5 path not the filename """
|
""" Test that the url returned is the md5 path not the filename """
|
||||||
self.assertIn(self.md5, default_storage.url(self.md5))
|
self.assertIn(self.filename, default_storage.url(self.md5))
|
||||||
|
|
||||||
def test_view(self):
|
def test_view(self):
|
||||||
client = Client()
|
client = Client()
|
||||||
# check it works for both md5 and filename
|
# check it works for both md5 and filename
|
||||||
for param in (self.md5, self.filehash_ext):
|
for param in (self.md5, self.filepath):
|
||||||
url = default_storage.url(param)
|
url = default_storage.url(param)
|
||||||
resp = client.get(url)
|
resp = client.get(url)
|
||||||
self.assertEqual(resp.status_code, 200)
|
self.assertEqual(resp.status_code, 200)
|
||||||
|
@ -112,5 +111,5 @@ class DBFileTest(TestCase):
|
||||||
|
|
||||||
def test_mtime(self):
|
def test_mtime(self):
|
||||||
""" Ensure we can get the modified time """
|
""" Ensure we can get the modified time """
|
||||||
mtime = default_storage.modified_time(self.filehash_ext)
|
mtime = default_storage.modified_time(self.filepath)
|
||||||
self.assertIsNotNone(mtime)
|
self.assertIsNotNone(mtime)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user