From 9b819f21da4e57962e96fd811c84aa46d0ffbff8 Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Fri, 16 Apr 2021 09:34:34 +0200
Subject: [PATCH] misc: remove postgres.E003 warnings (#52028)

---
 .../migrations/0013_auto_20210416_0938.py     | 34 +++++++++++++++++++
 passerelle/apps/cartads_cs/models.py          |  8 ++---
 .../migrations/0010_auto_20210416_0936.py     | 34 +++++++++++++++++++
 .../migrations/0010_auto_20210416_0936.py     | 34 +++++++++++++++++++
 .../ovh/migrations/0014_auto_20210416_0936.py | 34 +++++++++++++++++++
 .../migrations/0010_auto_20210416_0937.py     | 34 +++++++++++++++++++
 .../migrations/0004_auto_20210416_0938.py     | 26 ++++++++++++++
 passerelle/apps/phonecalls/models.py          |  2 +-
 .../migrations/0003_auto_20210416_0935.py     | 34 +++++++++++++++++++
 passerelle/base/models.py                     |  6 ++--
 passerelle/sms/models.py                      |  7 +++-
 11 files changed, 244 insertions(+), 9 deletions(-)
 create mode 100644 passerelle/apps/cartads_cs/migrations/0013_auto_20210416_0938.py
 create mode 100644 passerelle/apps/mobyt/migrations/0010_auto_20210416_0936.py
 create mode 100644 passerelle/apps/orange/migrations/0010_auto_20210416_0936.py
 create mode 100644 passerelle/apps/ovh/migrations/0014_auto_20210416_0936.py
 create mode 100644 passerelle/apps/oxyd/migrations/0010_auto_20210416_0937.py
 create mode 100644 passerelle/apps/phonecalls/migrations/0004_auto_20210416_0938.py
 create mode 100644 passerelle/apps/twilio/migrations/0003_auto_20210416_0935.py

diff --git a/passerelle/apps/cartads_cs/migrations/0013_auto_20210416_0938.py b/passerelle/apps/cartads_cs/migrations/0013_auto_20210416_0938.py
new file mode 100644
index 00000000..a05bbfb8
--- /dev/null
+++ b/passerelle/apps/cartads_cs/migrations/0013_auto_20210416_0938.py
@@ -0,0 +1,34 @@
+# Generated by Django 2.2.19 on 2021-04-16 07:38
+
+import django.contrib.postgres.fields.jsonb
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('cartads_cs', '0012_text_to_jsonb'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='cartadsdatacache',
+            name='data_parameters',
+            field=django.contrib.postgres.fields.jsonb.JSONField(default=dict),
+        ),
+        migrations.AlterField(
+            model_name='cartadsdatacache',
+            name='data_values',
+            field=django.contrib.postgres.fields.jsonb.JSONField(default=dict),
+        ),
+        migrations.AlterField(
+            model_name='cartadsdossier',
+            name='cartads_cache_infos',
+            field=django.contrib.postgres.fields.jsonb.JSONField(default=dict),
+        ),
+        migrations.AlterField(
+            model_name='cartadsdossier',
+            name='cartads_steps_cache',
+            field=django.contrib.postgres.fields.jsonb.JSONField(default=dict),
+        ),
+    ]
diff --git a/passerelle/apps/cartads_cs/models.py b/passerelle/apps/cartads_cs/models.py
index 5ac14102..0e4ac2ce 100644
--- a/passerelle/apps/cartads_cs/models.py
+++ b/passerelle/apps/cartads_cs/models.py
@@ -57,18 +57,18 @@ def cartads_file_location(instance, filename):
 
 
 def key_value_of_stringstring(d):
     return {'KeyValueOfstringstring': [{'Key': x, 'Value': y} for x, y in d.items()]}
 
 
 class CartaDSDataCache(models.Model):
     data_type = models.CharField(max_length=50)
-    data_parameters = JSONField(default={})
-    data_values = JSONField(default={})
+    data_parameters = JSONField(default=dict)
+    data_values = JSONField(default=dict)
     last_update_datetime = models.DateTimeField(auto_now=True)
 
 
 class CartaDSFile(models.Model):
     tracking_code = models.CharField(max_length=20)
     id_piece = models.CharField(max_length=20)
     uploaded_file = models.FileField(upload_to=cartads_file_location)
     sent_to_cartads = models.DateTimeField(null=True)
