From b31357e34f90cb4298ea8a717017e286b1d853ba Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Fri, 20 Jan 2017 15:22:17 -0500 Subject: [PATCH 1/6] redo migrations --- dbfilestorage/migrations/0001_initial.py | 4 +++- .../migrations/0002_add_filehash_rename_files.py | 12 ------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/dbfilestorage/migrations/0001_initial.py b/dbfilestorage/migrations/0001_initial.py index 838d2c6..8ac6821 100644 --- a/dbfilestorage/migrations/0001_initial.py +++ b/dbfilestorage/migrations/0001_initial.py @@ -17,8 +17,10 @@ class Migration(migrations.Migration): name='DBFile', fields=[ ('name', models.CharField(max_length=100, - primary_key=True, serialize=False)), + ('filehash', models.CharField(max_length=32, + primary_key=True, + serialize=False)), ('content_type', models.CharField(max_length=100)), ('b64', models.TextField()), ], diff --git a/dbfilestorage/migrations/0002_add_filehash_rename_files.py b/dbfilestorage/migrations/0002_add_filehash_rename_files.py index 7d3666b..b0b5a82 100644 --- a/dbfilestorage/migrations/0002_add_filehash_rename_files.py +++ b/dbfilestorage/migrations/0002_add_filehash_rename_files.py @@ -27,18 +27,6 @@ class Migration(migrations.Migration): ] operations = [ - migrations.AlterField( - model_name='dbfile', - name='name', - field=models.CharField(max_length=100), - ), - migrations.AddField( - model_name='dbfile', - name='filehash', - field=models.CharField(default='filehash', max_length=32, primary_key=True, serialize=False), - preserve_default=False, - ), - migrations.RunPython(copy_filehash), migrations.RunPython(fix_filename), ] From 4ddfe8898dfd63df7a2c005db372c52961ee6800 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Fri, 20 Jan 2017 15:23:05 -0500 Subject: [PATCH 2/6] merge and new version --- docs/conf.py | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index f5ec7ca..8c58772 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.2.0' +version = u'0.3.0' # The full version, including alpha/beta/rc tags. -release = u'0.2.0' +release = u'0.3.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 abfc21b..e2ab505 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ class CleanCommand(Command): setup( name="django-dbfilestorage", - version="0.2.0", + version="0.3.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", From 430644f35f2a2e166ed6901c547398675d10f4d5 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Fri, 20 Jan 2017 15:55:54 -0500 Subject: [PATCH 3/6] remove serialize (#25) --- .../migrations/0003_auto_remove_serialize.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 dbfilestorage/migrations/0003_auto_remove_serialize.py diff --git a/dbfilestorage/migrations/0003_auto_remove_serialize.py b/dbfilestorage/migrations/0003_auto_remove_serialize.py new file mode 100644 index 0000000..c3b24c8 --- /dev/null +++ b/dbfilestorage/migrations/0003_auto_remove_serialize.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2017-01-20 20:51 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dbfilestorage', '0002_add_filehash_rename_files'), + ] + + operations = [ + migrations.AlterField( + model_name='dbfile', + name='name', + field=models.CharField(max_length=100), + ), + ] From 7c0290972224a923ab817367771bfd7b6b445254 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Fri, 20 Jan 2017 15:56:54 -0500 Subject: [PATCH 4/6] bump Version and add more readme --- README.md | 1 + docs/conf.py | 4 ++-- setup.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0d6b062..30c125d 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ I will sign everything with 0x769A1BC78A2DDEE2 ## CHANGELOG +- 2017-01-20 [Tyrel Souza] Add another migration, and redo all the initial migrations. - 2017-01-20 [Tyrel Souza] Make sure migrations is actually there. - 2017-01-20 [Tyrel Souza] Split filename and filehash. - 2016-12-09 [Tyrel Souza] Add signing key to readme. diff --git a/docs/conf.py b/docs/conf.py index 8c58772..73bfe2e 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.3.0' +version = u'0.4.0' # The full version, including alpha/beta/rc tags. -release = u'0.3.0' +release = u'0.4.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 e2ab505..e7a494f 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ class CleanCommand(Command): setup( name="django-dbfilestorage", - version="0.3.0", + version="0.4.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", From 4820136284e91505c52d2dbc7eb1956a88a5de49 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Fri, 20 Jan 2017 16:22:59 -0500 Subject: [PATCH 5/6] Path returns filename (#27) --- dbfilestorage/storage.py | 8 +++++++- tests/tests.py | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) 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 """ From f1e66ad828fb6a9a2e842a527290390fd09d544d Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Fri, 20 Jan 2017 16:23:52 -0500 Subject: [PATCH 6/6] changelog --- README.md | 1 + docs/conf.py | 4 ++-- setup.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 30c125d..22bdf82 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ I will sign everything with 0x769A1BC78A2DDEE2 ## CHANGELOG +- 2017-01-20 [Tyrel Souza] Make path return filename - 2017-01-20 [Tyrel Souza] Add another migration, and redo all the initial migrations. - 2017-01-20 [Tyrel Souza] Make sure migrations is actually there. - 2017-01-20 [Tyrel Souza] Split filename and filehash. diff --git a/docs/conf.py b/docs/conf.py index 73bfe2e..fb008f8 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.0' +version = u'0.4.1' # The full version, including alpha/beta/rc tags. -release = u'0.4.0' +release = u'0.4.1' # 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 e7a494f..c2abf4a 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ class CleanCommand(Command): setup( name="django-dbfilestorage", - version="0.4.0", + version="0.4.1", description="Database backed file storage for testing.", long_description="Database backed file storage for testing. Stores files as base64 encoded textfields.", author="Tyrel Souza",