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 6726b1e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
@@ -0,0 +1,39 @@
# Generated by Django 4.2.11 on 2024-04-01 20:44

import bookwyrm.models.fields
from django.db import migrations
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=bookwyrm.models.fields.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
5 changes: 3 additions & 2 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
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 = fields.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

0 comments on commit 6726b1e

Please sign in to comment.