py-django-binary-database-files: updated to 1.0.14

1.0.14:
Bug fixes
This commit is contained in:
adam 2021-03-19 10:09:52 +00:00
parent 798a95eab2
commit 08b55bbee3
4 changed files with 9 additions and 123 deletions

View file

@ -1,23 +1,19 @@
# $NetBSD: Makefile,v 1.3 2020/09/11 09:40:24 adam Exp $
# $NetBSD: Makefile,v 1.4 2021/03/19 10:09:52 adam Exp $
DISTNAME= django-binary-database-files-1.0.13
DISTNAME= django-binary-database-files-1.0.14
PKGNAME= ${PYPKGPREFIX}-${DISTNAME}
PKGREVISION= 1
CATEGORIES= www python
MASTER_SITES= ${MASTER_SITE_GITHUB:=kimetrica/}
MASTER_SITES= ${MASTER_SITE_PYPI:=d/django-binary-database-files/}
MAINTAINER= pkgsrc-users@NetBSD.org
HOMEPAGE= https://github.com/kimetrica/django-binary-database-files
COMMENT= In-database file storage backend for Django
LICENSE= modified-bsd
GITHUB_PROJECT= django-binary-database-files
GITHUB_TAG= cedd9f4608eb0da343cf15cfcaf5400a0754cc28
DEPENDS+= ${PYPKGPREFIX}-django>=2.2:../../www/py-django2
TEST_DEPENDS+= ${PYPKGPREFIX}-coverage-[0-9]*:../../devel/py-coverage
USE_LANGUAGES= # none
USE_LANGUAGES= # none
PYTHON_VERSIONS_INCOMPATIBLE= 27

View file

@ -1,8 +1,6 @@
$NetBSD: distinfo,v 1.2 2020/08/19 00:29:46 joerg Exp $
$NetBSD: distinfo,v 1.3 2021/03/19 10:09:52 adam Exp $
SHA1 (django-binary-database-files-1.0.13-cedd9f4608eb0da343cf15cfcaf5400a0754cc28.tar.gz) = 74c359eff5cd2039a9bc2badf7f4de581439c4ad
RMD160 (django-binary-database-files-1.0.13-cedd9f4608eb0da343cf15cfcaf5400a0754cc28.tar.gz) = 880660c927751ba1cb0def0b97f3b10915a8f893
SHA512 (django-binary-database-files-1.0.13-cedd9f4608eb0da343cf15cfcaf5400a0754cc28.tar.gz) = a275dc6763f98baf1170c0e160e3b9f2c515af7ee1bfb1229d0106c634c9a77af3b399d8cac781692fad56355f83cc260fd7a22f610600dcd1bbaebd3ce11598
Size (django-binary-database-files-1.0.13-cedd9f4608eb0da343cf15cfcaf5400a0754cc28.tar.gz) = 31835 bytes
SHA1 (patch-binary__database__files_storage.py) = 76eed8510370dd17bddc671b13251581db556181
SHA1 (patch-binary__database__files_tests_tests.py) = d578a3cbdfb53f8547f689c9e761113abc795fc3
SHA1 (django-binary-database-files-1.0.14.tar.gz) = 3ddd06b8228b0f4ed95befd57c7734ef911c8789
RMD160 (django-binary-database-files-1.0.14.tar.gz) = 9f2b4a94d696f3076eabefc83cf58caff35b7892
SHA512 (django-binary-database-files-1.0.14.tar.gz) = a78baaf3a337e1c14710ccb5b652e887d6969f5541ca99fe5bf14794dbe590422640a48218598156236034a563c9238753b8475798d76fb035a51c58b57ce06e
Size (django-binary-database-files-1.0.14.tar.gz) = 34576 bytes

View file