@@ -92,18 +92,18 @@ class CartaDSDossier(models.Model):
     zip_ready = models.BooleanField(default=False)
     zip_sent = models.BooleanField(default=False)
     zip_ack_response = models.CharField(null=True, max_length=20)
     notification_url = models.URLField(null=True)
     notification_message = models.TextField(null=True)
     cartads_id_dossier = models.CharField(max_length=50, null=True)
     cartads_numero_dossier = models.CharField(max_length=50, null=True)
     cartads_cache_code_acces = models.CharField(max_length=200, null=True)
-    cartads_cache_infos = JSONField(default={})
-    cartads_steps_cache = JSONField(default={})
+    cartads_cache_infos = JSONField(default=dict)
+    cartads_steps_cache = JSONField(default=dict)
     last_update_datetime = models.DateTimeField(auto_now=True)
     subscribers = models.ManyToManyField(CartaDSSubscriber, blank=True)
     formdata_url = models.CharField(null=True, max_length=200)
 
 
 class AbstractCartaDSCS(BaseResource):
 
     wsdl_base_url = models.URLField(
diff --git a/passerelle/apps/mobyt/migrations/0010_auto_20210416_0936.py b/passerelle/apps/mobyt/migrations/0010_auto_20210416_0936.py
new file mode 100644
index 00000000..450e4512
--- /dev/null
+++ b/passerelle/apps/mobyt/migrations/0010_auto_20210416_0936.py
@@ -0,0 +1,34 @@
+# Generated by Django 2.2.19 on 2021-04-16 07:36
+
+import django.contrib.postgres.fields
+from django.db import migrations, models
+import passerelle.sms.models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('mobyt', '0009_auto_20210202_1304'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='mobytsmsgateway',
+            name='authorized',
+            field=django.contrib.postgres.fields.ArrayField(
+                base_field=models.CharField(
+                    choices=[
+                        ('fr-metro', 'France mainland (+33 [67])'),
+                        ('fr-domtom', 'France DOM/TOM (+262, etc.)'),
+                        ('be', 'Belgian (+32 4[5-9]) '),
+                        ('all', 'All'),
+                    ],
+                    max_length=32,
+                    null=True,
+                ),
+                default=passerelle.sms.models.authorized_default,
+                size=None,
+                verbose_name='Authorized Countries',
+            ),
+        ),
+    ]
diff --git a/passerelle/apps/orange/migrations/0010_auto_20210416_0936.py b/passerelle/apps/orange/migrations/0010_auto_20210416_0936.py
new file mode 100644
index 00000000..3ad8e4a0
--- /dev/null
+++ b/passerelle/apps/orange/migrations/0010_auto_20210416_0936.py
@@ -0,0 +1,34 @@
+# Generated by Django 2.2.19 on 2021-04-16 07:36
+
+import django.contrib.postgres.fields
+from django.db import migrations, models
+import passerelle.sms.models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('orange', '0009_auto_20210202_1304'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='orangesmsgateway',
+            name='authorized',
+            field=django.contrib.postgres.fields.ArrayField(
+                base_field=models.CharField(
+                    choices=[
+                        ('fr-metro', 'France mainland (+33 [67])'),
+                        ('fr-domtom', 'France DOM/TOM (+262, etc.)'),
+                        ('be', 'Belgian (+32 4[5-9]) '),
+                        ('all', 'All'),
+                    ],
+                    max_length=32,
+                    null=True,
+                ),
+                default=passerelle.sms.models.authorized_default,
+                size=None,
+                verbose_name='Authorized Countries',
+            ),
+        ),
+    ]
diff --git a/passerelle/apps/ovh/migrations/0014_auto_20210416_0936.py b/passerelle/apps/ovh/migrations/0014_auto_20210416_0936.py
new file mode 100644
index 00000000..e88ba58f
--- /dev/null
+++ b/passerelle/apps/ovh/migrations/0014_auto_20210416_0936.py
@@ -0,0 +1,34 @@
+# Generated by Django 2.2.19 on 2021-04-16 07:36
+
+import django.contrib.postgres.fields
+from django.db import migrations, models
+import passerelle.sms.models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('ovh', '0013_auto_20210202_1304'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='ovhsmsgateway',
+            name='authorized',
+            field=django.contrib.postgres.fields.ArrayField(
+                base_field=models.CharField(
+                    choices=[
+                        ('fr-metro', 'France mainland (+33 [67])'),
+                        ('fr-domtom', 'France DOM/TOM (+262, etc.)'),
+                        ('be', 'Belgian (+32 4[5-9]) '),
+                        ('all', 'All'),
+                    ],
+                    max_length=32,
+                    null=True,
+                ),
+                default=passerelle.sms.models.authorized_default,
+                size=None,
+                verbose_name='Authorized Countries',
+            ),
+        ),
+    ]
diff --git a/passerelle/apps/oxyd/migrations/0010_auto_20210416_0937.py b/passerelle/apps/oxyd/migrations/0010_auto_20210416_0937.py
new file mode 100644
index 00000000..ff1688cb
--- /dev/null
+++ b/passerelle/apps/oxyd/migrations/0010_auto_20210416_0937.py
@@ -0,0 +1,34 @@
+# Generated by Django 2.2.19 on 2021-04-16 07:37
+
+import django.contrib.postgres.fields
+from django.db import migrations, models
+import passerelle.sms.models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('oxyd', '0009_auto_20210202_1304'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='oxydsmsgateway',
+            name='authorized',
+            field=django.contrib.postgres.fields.ArrayField(
+                base_field=models.CharField(
+                    choices=[
+                        ('fr-metro', 'France mainland (+33 [67])'),
+                        ('fr-domtom', 'France DOM/TOM (+262, etc.)'),
+                        ('be', 'Belgian (+32 4[5-9]) '),
+                        ('all', 'All'),
+                    ],
+                    max_length=32,
+                    null=True,
+                ),
+                default=passerelle.sms.models.authorized_default,
+                size=None,
+                verbose_name='Authorized Countries',
+            ),
+        ),
+    ]
diff --git a/passerelle/apps/phonecalls/migrations/0004_auto_20210416_0938.py b/passerelle/apps/phonecalls/migrations/0004_auto_20210416_0938.py
new file mode 100644
index 00000000..1de7b659
--- /dev/null
+++ b/passerelle/apps/phonecalls/migrations/0004_auto_20210416_0938.py
@@ -0,0 +1,26 @@
+# Generated by Django 2.2.19 on 2021-04-16 07:38
+
+import django.contrib.postgres.fields.jsonb
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('phonecalls', '0003_phonecalls_redirect_url'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='call',
+            name='details',
+            field=django.contrib.postgres.fields.jsonb.JSONField(default=dict),
+        ),
+        migrations.AlterField(
+            model_name='phonecalls',
+            name='redirect_url',
+            field=models.URLField(
+                null=True, verbose_name='URL to redirect to or open when using redirect or newtab parameters'
+            ),
+        ),
+    ]
diff --git a/passerelle/apps/phonecalls/models.py b/passerelle/apps/phonecalls/models.py
index 0fb98484..fbfffeb6 100644
--- a/passerelle/apps/phonecalls/models.py
+++ b/passerelle/apps/phonecalls/models.py
@@ -145,17 +145,17 @@ class PhoneCalls(BaseResource):
 
 
 class Call(models.Model):
     resource = models.ForeignKey(PhoneCalls, on_delete=models.CASCADE)
     callee = models.CharField(blank=False, max_length=64)
     caller = models.CharField(blank=False, max_length=64)
     start_timestamp = models.DateTimeField(auto_now_add=True)
     end_timestamp = models.DateTimeField(null=True, default=None)
