toulouse_foederis: simplify document model (#76680)
gitea/passerelle/pipeline/head Build started...
Details
gitea/passerelle/pipeline/head Build started...
Details
- no null, only blank and default values. - no limited charfield, all textfield.
This commit is contained in:
parent
e852d7e2f3
commit
2d518f5f06
|
@ -86,6 +86,7 @@ class Migration(migrations.Migration):
|
|||
models.FileField(
|
||||
upload_to=passerelle.contrib.toulouse_foederis.models.upload_to,
|
||||
verbose_name='PDF file',
|
||||
blank=True,
|
||||
),
|
||||
),
|
||||
('created', models.DateTimeField(auto_now_add=True, verbose_name='Created')),
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 3.2.18 on 2023-04-16 06:16
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def set_default(apps, schema_editor):
|
||||
# prevent postgresql error "pending event triggers" when altering the nullable status
|
||||
schema_editor.execute('SET CONSTRAINTS ALL IMMEDIATE')
|
||||
apps.get_model('toulouse_foederis', 'Document').objects.filter(text__isnull=True).update(text='')
|
||||
apps.get_model('toulouse_foederis', 'Document').objects.filter(data__isnull=True).update(data={})
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('toulouse_foederis', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(set_default, migrations.RunPython.noop),
|
||||
]
|
|
@ -0,0 +1,28 @@
|
|||
# Generated by Django 3.2.18 on 2023-04-16 06:16
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('toulouse_foederis', '0002_set_default_value'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='document',
|
||||
name='data',
|
||||
field=models.JSONField(blank=True, default=dict, verbose_name='Data'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='document',
|
||||
name='external_id',
|
||||
field=models.TextField(unique=True, verbose_name='Key'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='document',
|
||||
name='text',
|
||||
field=models.TextField(blank=True, default='', verbose_name='Text'),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
|
@ -355,10 +355,10 @@ class Document(models.Model):
|
|||
on_delete=models.CASCADE,
|
||||
related_name='documents',
|
||||
)
|
||||
external_id = models.CharField(_('Key'), max_length=64, unique=True)
|
||||
text = models.CharField(_('Text'), max_length=64, null=True)
|
||||
data = JSONField(_('Data'), null=True)
|
||||
pdf = models.FileField(_('PDF file'), upload_to=upload_to)
|
||||
external_id = models.TextField(_('Key'), unique=True)
|
||||
text = models.TextField(_('Text'), blank=True)
|
||||
data = JSONField(_('Data'), blank=True, default=dict)
|
||||
pdf = models.FileField(_('PDF file'), blank=True, upload_to=upload_to)
|
||||
created = models.DateTimeField(_('Created'), auto_now_add=True)
|
||||
updated = models.DateTimeField(_('Updated'), auto_now=True)
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import urllib.parse
|
|||
|
||||
import httmock
|
||||
import pytest
|
||||
from django.db import connection
|
||||
|
||||
from passerelle.base.models import AccessRight
|
||||
from passerelle.contrib.toulouse_foederis.models import Document, Resource
|
||||
|
@ -346,3 +347,25 @@ class TestEndpoints:
|
|||
assert response.content.startswith(b'%PDF-1.4')
|
||||
app.get('/toulouse-foederis/foederis/announce/111/pdf/', status=404)
|
||||
assert response.headers['content-type'] == 'application/pdf'
|
||||
|
||||
|
||||
def test_migration_0003_no_null_no_charfield(migration):
|
||||
with connection.cursor() as cur:
|
||||
cur.execute('SET CONSTRAINTS ALL IMMEDIATE')
|
||||
apps = migration.before([('toulouse_foederis', '0001_initial')])
|
||||
Document = apps.get_model('toulouse_foederis', 'Document')
|
||||
Resource = apps.get_model('toulouse_foederis', 'Resource')
|
||||
resource = Resource.objects.create(
|
||||
title='Foederis',
|
||||
slug='foederis',
|
||||
description='Foederis',
|
||||
url='https://passerelle.cutm-publik-preprod.nfrance.com/foederis/',
|
||||
api_key=APIKEY,
|
||||
)
|
||||
doc_before = Document.objects.create(resource=resource, external_id='1', data=None, text=None, pdf='')
|
||||
|
||||
apps = migration.apply([('toulouse_foederis', '0003_no_null_no_charfield')])
|
||||
Document = apps.get_model('toulouse_foederis', 'Document')
|
||||
doc_after = Document.objects.get(pk=doc_before.pk)
|
||||
assert doc_after.data == {}
|
||||
assert doc_after.text == ''
|
||||
|
|
Loading…
Reference in New Issue