Verified Commit be7b223a authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Prevent saving accepted/rejected model

parent a13abe14
......@@ -155,10 +155,11 @@ class RegistrationAdmin(admin.ModelAdmin):
"""Does the user have the review permission?"""
return request.user.has_perm('registrations.review_entries')
def has_change_permission(self, request, obj=None):
if (obj and obj.status == Registration.STATUS_REVIEW) or not obj:
return super().has_change_permission(request, obj)
return False
def save_model(self, request, obj, form, change):
if not (obj.status == Entry.STATUS_REJECTED or
obj.status == Entry.STATUS_ACCEPTED or
obj.status == Entry.STATUS_COMPLETED):
super().save_model(request, obj, form, change)
@admin.register(Renewal)
......@@ -185,6 +186,7 @@ class RenewalAdmin(RegistrationAdmin):
'member',)
}),
)
actions = RegistrationAdmin.actions
def get_readonly_fields(self, request, obj=None):
"""Make all fields read-only and add member if needed"""
......
......@@ -11,6 +11,7 @@ from django.utils.translation import ugettext_lazy as _
from members.models import Member
from payments.models import Payment
from payments.widgets import PaymentWidget
from registrations import admin
from registrations.models import Entry, Registration, Renewal
......@@ -300,6 +301,50 @@ class RegistrationAdminTest(TestCase):
reg.payment = None
self.assertEqual(self.admin.payment_status(reg), '-')
def test_formfield_for_dbfield(self):
with self.subTest('Payment field'):
field = self.admin.formfield_for_dbfield(
Registration._meta.get_field('payment'), request=None)
self.assertIsInstance(field.widget, PaymentWidget)
with self.subTest('Other field'):
field = self.admin.formfield_for_dbfield(
Registration._meta.get_field('first_name'), request=None)
self.assertNotIsInstance(field.widget, PaymentWidget)
self.assertIsNotNone(field.widget)
def test_save_model(self):
reg = Registration(
status=Registration.STATUS_REVIEW,
birthday=timezone.now()
)
with self.subTest('Status review saves'):
reg.first_name = 'Test1'
self.admin.save_model({}, reg, None, True)
self.assertTrue(
Registration.objects.filter(first_name='Test1').exists())
with self.subTest('Status accepted, no save'):
reg.first_name = 'Test2'
reg.status = Registration.STATUS_ACCEPTED
self.admin.save_model({}, reg, None, True)
self.assertFalse(
Registration.objects.filter(first_name='Test2').exists())
with self.subTest('Status reject, no save'):
reg.first_name = 'Test2'
reg.status = Registration.STATUS_REJECTED
self.admin.save_model({}, reg, None, True)
self.assertFalse(
Registration.objects.filter(first_name='Test2').exists())
with self.subTest('Status completed, no save'):
reg.first_name = 'Test2'
reg.status = Registration.STATUS_COMPLETED
self.admin.save_model({}, reg, None, True)
self.assertFalse(
Registration.objects.filter(first_name='Test2').exists())
class RenewalAdminTest(TestCase):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment