2018-01-02 13:02:13 +01:00
|
|
|
from django.db import migrations, models
|
2022-05-27 23:33:51 +02:00
|
|
|
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
|
2018-01-02 13:02:13 +01:00
|
|
|
from django.db.migrations.state import StateApps
|
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2021-09-08 21:21:51 +02:00
|
|
|
# change emoji set to text if emoji_alt_code is true.
|
2022-05-27 23:33:51 +02:00
|
|
|
def change_emojiset(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
|
2018-01-02 13:02:13 +01:00
|
|
|
UserProfile = apps.get_model("zerver", "UserProfile")
|
|
|
|
for user in UserProfile.objects.filter(emoji_alt_code=True):
|
|
|
|
user.emojiset = "text"
|
|
|
|
user.save(update_fields=["emojiset"])
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2022-05-27 23:33:51 +02:00
|
|
|
def reverse_change_emojiset(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
|
2018-02-06 01:52:04 +01:00
|
|
|
UserProfile = apps.get_model("zerver", "UserProfile")
|
|
|
|
for user in UserProfile.objects.filter(emojiset="text"):
|
|
|
|
# Resetting `emojiset` to "google" (the default) doesn't make an
|
|
|
|
# exact round trip, but it's nearly indistinguishable -- the setting
|
|
|
|
# shouldn't really matter while `emoji_alt_code` is true.
|
|
|
|
user.emoji_alt_code = True
|
|
|
|
user.emojiset = "google"
|
|
|
|
user.save(update_fields=["emoji_alt_code", "emojiset"])
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-01-02 13:02:13 +01:00
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
2021-02-12 08:20:45 +01:00
|
|
|
("zerver", "0129_remove_userprofile_autoscroll_forever"),
|
2018-01-02 13:02:13 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.AlterField(
|
2021-02-12 08:20:45 +01:00
|
|
|
model_name="userprofile",
|
|
|
|
name="emojiset",
|
2021-02-12 08:19:30 +01:00
|
|
|
field=models.CharField(
|
|
|
|
choices=[
|
2021-02-12 08:20:45 +01:00
|
|
|
("google", "Google"),
|
|
|
|
("apple", "Apple"),
|
|
|
|
("twitter", "Twitter"),
|
|
|
|
("emojione", "EmojiOne"),
|
|
|
|
("text", "Plain text"),
|
2021-02-12 08:19:30 +01:00
|
|
|
],
|
2021-02-12 08:20:45 +01:00
|
|
|
default="google",
|
2021-02-12 08:19:30 +01:00
|
|
|
max_length=20,
|
|
|
|
),
|
2018-01-02 13:02:13 +01:00
|
|
|
),
|
2020-04-29 08:43:25 +02:00
|
|
|
migrations.RunPython(change_emojiset, reverse_change_emojiset, elidable=True),
|
2018-01-02 13:02:13 +01:00
|
|
|
migrations.RemoveField(
|
2021-02-12 08:20:45 +01:00
|
|
|
model_name="userprofile",
|
|
|
|
name="emoji_alt_code",
|
2018-01-02 13:02:13 +01:00
|
|
|
),
|
|
|
|
]
|