From: Radek Czajka Date: Fri, 17 Jan 2020 12:26:49 +0000 (+0100) Subject: Messaging. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/06a4fa420a6b220d7f6feac773bb9e6302b9b3dc?hp=5b5cf22bf0a6acd75c09f34dbafaea00b3876444 Messaging. --- 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, ]