Skip to content

Commit d8ec0fc

Browse files
committed
feat: support URLField with EncryptedURLField #23
1 parent 0e76046 commit d8ec0fc

File tree

6 files changed

+36
-10
lines changed

6 files changed

+36
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
## Introduce
77

8-
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.
8+
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.
99

1010
Mirage can also migrate data from origin column to encrypted column in database with a good performance.
1111

@@ -83,6 +83,7 @@ Mirage will get the `settings.MIRAGE_SECRET_KEY` first, if not set, mirage will
8383
2. EncryptedCharField
8484
3. EncryptedEmailField
8585
4. EncryptedIntegerField
86+
5. EncryptedURLField(v1.3.0+)
8687

8788
## Data Migrate
8889

mirage/fields.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class EncryptedCharField(EncryptedMixin, models.CharField):
4141
prepared_max_length = 255
4242

4343

44+
class EncryptedURLField(EncryptedMixin, models.URLField):
45+
prepared_max_length = 200
46+
47+
4448
class EncryptedEmailField(EncryptedMixin, models.EmailField):
4549
prepared_max_length = 254
4650

setup.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
88
setup(
99
name='django-mirage-field',
10-
version='1.2.4',
10+
version='1.3.0',
1111
install_requires=[
1212
"cryptography",
1313
"tqdm",
1414
],
1515
packages=find_packages(exclude=["tests*"]),
1616
include_package_data=True,
1717
license='MIT License',
18-
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.',
18+
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.',
1919
long_description_content_type="text/markdown",
2020
long_description=README,
2121
url='https://github.com/luojilab/django-mirage-field',
@@ -24,19 +24,15 @@
2424
classifiers=[
2525
'Environment :: Web Environment',
2626
'Framework :: Django',
27-
'Framework :: Django :: 1.8',
28-
'Framework :: Django :: 1.9',
29-
'Framework :: Django :: 1.10',
30-
'Framework :: Django :: 1.11',
31-
'Framework :: Django :: 2.0',
32-
'Framework :: Django :: 2.1',
3327
'Framework :: Django :: 2.2',
34-
'Framework :: Django :: 3.0',
28+
'Framework :: Django :: 3.2',
29+
'Framework :: Django :: 4.0',
3530
'Intended Audience :: Developers',
3631
'License :: OSI Approved :: MIT License',
3732
'Operating System :: OS Independent',
3833
'Programming Language :: Python',
3934
'Programming Language :: Python :: 3.6',
35+
'Programming Language :: Python :: 3.9',
4036
'Topic :: Internet :: WWW/HTTP',
4137
],
4238
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 4.0 on 2021-12-25 03:30
2+
3+
from django.db import migrations
4+
import mirage.fields
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('apps', '0002_testmodel_textraw'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='testmodel',
16+
name='url',
17+
field=mirage.fields.EncryptedURLField(blank=True, null=True),
18+
),
19+
]

tests/apps/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ class TestModel(models.Model):
88
textraw = models.TextField(blank=True, null=True)
99
integer = fields.EncryptedIntegerField(blank=True, null=True)
1010
email = fields.EncryptedEmailField(blank=True, null=True)
11+
url = fields.EncryptedURLField(blank=True, null=True)

tests/test_field.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class TestField(TestCase):
77
TEXT = 'hello,text'
88
INTEGER = 1234567890
99
10+
URL = 'https://yindongliang.com'
1011

1112
@classmethod
1213
def setUpTestData(cls):
@@ -35,3 +36,7 @@ def test_int_field(self):
3536
def test_email_field(self):
3637
self.assertEqual(self.obj.email, self.EMAIL)
3738
self.assertEqual(type(self.obj.email), str)
39+
40+
def test_url_field(self):
41+
self.assertEqual(self.obj.url, self.URL)
42+
self.assertEqual(type(self.obj.url), str)

0 commit comments

Comments
 (0)