-    details = JSONField(default={})
+    details = JSONField(default=dict)
 
     class Meta:
         verbose_name = _('Phone Call')
         ordering = ['-start_timestamp']
 
     def json(self):
         # We use make_naive to send localtime, because this API will be used
         # by javascript, which will not be comfortable with UTC datetimes
diff --git a/passerelle/apps/twilio/migrations/0003_auto_20210416_0935.py b/passerelle/apps/twilio/migrations/0003_auto_20210416_0935.py
new file mode 100644
index 00000000..b73b38c7
--- /dev/null
+++ b/passerelle/apps/twilio/migrations/0003_auto_20210416_0935.py
@@ -0,0 +1,34 @@
+# Generated by Django 2.2.19 on 2021-04-16 07:35
+
+import django.contrib.postgres.fields
+from django.db import migrations, models
+import passerelle.sms.models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('twilio', '0002_auto_20210202_1304'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='twiliosmsgateway',
+            name='authorized',
+            field=django.contrib.postgres.fields.ArrayField(
+                base_field=models.CharField(
+                    choices=[
+                        ('fr-metro', 'France mainland (+33 [67])'),
+                        ('fr-domtom', 'France DOM/TOM (+262, etc.)'),
+                        ('be', 'Belgian (+32 4[5-9]) '),
+                        ('all', 'All'),
+                    ],
+                    max_length=32,
+                    null=True,
+                ),
+                default=passerelle.sms.models.authorized_default,
+                size=None,
+                verbose_name='Authorized Countries',
+            ),
+        ),
+    ]
diff --git a/passerelle/base/models.py b/passerelle/base/models.py
index e54a1f1d..c35f9445 100644
--- a/passerelle/base/models.py
+++ b/passerelle/base/models.py
@@ -755,33 +755,33 @@ class SkipJob(Exception):
 
 
 class Job(models.Model):
     resource_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
     resource_pk = models.PositiveIntegerField()
     resource = fields.GenericForeignKey('resource_type', 'resource_pk')
     method_name = models.CharField(max_length=50)
     natural_id = models.CharField(max_length=256, blank=True, null=True)
