0001-cartads_cs-allow-many-subscribers-to-a-single-dossie.patch
passerelle/apps/cartads_cs/migrations/0007_auto_20190923_1711.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.12 on 2019-09-23 15:11 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations, models |
|
6 | ||
7 | ||
8 |
class Migration(migrations.Migration): |
|
9 | ||
10 |
dependencies = [ |
|
11 |
('cartads_cs', '0006_cartadscs_client_name'), |
|
12 |
] |
|
13 | ||
14 |
operations = [ |
|
15 |
migrations.CreateModel( |
|
16 |
name='CartaDSSubscriber', |
|
17 |
fields=[ |
|
18 |
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
|
19 |
('name_id', models.CharField(max_length=32, null=True)), |
|
20 |
], |
|
21 |
), |
|
22 |
migrations.AddField( |
|
23 |
model_name='cartadsdossier', |
|
24 |
name='subscribers', |
|
25 |
field=models.ManyToManyField(blank=True, to='cartads_cs.CartaDSSubscriber'), |
|
26 |
), |
|
27 |
] |
passerelle/apps/cartads_cs/migrations/0008_auto_20190923_1712.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.12 on 2019-09-23 15:12 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations |
|
6 | ||
7 | ||
8 |
def migrate_subscribers(apps, schema_editor): |
|
9 |
CartaDSDossier = apps.get_model('cartads_cs', 'CartaDSDossier') |
|
10 |
CartaDSSubscriber = apps.get_model('cartads_cs', 'CartaDSSubscriber') |
|
11 |
for instance in CartaDSDossier.objects.all(): |
|
12 |
if instance.name_id: |
|
13 |
subscriber, created = CartaDSSubscriber.objects.get_or_create(name_id=instance.name_id) |
|
14 |
instance.subscribers.add(subscriber) |
|
15 | ||
16 | ||
17 |
class Migration(migrations.Migration): |
|
18 | ||
19 |
dependencies = [ |
|
20 |
('cartads_cs', '0007_auto_20190923_1711'), |
|
21 |
] |
|
22 | ||
23 |
operations = [ |
|
24 |
migrations.RunPython(migrate_subscribers, migrations.RunPython.noop), |
|
25 |
] |
passerelle/apps/cartads_cs/models.py | ||
---|---|---|
75 | 75 |
ordering = ['id'] |
76 | 76 | |
77 | 77 | |
78 |
class CartaDSSubscriber(models.Model): |
|
79 |
name_id = models.CharField(max_length=32, null=True) |
|
80 | ||
81 | ||
78 | 82 |
class CartaDSDossier(models.Model): |
79 | 83 |
email = models.CharField(max_length=256) |
80 | 84 |
name_id = models.CharField(max_length=32, null=True) |
... | ... | |
91 | 95 |
cartads_numero_dossier = models.CharField(max_length=50, null=True) |
92 | 96 |
cartads_steps_cache = JSONField(default={}) |
93 | 97 |
last_update_datetime = models.DateTimeField(auto_now=True) |
98 |
subscribers = models.ManyToManyField(CartaDSSubscriber, blank=True) |
|
94 | 99 | |
95 | 100 | |
96 | 101 |
class AbstractCartaDSCS(BaseResource): |
... | ... | |
650 | 655 |
objet_demande_id=objet_demande_id, |
651 | 656 |
tracking_code=tracking_code, |
652 | 657 |
email=email, |
653 |
name_id=name_id, |
|
654 | 658 |
) |
655 | 659 |
dossier.save() |
656 | 660 |
signer = Signer(salt='cart@ds_cs/dossier') |
... | ... | |
660 | 664 |
'slug': self.slug, |
661 | 665 |
'endpoint': 'notification'})) + '/%s/' % signer.sign(str(dossier.id)) |
662 | 666 |
dossier.save() |
667 |
if name_id: |
|
668 |
dossier.subscribers.add(CartaDSSubscriber.objects.get_or_create(name_id=name_id)[0]) |
|
663 | 669 |
self.add_job('pack', dossier_id=dossier.id) |
664 | 670 |
return {'err': 0, 'dossier_id': dossier.id} |
665 | 671 | |
... | ... | |
954 | 960 |
}, |
955 | 961 |
}) |
956 | 962 |
def files(self, request, name_id, status=None): |
957 |
files = CartaDSDossier.objects.filter(name_id=name_id, cartads_numero_dossier__isnull=False) |
|
963 |
files = CartaDSDossier.objects.filter( |
|
964 |
cartads_numero_dossier__isnull=False, |
|
965 |
subscribers__name_id__in=[name_id]) |
|
958 | 966 |
if status: |
959 | 967 |
files = [x for x in files if |
960 | 968 |
self.get_file_status(x).get('status_id') == status or |
961 |
- |