Messaging.
authorRadek Czajka <rczajka@rczajka.pl>
Fri, 17 Jan 2020 12:26:49 +0000 (13:26 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Fri, 17 Jan 2020 12:26:49 +0000 (13:26 +0100)
src/messaging/management/commands/messaging_send.py
src/messaging/migrations/0002_auto_20200117_1326.py [new file with mode: 0644]
src/messaging/models.py
src/messaging/states.py

index 6fb4a69..b85957f 100644 (file)
@@ -9,6 +9,6 @@ class Command(BaseCommand):
         parser.add_argument('--dry-run', action='store_true', help='Dry run')
 
     def handle(self, *args, **options):
         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'])
 
             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 (file)
index 0000000..75bb21a
--- /dev/null
@@ -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'),
+        ),
+    ]
index feb5daa..c40abbb 100644 (file)
@@ -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)
     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')
 
     class Meta:
         verbose_name = _('email template')
index 317be21..0bb63b4 100644 (file)
@@ -56,6 +56,7 @@ class ClubMembershipExpiring(State):
     def get_hashed_value(self, obj):
         return '%s:%s' % (obj.pk, obj.expires_at.isoformat())
 
     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')
 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,
 states = [
     ClubMembershipExpiring,
     ClubPaymentUnfinished,
+    ClubRecurringPaymentProblem,
 ]
 
 ]