From d9e3ec3a399a943f22a28e741e8f01f2481f27fb Mon Sep 17 00:00:00 2001
From: "J.-S. Caux" <J.S.Caux@uva.nl>
Date: Wed, 5 Dec 2018 19:23:22 +0100
Subject: [PATCH] Add way of making subsidy amount hidden from public

---
 finances/forms.py                             |  3 ++-
 .../0008_subsidy_amount_publicly_shown.py     | 20 +++++++++++++++++++
 finances/models.py                            |  1 +
 .../templates/finances/_subsidy_card.html     |  2 +-
 finances/templates/finances/subsidy_list.html |  2 +-
 finances/views.py                             |  2 +-
 6 files changed, 26 insertions(+), 4 deletions(-)
 create mode 100644 finances/migrations/0008_subsidy_amount_publicly_shown.py

diff --git a/finances/forms.py b/finances/forms.py
index 70ac25a24..7786bd894 100644
--- a/finances/forms.py
+++ b/finances/forms.py
@@ -21,7 +21,8 @@ class SubsidyForm(forms.ModelForm):
     class Meta:
         model = Subsidy
         fields = ['organization', 'subsidy_type', 'description',
-                  'amount', 'status', 'date', 'date_until']
+                  'amount', 'amount_publicly_shown', 'status',
+                  'date', 'date_until']
 
 
 class WorkLogForm(forms.ModelForm):
diff --git a/finances/migrations/0008_subsidy_amount_publicly_shown.py b/finances/migrations/0008_subsidy_amount_publicly_shown.py
new file mode 100644
index 000000000..a13a33679
--- /dev/null
+++ b/finances/migrations/0008_subsidy_amount_publicly_shown.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.4 on 2018-12-05 18:07
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('finances', '0007_auto_20181011_2146'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='subsidy',
+            name='amount_publicly_shown',
+            field=models.BooleanField(default=True),
+        ),
+    ]
diff --git a/finances/models.py b/finances/models.py
index f7755ead7..c6cd60606 100644
--- a/finances/models.py
+++ b/finances/models.py
@@ -36,6 +36,7 @@ class Subsidy(models.Model):
     subsidy_type = models.CharField(max_length=256, choices=SUBSIDY_TYPES)
     description = models.TextField()
     amount = models.PositiveIntegerField(help_text="in &euro; (rounded)")
+    amount_publicly_shown = models.BooleanField(default=True)
     status = models.CharField(max_length=32, choices=SUBSIDY_STATUS)
     date = models.DateField()
     date_until = models.DateField(blank=True, null=True)
diff --git a/finances/templates/finances/_subsidy_card.html b/finances/templates/finances/_subsidy_card.html
index 21b131fbc..e7168adcd 100644
--- a/finances/templates/finances/_subsidy_card.html
+++ b/finances/templates/finances/_subsidy_card.html
@@ -25,7 +25,7 @@
 	  <td>Description:</td><td>{{ subsidy.description }}</td>
 	</tr>
 	<tr>
-	  <td>Amount:</td><td>&euro;{{ subsidy.amount }}</td>
+	  <td>Amount:</td><td>{% if subsidy.amount_publicly_shown or perms.scipost.can_manage_subsidies %}&euro;{{ subsidy.amount }}{% else %}-{% endif %}</td>
 	</tr>
 	<tr>
 	  <td>Date:</td><td>{{ subsidy.date }}</td>
diff --git a/finances/templates/finances/subsidy_list.html b/finances/templates/finances/subsidy_list.html
index 6fcbb6e74..e8a11c932 100644
--- a/finances/templates/finances/subsidy_list.html
+++ b/finances/templates/finances/subsidy_list.html
@@ -72,7 +72,7 @@ $(document).ready(function($) {
 	<tr class="table-row" data-href="{% url 'finances:subsidy_details' pk=subsidy.id %}" style="cursor: pointer;">
 	  <td>{{ subsidy.organization }}</td>
 	  <td>{{ subsidy.get_subsidy_type_display }}</td>
-	  <td>&euro;{{ subsidy.amount }}</td>
+	  <td>{% if subsidy.amount_publicly_shown or perms.scipost.can_manage_subsidies %}&euro;{{ subsidy.amount }}{% else %}-{% endif %}</td>
 	  <td>{{ subsidy.date }}</td>
 	</tr>
 	{% empty %}
diff --git a/finances/views.py b/finances/views.py
index 8c574883a..6b43fd16b 100644
--- a/finances/views.py
+++ b/finances/views.py
@@ -66,7 +66,7 @@ class SubsidyListView(ListView):
         order_by = self.request.GET.get('order_by')
         ordering = self.request.GET.get('ordering')
         if order_by == 'amount':
-            qs = qs.order_by('amount')
+            qs = qs.filter(amount_publicly_shown=True).order_by('amount')
         elif order_by == 'date':
             qs = qs.order_by('date')
         if ordering == 'desc':
-- 
GitLab