Give the old_subscribers group when subscribing

This commit is contained in:
imperosol 2024-12-03 17:55:21 +01:00
parent 2f9e5bfee1
commit 7bff28ee72
3 changed files with 12 additions and 7 deletions

View File

@ -57,7 +57,7 @@ class Command(BaseCommand):
subscribers = random.sample(users, k=int(0.8 * len(users))) subscribers = random.sample(users, k=int(0.8 * len(users)))
self.stdout.write("Creating subscriptions...") self.stdout.write("Creating subscriptions...")
self.create_subscriptions(users) self.create_subscriptions(subscribers)
self.stdout.write("Creating club memberships...") self.stdout.write("Creating club memberships...")
users_qs = User.objects.filter(id__in=[s.id for s in subscribers]) users_qs = User.objects.filter(id__in=[s.id for s in subscribers])
subscribers_now = list( subscribers_now = list(
@ -103,10 +103,10 @@ class Command(BaseCommand):
self.stdout.write("Done") self.stdout.write("Done")
def create_subscriptions(self, users: list[User]): def create_subscriptions(self, users: list[User]):
def prepare_subscription(user: User, start_date: date) -> Subscription: def prepare_subscription(_user: User, start_date: date) -> Subscription:
payment_method = random.choice(settings.SITH_SUBSCRIPTION_PAYMENT_METHOD)[0] payment_method = random.choice(settings.SITH_SUBSCRIPTION_PAYMENT_METHOD)[0]
duration = random.randint(1, 4) duration = random.randint(1, 4)
sub = Subscription(member=user, payment_method=payment_method) sub = Subscription(member=_user, payment_method=payment_method)
sub.subscription_start = sub.compute_start(d=start_date, duration=duration) sub.subscription_start = sub.compute_start(d=start_date, duration=duration)
sub.subscription_end = sub.compute_end(duration) sub.subscription_end = sub.compute_end(duration)
return sub return sub
@ -130,6 +130,10 @@ class Command(BaseCommand):
user, self.faker.past_date(sub.subscription_end) user, self.faker.past_date(sub.subscription_end)
) )
subscriptions.append(sub) subscriptions.append(sub)
old_subscriber_group = Group.objects.get(
pk=settings.SITH_GROUP_OLD_SUBSCRIBERS_ID
)
old_subscriber_group.users.add(*users)
Subscription.objects.bulk_create(subscriptions) Subscription.objects.bulk_create(subscriptions)
Customer.objects.bulk_create(customers, ignore_conflicts=True) Customer.objects.bulk_create(customers, ignore_conflicts=True)

View File

@ -434,8 +434,6 @@ class User(AbstractUser):
return True return True
if group.id == settings.SITH_GROUP_SUBSCRIBERS_ID: if group.id == settings.SITH_GROUP_SUBSCRIBERS_ID:
return self.is_subscribed return self.is_subscribed
if group.id == settings.SITH_GROUP_OLD_SUBSCRIBERS_ID:
return self.was_subscribed
if group.id == settings.SITH_GROUP_ROOT_ID: if group.id == settings.SITH_GROUP_ROOT_ID:
return self.is_root return self.is_root
if group.is_meta: if group.is_meta:

View File

@ -76,8 +76,11 @@ class Subscription(models.Model):
super().save() super().save()
from counter.models import Customer from counter.models import Customer
_, created = Customer.get_or_create(self.member) _, account_created = Customer.get_or_create(self.member)
if created: if account_created:
# Someone who subscribed once will be considered forever
# as an old subscriber.
self.member.groups.add(settings.SITH_GROUP_OLD_SUBSCRIBERS_ID)
form = PasswordResetForm({"email": self.member.email}) form = PasswordResetForm({"email": self.member.email})
if form.is_valid(): if form.is_valid():
form.save( form.save(