-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
329 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from babel.numbers import list_currencies | ||
|
||
CURRENCY_LIST = [currency.upper() for currency in list_currencies()] | ||
CURRENCY_CHOICES = [(key, key) for key in CURRENCY_LIST] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.contrib import admin | ||
|
||
from open_prices.locations.models import Location | ||
|
||
|
||
@admin.register(Location) | ||
class LocationAdmin(admin.ModelAdmin): | ||
list_display = ( | ||
"osm_id", | ||
"osm_type", | ||
"osm_name", | ||
"osm_tag_key", | ||
"osm_tag_value", | ||
"price_count", | ||
"created", | ||
) | ||
list_filter = ("osm_type",) | ||
search_fields = ("osm_id",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
OSM_TYPE_NODE = "NODE" | ||
OSM_TYPE_WAY = "WAY" | ||
OSM_TYPE_RELATION = "RELATION" | ||
|
||
OSM_TYPE_LIST = [OSM_TYPE_NODE, OSM_TYPE_WAY, OSM_TYPE_RELATION] | ||
OSM_TYPE_CHOICES = ((key, key) for key in OSM_TYPE_LIST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from django.db import models | ||
from django.utils import timezone | ||
|
||
from open_prices.locations import constants as location_constants | ||
|
||
|
||
class Location(models.Model): | ||
osm_id = models.PositiveBigIntegerField(blank=True, null=True) | ||
osm_type = models.CharField( | ||
max_length=10, choices=location_constants.OSM_TYPE_CHOICES | ||
) | ||
|
||
osm_name = models.CharField(blank=True, null=True) | ||
osm_display_name = models.CharField(blank=True, null=True) | ||
osm_tag_key = models.CharField(blank=True, null=True) | ||
osm_tag_value = models.CharField(blank=True, null=True) | ||
osm_address_postcode = models.CharField(blank=True, null=True) | ||
osm_address_city = models.CharField(blank=True, null=True) | ||
osm_address_country = models.CharField(blank=True, null=True) | ||
osm_address_country_code = models.CharField(blank=True, null=True) | ||
osm_lat = models.DecimalField( | ||
max_digits=11, decimal_places=7, blank=True, null=True | ||
) | ||
osm_lon = models.DecimalField( | ||
max_digits=11, decimal_places=7, blank=True, null=True | ||
) | ||
|
||
price_count = models.PositiveIntegerField(blank=True, null=True) | ||
|
||
created = models.DateTimeField(default=timezone.now) | ||
updated = models.DateTimeField(auto_now=True) | ||
|
||
class Meta: | ||
managed = False | ||
db_table = "locations" | ||
verbose_name = "Location" | ||
verbose_name_plural = "Locations" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"""For raw products (fruits, vegetables, etc.), the price is either | ||
per unit or per kilogram. This enum is used to store this information. | ||
""" | ||
|
||
PRICE_PER_UNIT = "UNIT" | ||
PRICE_PER_KILOGRAM = "KILOGRAM" | ||
|
||
PRICE_PER_LIST = [PRICE_PER_UNIT, PRICE_PER_KILOGRAM] | ||
PRICE_PER_CHOICES = [(key, key) for key in PRICE_PER_LIST] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from django.db import models | ||
from django.utils import timezone | ||
|
||
from open_prices.common import constants | ||
from open_prices.locations import constants as location_constants | ||
from open_prices.prices import constants as price_constants | ||
|
||
|
||
class Price(models.Model): | ||
product_code = models.CharField(blank=True, null=True) | ||
category_tag = models.CharField(blank=True, null=True) | ||
labels_tags = models.JSONField(blank=True, null=True) | ||
product_name = models.CharField(blank=True, null=True) | ||
origins_tags = models.JSONField(blank=True, null=True) | ||
product = models.ForeignKey( | ||
"products.Product", | ||
on_delete=models.SET_NULL, | ||
blank=True, | ||
null=True, | ||
related_name="prices", | ||
) | ||
|
||
price = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True) | ||
price_is_discounted = models.BooleanField(blank=True, null=True) | ||
price_without_discount = models.DecimalField( | ||
max_digits=10, decimal_places=2, blank=True, null=True | ||
) | ||
price_per = models.CharField( | ||
max_length=10, | ||
constants=price_constants.PRICE_PER_CHOICES, | ||
blank=True, | ||
null=True, | ||
) | ||
currency = models.CharField( | ||
max_length=3, choices=constants.CURRENCY_CHOICES, blank=True, null=True | ||
) | ||
|
||
location_osm_id = models.PositiveBigIntegerField(blank=True, null=True) | ||
location_osm_type = models.CharField( | ||
max_length=10, | ||
choices=location_constants.OSM_TYPE_CHOICES, | ||
blank=True, | ||
null=True, | ||
) | ||
location = models.ForeignKey( | ||
"locations.Location", | ||
on_delete=models.SET_NULL, | ||
blank=True, | ||
null=True, | ||
related_name="prices", | ||
) | ||
|
||
date = models.DateField(blank=True, null=True) | ||
|
||
proof = models.ForeignKey( | ||
"proofs.Proof", | ||
on_delete=models.SET_NULL, | ||
blank=True, | ||
null=True, | ||
related_name="prices", | ||
) | ||
|
||
owner = models.CharField(blank=True, null=True) | ||
source = models.CharField(blank=True, null=True) | ||
|
||
created = models.DateTimeField(default=timezone.now) | ||
updated = models.DateTimeField(auto_now=True) | ||
|
||
class Meta: | ||
managed = False | ||
db_table = "prices" | ||
verbose_name = "Price" | ||
verbose_name_plural = "Prices" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.contrib import admin | ||
|
||
from open_prices.products.models import Product | ||
|
||
|
||
@admin.register(Product) | ||
class ProductAdmin(admin.ModelAdmin): | ||
list_display = ( | ||
"code", | ||
"source", | ||
"product_name", | ||
"price_count", | ||
"created", | ||
) | ||
list_filter = ("source",) | ||
search_fields = ("code",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from openfoodfacts import Flavor | ||
|
||
SOURCE_LIST = [Flavor.off, Flavor.obf, Flavor.opff, Flavor.opf, Flavor.off_pro] | ||
SOURCE_CHOICES = ((key, key) for key in SOURCE_LIST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from django.contrib.postgres.fields import ArrayField | ||
from django.db import models | ||
from django.utils import timezone | ||
|
||
from open_prices.products import constants as product_constants | ||
|
||
|
||
class Product(models.Model): | ||
code = models.CharField(unique=True, blank=True, null=True) | ||
|
||
source = models.CharField(max_length=10, choices=product_constants.SOURCE_CHOICES) | ||
source_last_synced = models.DateTimeField(blank=True, null=True) | ||
|
||
product_name = models.CharField(blank=True, null=True) | ||
image_url = models.CharField(blank=True, null=True) | ||
product_quantity = models.IntegerField(blank=True, null=True) | ||
product_quantity_unit = models.CharField(blank=True, null=True) | ||
categories_tags = ArrayField(models.CharField(), blank=True) | ||
brands = models.CharField(blank=True, null=True) | ||
brands_tags = ArrayField(models.CharField(), blank=True) | ||
labels_tags = ArrayField(models.CharField(), blank=True) | ||
|
||
nutriscore_grade = models.CharField(blank=True, null=True) | ||
ecoscore_grade = models.CharField(blank=True, null=True) | ||
nova_group = models.PositiveIntegerField(blank=True, null=True) | ||
unique_scans_n = models.PositiveIntegerField(blank=True, null=True) | ||
|
||
price_count = models.PositiveIntegerField(blank=True, null=True) | ||
|
||
created = models.DateTimeField(default=timezone.now) | ||
updated = models.DateTimeField(auto_now=True) | ||
|
||
class Meta: | ||
managed = False | ||
db_table = "products" | ||
verbose_name = "Product" | ||
verbose_name_plural = "Products" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django.contrib import admin | ||
|
||
from open_prices.proofs.models import Proof | ||
|
||
|
||
@admin.register(Proof) | ||
class ProofAdmin(admin.ModelAdmin): | ||
list_display = ( | ||
"type", | ||
"location", | ||
"date", | ||
"currency", | ||
"price_count", | ||
"owner", | ||
"created", | ||
) | ||
list_filter = ("type",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
PRICE_TAG = "PRICE_TAG" | ||
RECEIPT = "RECEIPT" | ||
GDPR_REQUEST = "GDPR_REQUEST" | ||
|
||
TYPE_LIST = [PRICE_TAG, RECEIPT, GDPR_REQUEST] | ||
TYPE_CHOICES = [(key, key) for key in TYPE_LIST] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from django.db import models | ||
from django.utils import timezone | ||
|
||
from open_prices.common import constants | ||
from open_prices.locations import constants as location_constants | ||
from open_prices.proofs import constants as proof_constants | ||
|
||
|
||
class Proof(models.Model): | ||
file_path = models.CharField() | ||
mimetype = models.CharField(blank=True, null=True) | ||
type = models.CharField(max_length=20, choices=proof_constants.TYPE_CHOICES) | ||
|
||
location_osm_id = models.PositiveBigIntegerField(blank=True, null=True) | ||
location_osm_type = models.CharField( | ||
max_length=10, | ||
choices=location_constants.OSM_TYPE_CHOICES, | ||
blank=True, | ||
null=True, | ||
) | ||
location = models.ForeignKey( | ||
"locations.Location", | ||
on_delete=models.SET_NULL, | ||
blank=True, | ||
null=True, | ||
related_name="proofs", | ||
) | ||
date = models.DateField(blank=True, null=True) | ||
currency = models.CharField( | ||
max_length=3, choices=constants.CURRENCY_CHOICES, blank=True, null=True | ||
) | ||
|
||
price_count = models.PositiveIntegerField(blank=True, null=True) | ||
|
||
owner = models.CharField(blank=True, null=True) | ||
source = models.CharField(blank=True, null=True) | ||
|
||
created = models.DateTimeField(default=timezone.now) | ||
updated = models.DateTimeField(auto_now=True) | ||
|
||
class Meta: | ||
managed = False | ||
db_table = "proofs" | ||
verbose_name = "Proof" | ||
verbose_name_plural = "Proofs" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.contrib import admin | ||
|
||
from open_prices.users.models import User, Session | ||
|
||
|
||
@admin.register(User) | ||
class UserAdmin(admin.ModelAdmin): | ||
list_display = ("user_id", "is_moderator", "price_count", "created") | ||
list_filter = ("is_moderator",) | ||
search_fields = ("user_id",) | ||
|
||
|
||
@admin.register(Session) | ||
class SessionAdmin(admin.ModelAdmin): | ||
list_display = ("user", "token", "created", "last_used") | ||
search_fields = ("token",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from django.db import models | ||
from django.utils import timezone | ||
|
||
|
||
class User(models.Model): | ||
user_id = models.CharField(primary_key=True) | ||
|
||
is_moderator = models.BooleanField(default=False) | ||
|
||
price_count = models.PositiveIntegerField(blank=True, null=True) | ||
|
||
created = models.DateTimeField(default=timezone.now) | ||
# updated = models.DateTimeField(auto_now=True) | ||
|
||
class Meta: | ||
managed = False | ||
db_table = "users" | ||
verbose_name = "User" | ||
verbose_name_plural = "Users" | ||
|
||
|
||
class Session(models.Model): | ||
user = models.ForeignKey("users.User", on_delete=models.DO_NOTHING, related_name="sessions") | ||
token = models.CharField(unique=True) | ||
|
||
created = models.DateTimeField(default=timezone.now) | ||
last_used = models.DateTimeField(blank=True, null=True) | ||
|
||
class Meta: | ||
managed = False | ||
db_table = "sessions" | ||
verbose_name = "Session" | ||
verbose_name_plural = "Sessions" |