@ -1,73 +0,0 @@
$NetBSD: patch-binary__database__files_storage.py,v 1.2 2020/08/19 00:29:46 joerg Exp $
1df96f9f7caf621c4c0d94bc09b27584e1c5aa9d
73cd278717a4dd9020979d6d08eb56365a728357
--- binary_database_files/storage.py.orig 2020-08-10 14:31:32.000000000 +0000
+++ binary_database_files/storage.py
@@ -12,6 +12,11 @@ from binary_database_files import utils
from binary_database_files import settings as _settings
+class DatabaseFile(files.File):
+ def close(self):
+ pass
+
+
class DatabaseStorage(FileSystemStorage):
"""Subclass of FileSystemStorage that implements the necessary methods to use the database for files."""
@@ -63,7 +68,7 @@ class DatabaseStorage(FileSystemStorage)
fh.name = name
fh.mode = mode
fh.size = size
- o = files.File(fh)
+ o = DatabaseFile(fh)
return o
def _save(self, name, content):
@@ -109,21 +109,31 @@ class DatabaseStorage(FileSystemStorage):
full_path = safe_join(self.location, name)
return full_path[len(root_path) + 1 :]
+ def _path(self, instance_name):
+ return safe_join(settings.MEDIA_ROOT, instance_name)
+
def path(self, name):
"""
Return a local filesystem path where the file can be retrieved using
Python's built-in open() function.
File names are normalized to the MEDIA_ROOT.
+
+ If the file has not been saved to disk, a NotImplementedError will
+ be raised.
"""
- return safe_join(settings.MEDIA_ROOT, self.get_instance_name(name))
+ localpath = self._path(self.get_instance_name(name))
+ if not os.path.exists(localpath):
+ raise NotImplementedError
+ return localpath
def exists(self, name):
"""Return True if a file with the given filename exists in the database. Return False otherwise."""
name = self.get_instance_name(name)
if models.File.objects.filter(name=name).exists():
return True
- return super(DatabaseStorage, self).exists(name)
+ localpath = self._path(name)
+ return os.path.exists(localpath)
def delete(self, name):
"""Delete the file with filename `name` from the database and filesystem."""
@@ -135,7 +145,9 @@ class DatabaseStorage(FileSystemStorage):
os.remove(hash_fn)
except models.File.DoesNotExist:
pass
- return super(DatabaseStorage, self).delete(name)
+ localpath = self._path(name)
+ if os.path.exists(localpath):
+ return super(DatabaseStorage, self).delete(name)
def url(self, name):
"""Return the web-accessible URL for the file with filename `name`.

View file

@ -1,35 +0,0 @@
$NetBSD: patch-binary__database__files_tests_tests.py,v 1.1 2020/08/18 14:27:16 joerg Exp $
1df96f9f7caf621c4c0d94bc09b27584e1c5aa9d
--- binary_database_files/tests/tests.py.orig 2020-08-10 14:31:32.000000000 +0000
+++ binary_database_files/tests/tests.py
@@ -313,12 +313,7 @@ class DatabaseFilesTestCase(TestCase):
self.assertTrue(t1.upload.storage.exists(t1.upload.name))
os.remove(t1.upload.path)
self.assertTrue(t1.upload.storage.exists(t1.upload.name))
- self.assertEqual(
- t1.upload.path, os.path.join(t1.upload.storage.location, "dummy.txt")
- )
- self.assertEqual(
- t1.upload.path, Location1Thing.objects.get(pk=t1.pk).upload.path
- )
+ self.assertRaises(NotImplementedError, lambda t1: t1.upload.path, t1)
data2 = b"22222222"
open(os.path.join(tmpdir, "dummy.txt"), "wb").write(data2)
t2 = Location2Thing.objects.create(
@@ -326,13 +321,7 @@ class DatabaseFilesTestCase(TestCase):
)
os.remove(t2.upload.path)
self.assertTrue(t2.upload.storage.exists(t2.upload.name))
- self.assertEqual(
- t2.upload.path, os.path.join(t2.upload.storage.location, "dummy.txt")
- )
- self.assertEqual(
- t2.upload.path, Location2Thing.objects.get(pk=t2.pk).upload.path
- )
-
+ self.assertRaises(NotImplementedError, lambda t2: t2.upload.path, t2)
self.assertEqual(File.objects.count(), 2)
self.assertEqual(Location2Thing.objects.get(pk=t2.pk).upload.file.read(), data2)
self.assertEqual(Location1Thing.objects.get(pk=t1.pk).upload.file.read(), data1)