diff --git a/sstreasury/jinja2/sstreasury/budget_print.html b/sstreasury/jinja2/sstreasury/budget_print.html
new file mode 100644
index 0000000..1a5dab5
--- /dev/null
+++ b/sstreasury/jinja2/sstreasury/budget_print.html
@@ -0,0 +1,154 @@
+{% extends 'ssmain/base.html' %}
+
+{#
+ Society Self-Service
+ Copyright © 2018-2019 Yingtong Li (RunasSudo)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+#}
+
+{% block title %}{{ revision.name }}{% endblock %}
+
+{% block content %}
+
{{ revision.name }}
+
+
+
+ {% if not is_latest %}
+
+
You are printing an older version of this budget.
+
+ {% endif %}
+
+
+
+
+ ID |
+ {{ revision.budget.id }} |
+
+
+ Name |
+ {{ revision.name }} |
+
+
+ Due date |
+ {{ revision.date or '' }} |
+
+
+ Contributors |
+
+
+ {% for contributor in revision.contributors.all() %}
+
+ {% endfor %}
+
+ |
+
+
+ Comments |
+ {{ revision.comments }} |
+
+
+ Revenue |
+
+
+ {% if revision.revenue_comments %}
+
+
+
+ Revenue comments
+
+
+ {{ revision.revenue_comments }}
+
+
+ {% endif %}
+ |
+
+
+ Expenses |
+
+ {% if revision.expense_no_emergency_fund %}
+ No emergency fund required (please add a comment explaining why)
+ {% endif %}
+
+ {% if revision.expense_comments %}
+
+
+
+ Expense comments
+
+
+ {{ revision.expense_comments }}
+
+
+ {% endif %}
+ |
+
+
+
+{% endblock %}
+
+{% block head %}
+ {{ super() }}
+
+
+
+
+
+{% endblock %}
+
+{% block script %}
+ {{ super() }}
+
+
+
+
+
+
+{% endblock %}
diff --git a/sstreasury/jinja2/sstreasury/budget_view.html b/sstreasury/jinja2/sstreasury/budget_view.html
index 16e9ec0..44f5f2e 100644
--- a/sstreasury/jinja2/sstreasury/budget_view.html
+++ b/sstreasury/jinja2/sstreasury/budget_view.html
@@ -23,10 +23,10 @@
{% block maincontent %}
{{ revision.name }}
- {% if is_latest %}
-
- {% else %}
-
-
You are viewing an older version of this budget. To make any changes, click here to return to the current version.
-
- {% endif %}
+ {% else %}
+ Print
+
+
+
You are viewing an older version of this budget. To make any changes, click here to return to the current version.
+
+ {% endif %}
+
diff --git a/sstreasury/urls.py b/sstreasury/urls.py
index 68aa07b..4165d72 100644
--- a/sstreasury/urls.py
+++ b/sstreasury/urls.py
@@ -22,6 +22,7 @@ urlpatterns = [
path('budgets/', views.budget_list, name='budget_list'),
path('budgets/new/', views.budget_new, name='budget_new'),
path('budgets/view/', views.budget_view, name='budget_view'),
+ path('budgets/view//print', views.budget_print, name='budget_print'),
path('budgets/edit/', views.budget_edit, name='budget_edit'),
path('budgets/action/', views.budget_action, name='budget_action'),
path('', views.index, name='treasury'),
diff --git a/sstreasury/views.py b/sstreasury/views.py
index c0153cc..ae4c7b1 100644
--- a/sstreasury/views.py
+++ b/sstreasury/views.py
@@ -85,6 +85,10 @@ def budget_view(request, id):
else:
revision = budget.budgetrevision_set.reverse()[0]
+ if request.user not in revision.contributors.all():
+ if not request.user.groups.filter(name='Treasury').exists():
+ raise PermissionDenied
+
history = list(itertools.chain(budget.budgetrevision_set.all(), revision.budget.budgetcomment_set.all()))
history.sort(key=lambda x: x.time, reverse=True)
@@ -94,6 +98,24 @@ def budget_view(request, id):
'is_latest': 'revision' not in request.GET
})
+@login_required
+def budget_print(request, id):
+ budget = models.Budget.objects.get(id=id)
+
+ if 'revision' in request.GET:
+ revision = budget.budgetrevision_set.get(id=int(request.GET['revision']))
+ else:
+ revision = budget.budgetrevision_set.reverse()[0]
+
+ if request.user not in revision.contributors.all():
+ if not request.user.groups.filter(name='Treasury').exists():
+ raise PermissionDenied
+
+ return render(request, 'sstreasury/budget_print.html', {
+ 'revision': revision,
+ 'is_latest': 'revision' not in request.GET
+ })
+
def revision_from_form(budget, revision, form):
revision.budget = budget