From 06a4fa420a6b220d7f6feac773bb9e6302b9b3dc Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 17 Jan 2020 13:26:49 +0100 Subject: [PATCH] Messaging. --- .../management/commands/messaging_send.py | 2 +- .../migrations/0002_auto_20200117_1326.py | 23 +++++++++++++++++++ src/messaging/models.py | 1 + src/messaging/states.py | 11 +++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/messaging/migrations/0002_auto_20200117_1326.py diff --git a/src/messaging/management/commands/messaging_send.py b/src/messaging/management/commands/messaging_send.py index 6fb4a696c..b85957fdc 100644 --- a/src/messaging/management/commands/messaging_send.py +++ b/src/messaging/management/commands/messaging_send.py @@ -9,6 +9,6 @@ class Command(BaseCommand): parser.add_argument('--dry-run', action='store_true', help='Dry run') def handle(self, *args, **options): - for et in EmailTemplate.objects.all(): + for et in EmailTemplate.objects.filter(is_active=True): et.run(verbose=True, dry_run=options['dry_run']) diff --git a/src/messaging/migrations/0002_auto_20200117_1326.py b/src/messaging/migrations/0002_auto_20200117_1326.py new file mode 100644 index 000000000..75bb21a5c --- /dev/null +++ b/src/messaging/migrations/0002_auto_20200117_1326.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.9 on 2020-01-17 12:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('messaging', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='emailtemplate', + name='is_active', + field=models.BooleanField(default=False, verbose_name='active'), + ), + migrations.AlterField( + model_name='emailtemplate', + name='state', + field=models.CharField(choices=[('club-membership-expiring', 'club membership expiring'), ('club-payment-unfinished', 'club payment unfinished'), ('club-recurring-payment-problem', 'club recurring payment problem')], help_text='?', max_length=128, verbose_name='state'), + ), + ] diff --git a/src/messaging/models.py b/src/messaging/models.py index feb5daaa4..c40abbbd9 100644 --- a/src/messaging/models.py +++ b/src/messaging/models.py @@ -13,6 +13,7 @@ class EmailTemplate(models.Model): body = models.TextField(_('body')) days = models.SmallIntegerField(_('days'), null=True, blank=True) hour = models.IntegerField(_('hour'), null=True, blank=True) + is_active = models.BooleanField(_('active'), default=False) class Meta: verbose_name = _('email template') diff --git a/src/messaging/states.py b/src/messaging/states.py index 317be2170..0bb63b442 100644 --- a/src/messaging/states.py +++ b/src/messaging/states.py @@ -56,6 +56,7 @@ class ClubMembershipExpiring(State): def get_hashed_value(self, obj): return '%s:%s' % (obj.pk, obj.expires_at.isoformat()) + class ClubPaymentUnfinished(State): slug = 'club-payment-unfinished' name = _('club payment unfinished') @@ -68,8 +69,18 @@ class ClubPaymentUnfinished(State): ) +class ClubRecurringPaymentProblem(State): + slug = 'club-recurring-payment-problem' + name = _('club recurring payment problem') + + def get_objects(self): + from club.models import Schedule + return Schedule.objects.none() + + states = [ ClubMembershipExpiring, ClubPaymentUnfinished, + ClubRecurringPaymentProblem, ] -- 2.20.1