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

Add fixes for Django 4.2 #478

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions beers/migrations/0040_create_collation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Create a case-insensitive collation for replacing the CITextField"""

# Generated by Django 4.2.1 on 2023-05-22 19:29

from django.db import migrations
from django.contrib.postgres.operations import CreateCollation


class Migration(migrations.Migration):
dependencies = [
("beers", "0039_alter_manufacturer_location"),
]

operations = [
CreateCollation(
"case_insensitive",
provider="icu",
locale="und-u-ks-level2",
deterministic=False,
)
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Generated by Django 4.2.1 on 2023-05-22 19:33

import django.contrib.postgres.fields
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("beers", "0040_create_collation"),
]

operations = [
migrations.AlterField(
model_name="beer",
name="alternate_names",
field=django.contrib.postgres.fields.ArrayField(
base_field=models.TextField(db_collation="case_insensitive"),
default=list,
size=None,
),
),
migrations.AlterField(
model_name="beer",
name="name",
field=models.TextField(db_collation="case_insensitive"),
),
migrations.AlterField(
model_name="manufacturer",
name="alternate_names",
field=django.contrib.postgres.fields.ArrayField(
base_field=models.TextField(db_collation="case_insensitive"),
default=list,
size=None,
),
),
migrations.AlterField(
model_name="manufacturer",
name="name",
field=models.TextField(db_collation="case_insensitive"),
),
migrations.AlterField(
model_name="style",
name="alternate_names",
field=django.contrib.postgres.fields.ArrayField(
base_field=models.TextField(db_collation="case_insensitive"),
default=list,
size=None,
),
),
migrations.AlterField(
model_name="style",
name="name",
field=models.TextField(db_collation="case_insensitive", unique=True),
),
]
20 changes: 13 additions & 7 deletions beers/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from typing import Iterable

from django.contrib.postgres.fields import CITextField, ArrayField
from django.contrib.postgres.fields import ArrayField
from django.db import models, transaction
from django.db.utils import IntegrityError
from django.utils.timezone import now
Expand All @@ -15,13 +15,15 @@


class Style(models.Model):
name = CITextField(unique=True)
name = models.TextField(unique=True, db_collation="case_insensitive")
default_color = models.CharField(
"HTML color (in hex) to use if the beer has no known color",
max_length=9, # #00112233 -> RGBA
blank=True,
)
alternate_names = ArrayField(CITextField(), default=list)
alternate_names = ArrayField(
models.TextField(db_collation="case_insensitive"), default=list
)

def merge_from(self, other_styles: Iterable["Style"]):
with transaction.atomic():
Expand Down Expand Up @@ -50,7 +52,7 @@ def __str__(self): # pylint: disable=invalid-str-returned


class Manufacturer(models.Model):
name = CITextField()
name = models.TextField(db_collation="case_insensitive")
url = models.URLField(blank=True)
location = models.CharField(blank=True, max_length=250)
logo_url = models.URLField(blank=True)
Expand All @@ -63,7 +65,9 @@ class Manufacturer(models.Model):
taplist_io_pk = models.PositiveIntegerField(blank=True, null=True)
time_first_seen = models.DateTimeField(blank=True, null=True, default=now)
beermenus_slug = models.CharField(max_length=250, blank=True, null=True)
alternate_names = ArrayField(CITextField(), default=list)
alternate_names = ArrayField(
models.TextField(db_collation="case_insensitive"), default=list
)

class Meta:
constraints = [
Expand Down Expand Up @@ -144,7 +148,7 @@ def __str__(self): # pylint: disable=invalid-str-returned


class Beer(models.Model):
name = CITextField()
name = models.TextField(db_collation="case_insensitive")
style = models.ForeignKey(
Style,
models.DO_NOTHING,
Expand Down Expand Up @@ -205,7 +209,9 @@ class Beer(models.Model):
time_first_seen = models.DateTimeField(blank=True, null=True, default=now)
tweeted_about = models.BooleanField(default=False)
beermenus_slug = models.CharField(max_length=250, blank=True, null=True)
alternate_names = ArrayField(CITextField(), default=list)
alternate_names = ArrayField(
models.TextField(db_collation="case_insensitive"), default=list
)

class Meta:
indexes = [
Expand Down
13 changes: 10 additions & 3 deletions hsv_dot_beer/config/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ class Production(Common):
INSTALLED_APPS += ("gunicorn",)

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
# https://docs.djangoproject.com/en/4.2/howto/static-files/
# http://django-storages.readthedocs.org/en/latest/index.html
INSTALLED_APPS += ("storages",)
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
STATICFILES_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
STORAGES = {
"default": {
"BACKEND": "storages.backends.s3boto3.S3Boto3Storage",
},
"staticfiles": {
# Leave whatever setting you already have here, e.g.:
"BACKEND": "storages.backends.s3boto3.S3Boto3Storage",
},
}
AWS_ACCESS_KEY_ID = os.getenv("DJANGO_AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.getenv("DJANGO_AWS_SECRET_ACCESS_KEY")
AWS_STORAGE_BUCKET_NAME = os.getenv("DJANGO_AWS_STORAGE_BUCKET_NAME")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.1 on 2023-05-22 19:33

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("venues", "0032_merge_20201124_1755"),
("beers", "0040_create_collation"),
]

operations = [
migrations.AlterField(
model_name="venueapiconfiguration",
name="arryved_manufacturer_name",
field=models.TextField(blank=True, db_collation="case_insensitive"),
),
]
6 changes: 4 additions & 2 deletions venues/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.db import models
from django.conf import settings
from django.shortcuts import reverse
from django.contrib.postgres.fields import ArrayField, CITextField
from django.contrib.postgres.fields import ArrayField
from django.utils.text import gettext_lazy as _
from timezone_field.fields import TimeZoneField
from django_countries.fields import CountryField
Expand Down Expand Up @@ -135,7 +135,9 @@ class VenueAPIConfiguration(models.Model):
beermenus_slug = models.CharField(max_length=250, blank=True)
arryved_location_id = models.CharField(max_length=50, blank=True)
arryved_menu_id = models.CharField(max_length=50, blank=True)
arryved_manufacturer_name = CITextField(blank=True)
arryved_manufacturer_name = models.TextField(
db_collation="case_insensitive", blank=True
)
arryved_serving_sizes = ArrayField(
models.TextField(),
default=list,
Expand Down