diff --git a/README.md b/README.md index 5839815..9767bff 100755 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ## Introduce -A Django model field that encrypt your data when save to DB and decrypt when get from DB. It keeps data always encrypted in DB. Base on AES, it supports query method like `get()` and `filter()` in Django. +A Django model fields collection that encrypt your data when save to and decrypt when get from database. It keeps data always encrypted in database. Base on AES, it supports query method like `get()` and `filter()` in Django. Mirage can also migrate data from origin column to encrypted column in database with a good performance. @@ -83,6 +83,7 @@ Mirage will get the `settings.MIRAGE_SECRET_KEY` first, if not set, mirage will 2. EncryptedCharField 3. EncryptedEmailField 4. EncryptedIntegerField +5. EncryptedURLField(v1.3.0+) ## Data Migrate diff --git a/mirage/fields.py b/mirage/fields.py index 658d18c..c6db2e4 100755 --- a/mirage/fields.py +++ b/mirage/fields.py @@ -41,6 +41,10 @@ class EncryptedCharField(EncryptedMixin, models.CharField): prepared_max_length = 255 +class EncryptedURLField(EncryptedMixin, models.URLField): + prepared_max_length = 200 + + class EncryptedEmailField(EncryptedMixin, models.EmailField): prepared_max_length = 254 diff --git a/setup.py b/setup.py index 9447fb7..a18780c 100755 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) setup( name='django-mirage-field', - version='1.2.4', + version='1.3.0', install_requires=[ "cryptography", "tqdm", @@ -15,7 +15,7 @@ packages=find_packages(exclude=["tests*"]), include_package_data=True, license='MIT License', - description='A Django model field that encrypt your data when save to and decrypt when get from database. It keeps data always encrypted in database.', + description='A Django model fields collection that encrypt your data when save to and decrypt when get from database. It keeps data always encrypted in database.', long_description_content_type="text/markdown", long_description=README, url='https://github.com/luojilab/django-mirage-field', @@ -24,19 +24,15 @@ classifiers=[ 'Environment :: Web Environment', 'Framework :: Django', - 'Framework :: Django :: 1.8', - 'Framework :: Django :: 1.9', - 'Framework :: Django :: 1.10', - 'Framework :: Django :: 1.11', - 'Framework :: Django :: 2.0', - 'Framework :: Django :: 2.1', 'Framework :: Django :: 2.2', - 'Framework :: Django :: 3.0', + 'Framework :: Django :: 3.2', + 'Framework :: Django :: 4.0', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.9', 'Topic :: Internet :: WWW/HTTP', ], ) diff --git a/tests/apps/migrations/0003_testmodel_url.py b/tests/apps/migrations/0003_testmodel_url.py new file mode 100644 index 0000000..afd0ea8 --- /dev/null +++ b/tests/apps/migrations/0003_testmodel_url.py @@ -0,0 +1,19 @@ +# Generated by Django 4.0 on 2021-12-25 03:30 + +from django.db import migrations +import mirage.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('apps', '0002_testmodel_textraw'), + ] + + operations = [ + migrations.AddField( + model_name='testmodel', + name='url', + field=mirage.fields.EncryptedURLField(blank=True, null=True), + ), + ] diff --git a/tests/apps/models.py b/tests/apps/models.py index a39632c..0bf87e4 100755 --- a/tests/apps/models.py +++ b/tests/apps/models.py @@ -8,3 +8,4 @@ class TestModel(models.Model): textraw = models.TextField(blank=True, null=True) integer = fields.EncryptedIntegerField(blank=True, null=True) email = fields.EncryptedEmailField(blank=True, null=True) + url = fields.EncryptedURLField(blank=True, null=True) diff --git a/tests/test_field.py b/tests/test_field.py index 69baf57..7c45029 100755 --- a/tests/test_field.py +++ b/tests/test_field.py @@ -7,6 +7,7 @@ class TestField(TestCase): TEXT = 'hello,text' INTEGER = 1234567890 EMAIL = 'hello@email.com' + URL = 'https://yindongliang.com' @classmethod def setUpTestData(cls): @@ -35,3 +36,7 @@ def test_int_field(self): def test_email_field(self): self.assertEqual(self.obj.email, self.EMAIL) self.assertEqual(type(self.obj.email), str) + + def test_url_field(self): + self.assertEqual(self.obj.url, self.URL) + self.assertEqual(type(self.obj.url), str)