Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Price tags): new Proof.ready_for_price_tag_validation field to help filter the frontend UI #656

Merged
merged 2 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions open_prices/api/proofs/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ class Meta:
fields = [
"proof_id",
"proof__owner",
"proof__ready_for_price_tag_validation",
"status",
]
5 changes: 5 additions & 0 deletions open_prices/proofs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
]
14 changes: 14 additions & 0 deletions open_prices/proofs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions open_prices/proofs/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading