From 40dbf92ac54a48cfe7ff5a8cd0e1b459f97d8150 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Thu, 26 Dec 2024 17:45:23 +0100 Subject: [PATCH 1/2] New Proof.ready_for_price_tag_validation boolean field. With specific rule --- open_prices/proofs/constants.py | 5 ++++ ...09_proof_ready_for_price_tag_validation.py | 25 +++++++++++++++++++ open_prices/proofs/models.py | 14 +++++++++++ open_prices/proofs/tests.py | 7 ++++++ 4 files changed, 51 insertions(+) create mode 100644 open_prices/proofs/migrations/0009_proof_ready_for_price_tag_validation.py diff --git a/open_prices/proofs/constants.py b/open_prices/proofs/constants.py index cb4ea05b..c635b245 100644 --- a/open_prices/proofs/constants.py +++ b/open_prices/proofs/constants.py @@ -34,6 +34,11 @@ (PRICE_TAG_EXTRACTION_TYPE, PRICE_TAG_EXTRACTION_TYPE) ] +PROOF_READY_FOR_PRICE_TAG_VALIDATION_SOURCES = [ + "/proofs/add/single", + "/proofs/add/multiple", +] + class PriceTagStatus(enum.IntEnum): deleted = 0 diff --git a/open_prices/proofs/migrations/0009_proof_ready_for_price_tag_validation.py b/open_prices/proofs/migrations/0009_proof_ready_for_price_tag_validation.py new file mode 100644 index 00000000..c116ad80 --- /dev/null +++ b/open_prices/proofs/migrations/0009_proof_ready_for_price_tag_validation.py @@ -0,0 +1,25 @@ +# Generated by Django 5.1.4 on 2024-12-26 16:37 + +from django.db import migrations, models + + +def init_ready_for_price_tag_validation(apps, schema_editor): + Proof = apps.get_model("proofs", "Proof") + Proof.objects.filter(type="PRICE_TAG", source__contains="/proofs/add/").update( + ready_for_price_tag_validation=True + ) + + +class Migration(migrations.Migration): + dependencies = [ + ("proofs", "0008_alter_proofprediction_type_pricetagprediction"), + ] + + operations = [ + migrations.AddField( + model_name="proof", + name="ready_for_price_tag_validation", + field=models.BooleanField(default=False), + ), + migrations.RunPython(init_ready_for_price_tag_validation), + ] diff --git a/open_prices/proofs/models.py b/open_prices/proofs/models.py index 259b3410..06a38636 100644 --- a/open_prices/proofs/models.py +++ b/open_prices/proofs/models.py @@ -98,6 +98,8 @@ class Proof(models.Model): null=True, ) + ready_for_price_tag_validation = models.BooleanField(default=False) + price_count = models.PositiveIntegerField(default=0, blank=True, null=True) owner = models.CharField(blank=True, null=True) @@ -230,9 +232,21 @@ def set_location(self): ) self.location = location + def set_ready_for_price_tag_validation(self): + if ( + self.type == proof_constants.TYPE_PRICE_TAG + and self.source + and any( + source in self.source + for source in proof_constants.PROOF_READY_FOR_PRICE_TAG_VALIDATION_SOURCES + ) + ): + self.ready_for_price_tag_validation = True + def save(self, *args, **kwargs): self.full_clean() self.set_location() + self.set_ready_for_price_tag_validation() super().save(*args, **kwargs) @property diff --git a/open_prices/proofs/tests.py b/open_prices/proofs/tests.py index 8f2af417..f5f59a90 100644 --- a/open_prices/proofs/tests.py +++ b/open_prices/proofs/tests.py @@ -165,6 +165,13 @@ def test_proof_receipt_fields(self): type=proof_constants.TYPE_PRICE_TAG, ) + def test_proof_ready_for_price_tag_validation_field(self): + proof = ProofFactory(type=proof_constants.TYPE_PRICE_TAG, source="/proofs/add/") + self.assertFalse(proof.ready_for_price_tag_validation) + proof.source = "/proofs/add/multiple" + proof.save() + self.assertTrue(proof.ready_for_price_tag_validation) + class ProofQuerySetTest(TestCase): @classmethod From 8fdb50b25173974319ac00a522034abbc63dcb74 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Thu, 26 Dec 2024 17:48:42 +0100 Subject: [PATCH 2/2] Allow filtering PriceTag with this new field --- open_prices/api/proofs/filters.py | 1 + 1 file changed, 1 insertion(+) diff --git a/open_prices/api/proofs/filters.py b/open_prices/api/proofs/filters.py index 66a01f82..f6f873f7 100644 --- a/open_prices/api/proofs/filters.py +++ b/open_prices/api/proofs/filters.py @@ -50,5 +50,6 @@ class Meta: fields = [ "proof_id", "proof__owner", + "proof__ready_for_price_tag_validation", "status", ]