diff --git a/README.md b/README.md index 48631fc..c959c3e 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ I will sign everything with 0x769A1BC78A2DDEE2 ## CHANGELOG +- 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-20 [Tyrel Souza] Make path return None if no file - 2017-01-20 [Tyrel Souza] Make path return filename diff --git a/dbfilestorage/migrations/0004_dbfile_mtime.py b/dbfilestorage/migrations/0004_dbfile_mtime.py new file mode 100644 index 0000000..a870123 --- /dev/null +++ b/dbfilestorage/migrations/0004_dbfile_mtime.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2017-01-23 20:34 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dbfilestorage', '0003_auto_remove_serialize'), + ] + + operations = [ + migrations.AddField( + model_name='dbfile', + name='mtime', + field=models.DateTimeField(auto_now=True), + ), + ] diff --git a/dbfilestorage/models.py b/dbfilestorage/models.py index 600a66d..82d5bc6 100644 --- a/dbfilestorage/models.py +++ b/dbfilestorage/models.py @@ -13,6 +13,7 @@ class DBFile(models.Model): # file data content_type = models.CharField(max_length=100) b64 = models.TextField() + mtime = models.DateTimeField(auto_now=True) def __unicode__(self): return u"{filehash} <{content_type}>".format( diff --git a/dbfilestorage/storage.py b/dbfilestorage/storage.py index 8814761..5e6e618 100644 --- a/dbfilestorage/storage.py +++ b/dbfilestorage/storage.py @@ -93,3 +93,8 @@ class DBFileStorage(Storage): dbf = _get_object(name) if dbf: return reverse('dbstorage_file', args=(dbf.name,)) + return reverse('dbstorage_file', args=(name,)) + + def modified_time(self, name): + dbf = _get_object(name) + return dbf.mtime diff --git a/docs/conf.py b/docs/conf.py index fcd56c5..871c0f0 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -54,9 +54,9 @@ author = u'Tyrel Souza' # built documents. # # The short X.Y version. -version = u'0.4.2' +version = u'0.5.0' # The full version, including alpha/beta/rc tags. -release = u'0.4.2' +release = u'0.5.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/setup.py b/setup.py index 6a7158c..bcc7fde 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ class CleanCommand(Command): setup( name="django-dbfilestorage", - version="0.4.2", + version="0.5.0", description="Database backed file storage for testing.", long_description="Database backed file storage for testing. Stores files as base64 encoded textfields.", author="Tyrel Souza", diff --git a/tests/tests.py b/tests/tests.py index 85e032e..d77c79c 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -99,7 +99,6 @@ class DBFileTest(TestCase): resp = client.get(url) self.assertEqual(resp.status_code, 404) - def test_admin(self): my_admin = User.objects.create_superuser( username='tester', @@ -110,3 +109,8 @@ class DBFileTest(TestCase): url = reverse("admin:dbfilestorage_dbfile_changelist") resp = client.get(url) self.assertContains(resp, self.md5) + + def test_mtime(self): + """ Ensure we can get the modified time """ + mtime = default_storage.modified_time(self.filehash_ext) + self.assertIsNotNone(mtime)