mirror of https://github.com/zulip/zulip.git
[schema] [manual] Add colors to the subscription model.
This is preparatory for removing the StreamColor model, so we also set things up so anything changing the StreamColor model changes the Subscription model too. The manual task is to run the copy_colors.py management command after deployment to each of staging and prod. (imported from commit 1be7523ca59f5266eb2c4dc2009e31209ed49635)
This commit is contained in:
parent
b06284717c
commit
0ee684a4b5
|
@ -431,13 +431,16 @@ def set_stream_color_backend(user_profile, subscription, color=None):
|
|||
if not created:
|
||||
stream_color.color = color
|
||||
stream_color.save(update_fields=["color"])
|
||||
subscription.color = color
|
||||
subscription.save(update_fields=["color"])
|
||||
return color
|
||||
|
||||
def do_add_subscription(user_profile, stream, no_log=False):
|
||||
recipient = get_recipient(Recipient.STREAM, stream.id)
|
||||
color = pick_color(user_profile)
|
||||
(subscription, created) = Subscription.objects.get_or_create(
|
||||
user_profile=user_profile, recipient=recipient,
|
||||
defaults={'active': True})
|
||||
defaults={'active': True, 'color': color})
|
||||
did_subscribe = created
|
||||
if not subscription.active:
|
||||
did_subscribe = True
|
||||
|
|
|
@ -63,3 +63,5 @@ class Command(BaseCommand):
|
|||
continue
|
||||
|
||||
StreamColor(subscription=subscription, color=color).save()
|
||||
subscription.color = color
|
||||
subscription.save(update_fields=["color"])
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
from zephyr.models import StreamColor, Subscription
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = """Copies all colors from the StreamColor table to the Subscription table."""
|
||||
|
||||
def handle(self, *args, **options):
|
||||
for stream_color in StreamColor.objects.all():
|
||||
subscription = stream_color.subscription
|
||||
subscription.color = stream_color.color
|
||||
subscription.save(update_fields=["color"])
|
|
@ -20,3 +20,5 @@ class Command(BaseCommand):
|
|||
stream_color, _ = StreamColor.objects.get_or_create(subscription=sub)
|
||||
stream_color.color = StreamColor.DEFAULT_STREAM_COLOR
|
||||
stream_color.save()
|
||||
sub.color = Subscription.DEFAULT_STREAM_COLOR
|
||||
sub.save(update_fields=["color"])
|
||||
|
|
|
@ -324,6 +324,9 @@ class Subscription(models.Model):
|
|||
active = models.BooleanField(default=True)
|
||||
in_home_view = models.NullBooleanField(default=True)
|
||||
|
||||
DEFAULT_STREAM_COLOR = "#c2c2c2"
|
||||
color = models.CharField(max_length=10, default=DEFAULT_STREAM_COLOR)
|
||||
|
||||
class Meta:
|
||||
unique_together = ("user_profile", "recipient")
|
||||
|
||||
|
|
Loading…
Reference in New Issue