Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

renaming sign_off to immutable_lock

  • Loading branch information...
commit 9ed3129c3df9dfc27ae56398058cf60d36b2e6a4 1 parent a4bafb3
Tim Diggins authored
5 README.rst
View
@@ -156,7 +156,7 @@ Reference
class ImmutableMeta:
immutable_quiet = False
- ``immutable_signoff_field``
+ ``immutable_lock_field``
This determines when to enforce immutability. By default it is equal to immutable_model.models.PK_FIELD.
This means that when the PK_FIELD is full (typically when saved) the model is immutable, but before it is
@@ -165,7 +165,7 @@ Reference
immutable fields once they are set (even before saving).
class ImmutableMeta:
- immutable_signoff_field = ['is_locked']
+ immutable_lock_field = ['is_locked']
**settings.py**
@@ -175,4 +175,3 @@ Reference
Set this to ``False`` to make all immutable_fields raise an Exception when attempting
to be changed.
-*#TODO: Need to document skandal's signoff_field (rename to lock_field)*
22 immutablefield/admin.py
View
@@ -3,20 +3,20 @@
class ImmutableModelAdmin(admin.ModelAdmin):
save_as = True
- fields = ('sign_off',)
+ fields = ('immutable_lock',)
- def _validate_and_check_immutable_sign_off_request(self, request, obj):
- if 'sign_off' in request.POST and request.POST['sign_off'] == 'on':
+ def _validate_and_check_immutable_immutable_lock_request(self, request, obj):
+ if 'immutable_lock' in request.POST and request.POST['immutable_lock'] == 'on':
try:
- setattr(obj, obj._meta.immutable_sign_off_field, True)
+ setattr(obj, obj._meta.immutable_lock_field, True)
except AttributeError:
pass
obj.save()
def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
- if not obj is None and obj.is_signed_off():
- context['adminform'].form.fields['sign_off'].widget.attrs['disabled'] = True
+ if not obj is None and obj.is_immutable():
+ context['adminform'].form.fields['immutable_lock'].widget.attrs['disabled'] = True
return super(ImmutableModelAdmin, self).render_change_form(
request,
@@ -38,7 +38,7 @@ def change_view(self, request, object_id, extra_context=None):
if '_saveasnew' in request.POST:
request.method = 'GET'
try:
- signed_off_field_name = obj._meta.immutable_sign_off_field
+ signed_off_field_name = obj._meta.immutable_lock_field
except AttributeError:
signed_off_field_name = ""
@@ -84,7 +84,7 @@ def reload_obj():
if not obj is None:
# We'r chaging the obj
try:
- signed_off_field_name = obj._meta.immutable_sign_off_field
+ signed_off_field_name = obj._meta.immutable_lock_field
except AttributeError:
return self.readonly_fields
else:
@@ -96,7 +96,7 @@ def reload_obj():
def has_delete_permission(self, request, obj=None):
try:
- return obj.immutable_is_deletable or not obj.is_signed_off()
+ return obj.immutable_is_deletable or not obj.is_immutable()
except AttributeError:
#Ok if it doesn't have signofability
return super(ImmutableModelAdmin, self).has_delete_permission(
@@ -106,12 +106,12 @@ def has_delete_permission(self, request, obj=None):
def response_change(self, request, obj):
response = super(ImmutableModelAdmin, self).response_change(request,obj)
- self._validate_and_check_immutable_sign_off_request(request, obj)
+ self._validate_and_check_immutable_immutable_lock_request(request, obj)
return response
def response_add(self, request, obj):
response = super(ImmutableModelAdmin, self).response_add(request,obj)
- self._validate_and_check_immutable_sign_off_request(request, obj)
+ self._validate_and_check_immutable_immutable_lock_request(request, obj)
return response
46 immutablefield/models.py
View
@@ -35,7 +35,7 @@ class PK_FIELD: pass
FieldsOption('mutable_fields'),
FieldsOption('immutable_fields'),
QuietOption('immutable_quiet'),
- Option('immutable_sign_off_field', default=PK_FIELD),
+ Option('immutable_lock_field', default=PK_FIELD),
Option('immutable_is_deletable', default=True),
)])
@@ -91,14 +91,14 @@ def check_options(model):
# we don't need the list of immutable_fields anymore -- only used for specifying
del model._meta.immutable_fields
- if model._meta.immutable_sign_off_field is PK_FIELD:
- model._meta.immutable_sign_off_field = model._meta.pk.name
- elif (isinstance(model._meta.immutable_sign_off_field, basestring) or
- model._meta.immutable_sign_off_field is None
+ if model._meta.immutable_lock_field is PK_FIELD:
+ model._meta.immutable_lock_field = model._meta.pk.name
+ elif (isinstance(model._meta.immutable_lock_field, basestring) or
+ model._meta.immutable_lock_field is None
):
pass
else:
- raise TypeError('immutable_sign_off_field attribute in '
+ raise TypeError('immutable_lock_field attribute in '
'%s must be a string (or None, or omitted)' % model)
@@ -114,7 +114,7 @@ class ImmutableModel(models.Model):
__metaclass__ = ImmutableModelMeta
def can_change_field(self, field_name):
- return field_name in self._meta.mutable_fields or not self.is_signed_off()
+ return field_name in self._meta.mutable_fields or not self.is_immutable()
def __setattr__(self, name, value):
if not self.can_change_field(name):
@@ -130,47 +130,35 @@ def __setattr__(self, name, value):
raise ValueError('%s is immutable and cannot be changed' % name)
super(ImmutableModel, self).__setattr__(name, value)
- def _not_signed_off_error(self):
- return u'In order to sign off, %s needs to be Signed Off' % (str(self),)
-
- def obstacles_for_signoff(self, dict=None):
- if self.has_sign_off_field():
- errors = {}
- return errors
- else:
- raise ImproperlyConfigured(
- u"Can't check signoffbility of a model without a signoff field."
- )
-
- def is_signed_off(self):
- if self.has_sign_off_field():
+ def is_immutable(self):
+ if self.has_immutable_lock_field():
"""
During the creation of a Django ORM object, as far as we know,
the object starts with no fields and they are added after the object
creation. This leads to an object with some fields created and some
fields to create.
- In the presence of a sign_off field decision,
+ In the presence of a immutable_lock field decision,
if the field does not exists, it can be changed.
"""
- return getattr(self, self._meta.immutable_sign_off_field, True)
+ return getattr(self, self._meta.immutable_lock_field, True)
return True
- def has_sign_off_field(self):
- return self._meta.immutable_sign_off_field != None
+ def has_immutable_lock_field(self):
+ return self._meta.immutable_lock_field != None
- def field_has_sign_off_field(self, field):
+ def field_has_immutable_lock_field(self, field):
if hasattr(field, '_meta'):
- return hasattr(field._meta, 'immutable_sign_off_field')
+ return hasattr(field._meta, 'immutable_lock_field')
else:
return False
def delete(self):
- if not self._meta.immutable_is_deletable and self.is_signed_off():
+ if not self._meta.immutable_is_deletable and self.is_immutable():
if self._meta.immutable_quiet:
return
else:
raise CantDeleteImmutableException(
- "%s is signed_off and cannot be deleted" % self
+ "%s is immutable and cannot be deleted" % self
)
super(ImmutableModel, self).delete()
116 tests/test_immutablemodel.py
View
@@ -67,10 +67,10 @@ def setUp(self):
self.obj = SimpleSignOffField.objects.create(
special_id=1,
name='Yoda',
- sign_off=False,
+ is_locked=False,
)
- def test__simple_not_signed_off(self):
+ def test__simple_not_locked(self):
self.assertEqual(self.obj.special_id, 1)
self.assertEqual(self.obj.name, 'Yoda')
@@ -80,14 +80,14 @@ def test__simple_not_signed_off(self):
db_object = SimpleSignOffField.objects.all()[0]
- # Should change, since the signed-off field is false
+ # Should change, since the lock field is false
self.assertEqual(self.obj.special_id, 1337)
self.assertEqual(self.obj.name, 'Obi-Wan')
self.assertEqual(db_object.special_id, 1337)
self.assertEqual(db_object.name, 'Obi-Wan')
- def test__simple_signed_off(self):
- self.obj.sign_off = True
+ def test__simple_locked(self):
+ self.obj.is_locked = True
self.obj.save()
self.obj.special_id = 1337
@@ -96,24 +96,24 @@ def test__simple_signed_off(self):
db_object = SimpleSignOffField.objects.all()[0]
- # Should not change, since the signed-off field is true
+ # Should not change, since the lock field is true
# Of course, that name is still changable
self.assertEqual(self.obj.special_id, 1)
self.assertEqual(self.obj.name, 'Obi-Wan')
- self.assertEqual(self.obj.sign_off, True)
+ self.assertEqual(self.obj.is_locked, True)
self.assertEqual(db_object.special_id, 1)
self.assertEqual(db_object.name, 'Obi-Wan')
- self.assertEqual(db_object.sign_off, True)
+ self.assertEqual(db_object.is_locked, True)
- def test__delete_not_signed_off(self):
+ def test__delete_not_locked(self):
self.obj.delete()
self.assertEqual(
0,
len(SimpleSignOffField.objects.all()),
)
- def test__delete_signed_off(self):
- self.obj.sign_off = True
+ def test__delete_locked(self):
+ self.obj.is_locked = True
self.obj.save()
self.obj.delete()
self.assertEqual(
@@ -125,12 +125,12 @@ def test__delete_signed_off(self):
class Case04_CanCreateModelSignOffFieldInAnyOrderTest(TestCase):
def setUp(self):
self.obj = ComplexSignOffField.objects.create(
- sign_off=False,
+ is_locked=False,
special_id=1,
name='Yoda',
)
- def test__simple_not_signed_off(self):
+ def test__simple_not_locked(self):
self.assertEqual(self.obj.special_id, 1)
self.assertEqual(self.obj.name, 'Yoda')
@@ -140,14 +140,14 @@ def test__simple_not_signed_off(self):
db_object = ComplexSignOffField.objects.all()[0]
- # Should change, since the signed-off field is false
+ # Should change, since the lock field is false
self.assertEqual(self.obj.special_id, 1337)
self.assertEqual(self.obj.name, 'Obi-Wan')
self.assertEqual(db_object.special_id, 1337)
self.assertEqual(db_object.name, 'Obi-Wan')
- def test__simple_signed_off(self):
- self.obj.sign_off = True
+ def test__simple_locked(self):
+ self.obj.is_locked = True
self.obj.save()
self.obj.special_id = 1337
@@ -156,61 +156,61 @@ def test__simple_signed_off(self):
db_object = ComplexSignOffField.objects.all()[0]
- # Should not change, since the signed-off field is true
+ # Should not change, since the lock field is true
# Of course, that name is still changable
self.assertEqual(self.obj.special_id, 1)
self.assertEqual(self.obj.name, 'Obi-Wan')
- self.assertEqual(self.obj.sign_off, True)
+ self.assertEqual(self.obj.is_locked, True)
self.assertEqual(db_object.special_id, 1)
self.assertEqual(db_object.name, 'Obi-Wan')
- self.assertEqual(db_object.sign_off, True)
+ self.assertEqual(db_object.is_locked, True)
- def test__sign_off_field_true_at_create(self):
- sign_off_true_at_first = ComplexSignOffField.objects.create(
- sign_off=True,
+ def test__lock_field_true_at_create(self):
+ is_locked_at_first = ComplexSignOffField.objects.create(
+ is_locked=True,
special_id=100,
name='Yoda',
)
self.assertEqual(
- sign_off_true_at_first.special_id,
+ is_locked_at_first.special_id,
100,
)
self.assertEqual(
- sign_off_true_at_first.sign_off,
+ is_locked_at_first.is_locked,
True,
)
self.assertEqual(
- sign_off_true_at_first.name,
+ is_locked_at_first.name,
'Yoda',
)
- sign_off_true_at_first.special_id = 1337
- sign_off_true_at_first.name = 'Obi-Wan'
- sign_off_true_at_first.save()
+ is_locked_at_first.special_id = 1337
+ is_locked_at_first.name = 'Obi-Wan'
+ is_locked_at_first.save()
db_object = ComplexSignOffField.objects.get(special_id=100)
- # Should not change, since the signed-off field is true
+ # Should not change, since the lock field is true
# Of course, that name is still changable
- self.assertEqual(sign_off_true_at_first.special_id, 100)
- self.assertEqual(sign_off_true_at_first.name, 'Obi-Wan')
- self.assertEqual(sign_off_true_at_first.sign_off, True)
+ self.assertEqual(is_locked_at_first.special_id, 100)
+ self.assertEqual(is_locked_at_first.name, 'Obi-Wan')
+ self.assertEqual(is_locked_at_first.is_locked, True)
self.assertEqual(db_object.special_id, 100)
self.assertEqual(db_object.name, 'Obi-Wan')
- self.assertEqual(db_object.sign_off, True)
+ self.assertEqual(db_object.is_locked, True)
- def test__delete_not_signed_off(self):
+ def test__delete_not_locked(self):
self.obj.delete()
self.assertEqual(
0,
len(ComplexSignOffField.objects.all()),
)
- def test__delete_signed_off(self):
- self.obj.sign_off = True
+ def test__delete_locked(self):
+ self.obj.is_locked = True
self.obj.save()
self.obj.delete()
self.assertEqual(
@@ -233,10 +233,10 @@ def test_no_delete(self):
class Case06_WillRaiseErrorsTest(TestCase):
def setUp(self):
- self.no_sign_off_field = NoisyNoSignOffField.objects.create(
+ self.no_lock_field = NoisyNoSignOffField.objects.create(
special_id=1,
)
- self.sign_off_field = NoisySignOffField.objects.create(
+ self.lock_field = NoisySignOffField.objects.create(
special_id=5,
)
self.not_deletable_noisy = NoisyNotDeletable.objects.create(
@@ -244,50 +244,50 @@ def setUp(self):
)
def test__simple(self):
- self.assertEqual(self.no_sign_off_field.special_id, 1)
- self.assertEqual(self.sign_off_field.special_id, 5)
+ self.assertEqual(self.no_lock_field.special_id, 1)
+ self.assertEqual(self.lock_field.special_id, 5)
self.assertRaises( ValueError,
setattr,
- self.no_sign_off_field,
+ self.no_lock_field,
'special_id', 1337,
)
- self.sign_off_field.special_id = 1000
- self.sign_off_field.sign_off = True
- self.sign_off_field.save()
+ self.lock_field.special_id = 1000
+ self.lock_field.is_locked = True
+ self.lock_field.save()
self.assertRaises( ValueError,
setattr,
- self.sign_off_field,
+ self.lock_field,
'special_id', 1337,
)
- def test__sign_off_field_true_at_create(self):
- sign_off_true_at_first = NoisySignOffField.objects.create(
- sign_off=True,
+ def test__lock_field_true_at_create(self):
+ is_locked_at_first = NoisySignOffField.objects.create(
+ is_locked=True,
special_id=1,
)
self.assertEqual(
- sign_off_true_at_first.special_id,
+ is_locked_at_first.special_id,
1,
)
self.assertEqual(
- sign_off_true_at_first.sign_off,
+ is_locked_at_first.is_locked,
True,
)
self.assertRaises( ValueError,
setattr,
- sign_off_true_at_first,
+ is_locked_at_first,
'special_id', 1337,
)
- def test__delete_not_signed_off(self):
- self.no_sign_off_field.delete()
- self.sign_off_field.delete()
+ def test__delete_not_locked(self):
+ self.no_lock_field.delete()
+ self.lock_field.delete()
self.assertRaises(
CantDeleteImmutableException,
@@ -302,10 +302,10 @@ def test__delete_not_signed_off(self):
len(NoisySignOffField.objects.all()),
)
- def test__delete_signed_off(self):
- self.sign_off_field.sign_off = True
- self.sign_off_field.save()
- self.sign_off_field.delete()
+ def test__delete_locked(self):
+ self.lock_field.is_locked = True
+ self.lock_field.save()
+ self.lock_field.delete()
self.assertEqual(
0,
len(NoisySignOffField.objects.all()),
12 tests/testapp/models.py
View
@@ -15,21 +15,21 @@ class Meta:
class SimpleSignOffField(ImmutableModel):
special_id = models.IntegerField()
name = models.CharField(max_length=50)
- sign_off = models.BooleanField(default=False)
+ is_locked = models.BooleanField(default=False)
class Meta:
immutable_fields = ['special_id']
- immutable_sign_off_field = 'sign_off'
+ immutable_lock_field = 'is_locked'
class ComplexSignOffField(ImmutableModel):
- sign_off = models.BooleanField(default=True)
+ is_locked = models.BooleanField(default=True)
special_id = models.IntegerField()
name = models.CharField(max_length=50)
class Meta:
immutable_fields = ['special_id']
- immutable_sign_off_field = 'sign_off'
+ immutable_lock_field = 'is_locked'
class NoisyNoSignOffField(ImmutableModel):
@@ -42,11 +42,11 @@ class Meta:
class NoisySignOffField(ImmutableModel):
special_id = models.IntegerField()
- sign_off = models.BooleanField(default=False)
+ is_locked = models.BooleanField(default=False)
class Meta:
immutable_fields = ['special_id']
- immutable_sign_off_field = 'sign_off'
+ immutable_lock_field = 'is_locked'
immutable_quiet = False
Please sign in to comment.
Something went wrong with that request. Please try again.