From d8f8ba2e1a8165b3958d5d7007e5999cb3431667 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Mon, 29 Jan 2018 16:46:46 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20probl=C3=A8me=20avec=20aes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- preferences/aes_field.py | 4 ++++ preferences/migrations/0039_auto_20180115_0003.py | 5 ----- ...o_20180115_0010.py => 0040_auto_20180129_1745.py} | 12 ++++++------ preferences/models.py | 3 ++- 4 files changed, 12 insertions(+), 12 deletions(-) rename preferences/migrations/{0040_auto_20180115_0010.py => 0040_auto_20180129_1745.py} (75%) diff --git a/preferences/aes_field.py b/preferences/aes_field.py index 27b026f7..81f8accc 100644 --- a/preferences/aes_field.py +++ b/preferences/aes_field.py @@ -33,6 +33,8 @@ def decrypt(key, s): class AESEncryptedField(models.CharField): def save_form_data(self, instance, data): + if value is None: + return value setattr(instance, self.name, binascii.b2a_base64(encrypt(settings.AES_KEY, data))) @@ -49,6 +51,8 @@ class AESEncryptedField(models.CharField): binascii.a2b_base64(value)).decode('utf-8') def get_prep_value(self, value): + if value is None: + return value return binascii.b2a_base64(encrypt( settings.AES_KEY, value diff --git a/preferences/migrations/0039_auto_20180115_0003.py b/preferences/migrations/0039_auto_20180115_0003.py index da1b6631..3dbe2b4c 100644 --- a/preferences/migrations/0039_auto_20180115_0003.py +++ b/preferences/migrations/0039_auto_20180115_0003.py @@ -18,9 +18,4 @@ class Migration(migrations.Migration): name='payment_id', field=models.CharField(max_length=255, null=True), ), - migrations.AddField( - model_name='assooption', - name='payment_pass', - field=preferences.aes_field.AESEncryptedField(max_length=255, null=True), - ), ] diff --git a/preferences/migrations/0040_auto_20180115_0010.py b/preferences/migrations/0040_auto_20180129_1745.py similarity index 75% rename from preferences/migrations/0040_auto_20180115_0010.py rename to preferences/migrations/0040_auto_20180129_1745.py index 407cb831..dc7800f4 100644 --- a/preferences/migrations/0040_auto_20180115_0010.py +++ b/preferences/migrations/0040_auto_20180129_1745.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.10.7 on 2018-01-14 23:10 +# Generated by Django 1.10.7 on 2018-01-29 16:45 from __future__ import unicode_literals from django.db import migrations, models @@ -13,14 +13,14 @@ class Migration(migrations.Migration): ] operations = [ + migrations.AddField( + model_name='assooption', + name='payment_pass', + field=preferences.aes_field.AESEncryptedField(blank=True, max_length=255, null=True), + ), migrations.AlterField( model_name='assooption', name='payment_id', field=models.CharField(default='', max_length=255), ), - migrations.AlterField( - model_name='assooption', - name='payment_pass', - field=preferences.aes_field.AESEncryptedField(default='', max_length=255), - ), ] diff --git a/preferences/models.py b/preferences/models.py index d4ef9645..4f1f388e 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -479,7 +479,8 @@ class AssoOption(models.Model): ) payment_pass = AESEncryptedField( max_length=255, - default='', + null=True, + blank=True, )