From 098683b761e1cc67fee2d20e83971e4c7806c787 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= <jan.bednarik@gmail.com>
Date: Thu, 27 Aug 2020 15:29:10 +0200
Subject: [PATCH] donate: Option to enable periodic donations for projects

---
 ...ateprojectpage_allow_periodic_donations.py | 20 +++++++++++++++++++
 donate/models.py                              |  8 +++++++-
 .../templates/donate/donate_project_page.html |  6 +++++-
 3 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 donate/migrations/0009_donateprojectpage_allow_periodic_donations.py

diff --git a/donate/migrations/0009_donateprojectpage_allow_periodic_donations.py b/donate/migrations/0009_donateprojectpage_allow_periodic_donations.py
new file mode 100644
index 00000000..18d75d6d
--- /dev/null
+++ b/donate/migrations/0009_donateprojectpage_allow_periodic_donations.py
@@ -0,0 +1,20 @@
+# Generated by Django 3.0.9 on 2020-08-27 12:57
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("donate", "0008_auto_20200826_0021"),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name="donateprojectpage",
+            name="allow_periodic_donations",
+            field=models.BooleanField(
+                default=False, verbose_name="umožnit pravidelné dary"
+            ),
+        ),
+    ]
diff --git a/donate/models.py b/donate/models.py
index f403a55f..d709dcfc 100644
--- a/donate/models.py
+++ b/donate/models.py
@@ -351,6 +351,9 @@ class DonateProjectPage(DonateFormMixin, Page, SubpageMixin, MetadataPageMixin):
     perex = models.TextField("krátký popis")
     body = RichTextField("obsah")
     is_new = models.BooleanField('označení "nový projekt"', default=False)
+    allow_periodic_donations = models.BooleanField(
+        "umožnit pravidelné dary", default=False
+    )
     photo = models.ForeignKey(
         "wagtailimages.Image",
         verbose_name="fotka",
@@ -401,7 +404,10 @@ class DonateProjectPage(DonateFormMixin, Page, SubpageMixin, MetadataPageMixin):
     ]
 
     settings_panels = Page.settings_panels + [
-        FieldPanel("portal_project_id"),
+        MultiFieldPanel(
+            [FieldPanel("portal_project_id"), FieldPanel("allow_periodic_donations"),],
+            "nastavení darů",
+        ),
     ]
 
     ### RELATIONS
diff --git a/donate/templates/donate/donate_project_page.html b/donate/templates/donate/donate_project_page.html
index b6e88d85..f80bed62 100644
--- a/donate/templates/donate/donate_project_page.html
+++ b/donate/templates/donate/donate_project_page.html
@@ -108,6 +108,7 @@
                         </div>
                       </div>
                   </div>
+                  {% if page.allow_periodic_donations %}
                   <div class="form-group row mb-4 align-items-center">
                       <legend class="col-form-label col-md-12 col-form-label-lg">Typ příspěvku</legend>
                       <div class="col-md-12">
@@ -121,7 +122,10 @@
                           </div>
                       </div>
                   </div>
-                  <div class="form-group row mb-0">
+                  {% else %}
+                  <input type="hidden" name="periodicity" value="99999">
+                  {% endif %}
+                  <div class="form-group row mb-0 mt-4">
                     <div class="col-12">
                       <button type="submit" class="btn btn-danger btn-lg">Darovat</button>
                     </div>
-- 
GitLab