diff --git a/core/management/commands/populate_more.py b/core/management/commands/populate_more.py index f8ac1cef..644296cf 100644 --- a/core/management/commands/populate_more.py +++ b/core/management/commands/populate_more.py @@ -57,7 +57,7 @@ class Command(BaseCommand): subscribers = random.sample(users, k=int(0.8 * len(users))) self.stdout.write("Creating subscriptions...") - self.create_subscriptions(users) + self.create_subscriptions(subscribers) self.stdout.write("Creating club memberships...") users_qs = User.objects.filter(id__in=[s.id for s in subscribers]) subscribers_now = list( @@ -103,10 +103,10 @@ class Command(BaseCommand): self.stdout.write("Done") 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] 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_end = sub.compute_end(duration) return sub @@ -130,6 +130,10 @@ class Command(BaseCommand): user, self.faker.past_date(sub.subscription_end) ) 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) Customer.objects.bulk_create(customers, ignore_conflicts=True) diff --git a/core/models.py b/core/models.py index c8375727..5445f8ee 100644 --- a/core/models.py +++ b/core/models.py @@ -434,8 +434,6 @@ class User(AbstractUser): return True if group.id == settings.SITH_GROUP_SUBSCRIBERS_ID: 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: return self.is_root if group.is_meta: diff --git a/subscription/models.py b/subscription/models.py index 96d77d08..4d68d979 100644 --- a/subscription/models.py +++ b/subscription/models.py @@ -76,8 +76,11 @@ class Subscription(models.Model): super().save() from counter.models import Customer - _, created = Customer.get_or_create(self.member) - if created: + _, account_created = Customer.get_or_create(self.member) + 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}) if form.is_valid(): form.save(