Skip to content

Commit

Permalink
Replace deprecated CICharField with custom collation for case-insensi…
Browse files Browse the repository at this point in the history
…tivity
  • Loading branch information
Minnozz committed Apr 1, 2024
1 parent e52ca67 commit a3430c9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
@@ -0,0 +1,39 @@
# Generated by Django 4.2.11 on 2024-04-01 21:09

import bookwyrm.models.fields
from django.db import migrations, models
from django.contrib.postgres.operations import CreateCollation


class Migration(migrations.Migration):

dependencies = [
("bookwyrm", "0200_alter_user_preferred_timezone"),
]

operations = [
CreateCollation(
"case_insensitive",
provider="icu",
locale="und-u-ks-level2",
deterministic=False,
),
migrations.AlterField(
model_name="hashtag",
name="name",
field=bookwyrm.models.fields.CharField(
db_collation="case_insensitive", max_length=256
),
),
migrations.AlterField(
model_name="user",
name="localname",
field=models.CharField(
db_collation="case_insensitive",
max_length=255,
null=True,
unique=True,
validators=[bookwyrm.models.fields.validate_localname],
),
),
]
5 changes: 3 additions & 2 deletions bookwyrm/models/hashtag.py
Expand Up @@ -2,18 +2,19 @@
from bookwyrm import activitypub
from .activitypub_mixin import ActivitypubMixin
from .base_model import BookWyrmModel
from .fields import CICharField
from .fields import CharField


class Hashtag(ActivitypubMixin, BookWyrmModel):
"a hashtag which can be used in statuses"

name = CICharField(
name = CharField(
max_length=256,
blank=False,
null=False,
activitypub_field="name",
deduplication_field=True,
db_collation="case_insensitive",
)

name_field = "name"
Expand Down
7 changes: 4 additions & 3 deletions bookwyrm/models/user.py
Expand Up @@ -7,7 +7,7 @@

from django.apps import apps
from django.contrib.auth.models import AbstractUser
from django.contrib.postgres.fields import ArrayField, CICharField
from django.contrib.postgres.fields import ArrayField as DjangoArrayField
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
from django.dispatch import receiver
from django.db import models, transaction, IntegrityError
Expand Down Expand Up @@ -82,11 +82,12 @@ class User(OrderedCollectionPageMixin, AbstractUser):
summary = fields.HtmlField(null=True, blank=True)
local = models.BooleanField(default=False)
bookwyrm_user = fields.BooleanField(default=True)
localname = CICharField(
localname = models.CharField(
max_length=255,
null=True,
unique=True,
validators=[fields.validate_localname],
db_collation="case_insensitive",
)
# name is your display name, which you can change at will
name = fields.CharField(max_length=100, null=True, blank=True)
Expand Down Expand Up @@ -163,7 +164,7 @@ class User(OrderedCollectionPageMixin, AbstractUser):
show_guided_tour = models.BooleanField(default=True)

# feed options
feed_status_types = ArrayField(
feed_status_types = DjangoArrayField(
models.CharField(max_length=10, blank=False, choices=FeedFilterChoices),
size=8,
default=get_feed_filter_choices,
Expand Down

0 comments on commit a3430c9

Please sign in to comment.