-    parameters = JSONField(default={})
+    parameters = JSONField(default=dict)
     creation_timestamp = models.DateTimeField(auto_now_add=True)
     update_timestamp = models.DateTimeField(auto_now=True)
     done_timestamp = models.DateTimeField(null=True)
     after_timestamp = models.DateTimeField(null=True)
     status = models.CharField(
         max_length=20,
         default='registered',
         choices=(
             ('registered', _('Registered')),
             ('running', _('Running')),
             ('failed', _('Failed')),
             ('restarted', _('Failed and restarted')),
             ('completed', _('Completed')),
         ),
     )
-    status_details = JSONField(default={})
+    status_details = JSONField(default=dict)
 
     class Meta:
         ordering = ('id',)
 
     def set_after_timestamp(self, value):
         if isinstance(value, datetime.datetime):
             self.after_timestamp = value
         elif isinstance(value, six.integer_types + (float,)):
@@ -836,17 +836,17 @@ class Job(models.Model):
 @six.python_2_unicode_compatible
 class ResourceLog(models.Model):
     timestamp = models.DateTimeField(auto_now_add=True)
     appname = models.CharField(max_length=128, verbose_name='appname', null=True)
     slug = models.CharField(max_length=128, verbose_name='slug', null=True)
     levelno = models.IntegerField(verbose_name='log level')
     sourceip = models.GenericIPAddressField(blank=True, null=True, verbose_name=_('Source IP'))
     message = models.TextField(verbose_name='message')
-    extra = JSONField(verbose_name='extras', default={})
+    extra = JSONField(verbose_name='extras', default=dict)
     transaction_id = models.UUIDField(null=True, db_index=True)
 
     class Meta:
         ordering = ('id',)
         permissions = (('see_resourcelog', 'Can see resource logs'),)
 
     @property
     def level(self):
diff --git a/passerelle/sms/models.py b/passerelle/sms/models.py
index db86dec8..bdee7230 100644
--- a/passerelle/sms/models.py
+++ b/passerelle/sms/models.py
@@ -46,16 +46,20 @@ SEND_SCHEMA = {
             'description': 'Destination numbers',
             "type": "array",
             "items": {'type': 'string', 'pattern': r'^\+?[-.\s/\d]+$'},
         },
     },
 }
 
 
+def authorized_default():
+    return [SMSResource.ALL]
+
+
 class SMSResource(BaseResource):
     manager_form_base_class = SMSConnectorForm
     category = _('SMS Providers')
     documentation_url = (
         'https://doc-publik.entrouvert.com/admin-fonctionnel/les-tutos/configuration-envoi-sms/'
     )
 
     _can_send_messages_description = _('Sending messages is limited to the following API users:')
@@ -75,20 +79,21 @@ class SMSResource(BaseResource):
     BE_ = 'be'
     ALL = 'all'
     AUTHORIZED = [
         (FR_METRO, _('France mainland (+33 [67])')),
         (FR_DOMTOM, _('France DOM/TOM (+262, etc.)')),
         (BE_, _('Belgian (+32 4[5-9]) ')),
         (ALL, _('All')),
     ]
+
     authorized = ArrayField(
         models.CharField(max_length=32, null=True, choices=AUTHORIZED),
         verbose_name=_('Authorized Countries'),
-        default=[ALL],
+        default=authorized_default,
     )
 
     allow_premium_rate = models.BooleanField(
         _('Allow premium rate numbers'),
         default=False,
         help_text=_('This option is only applyed to France mainland'),
     )
 
-- 
2.30.2

