|
2 | 2 | from operator import itemgetter
|
3 | 3 |
|
4 | 4 | from django.contrib.admin.views.decorators import staff_member_required
|
5 |
| -from django.contrib.auth.decorators import login_required, permission_required |
| 5 | +from django.contrib.auth.decorators import login_required, permission_required, user_passes_test |
| 6 | +from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin |
6 | 7 | from django.db.models import Sum
|
7 | 8 | from django.shortcuts import render, get_object_or_404
|
8 | 9 | from django.utils.decorators import method_decorator
|
@@ -35,14 +36,11 @@ def view_month(request, month_pk, month_slug):
|
35 | 36 | month = get_object_or_404(Month, pk=month_pk)
|
36 | 37 | return render(request, 'money/view_month.html', {'month': month})
|
37 | 38 |
|
| 39 | +class SuperuserRequiredMixin(LoginRequiredMixin, UserPassesTestMixin): |
| 40 | + def test_func(self): |
| 41 | + return self.request.user.is_superuser |
38 | 42 |
|
39 |
| -# access to paypal mrr is restricted. only staff can see page. |
40 |
| -# but if u want bigger restrictions, u can uncomment decorator |
41 |
| -# permission_required. but remember to set it for users u want to grant |
42 |
| -@method_decorator(staff_member_required, name='dispatch') |
43 |
| -# @method_decorator(login_required, name='dispatch') |
44 |
| -# @method_decorator(permission_required('money.view_paypalusers', raise_exception=True), name='dispatch') |
45 |
| -class Paypal(View): |
| 43 | +class Paypal(SuperuserRequiredMixin, View): |
46 | 44 | template_name = "paypal_mrr.html"
|
47 | 45 |
|
48 | 46 | def __init__(self):
|
|
0 commit comments