mirror of
https://github.com/samba-team/samba.git
synced 2025-03-09 08:58:35 +03:00
netcmd: models: add readonly attribute on fields to exclude it from save
There was trouble when saving fields like is system object, these need to be excluded on save. Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
parent
e256a04d5d
commit
6255d57ce8
@ -45,17 +45,20 @@ class Field(metaclass=ABCMeta):
|
||||
but really any field can be a list or single value.
|
||||
"""
|
||||
|
||||
def __init__(self, name, many=False, default=None, hidden=False):
|
||||
def __init__(self, name, many=False, default=None, hidden=False,
|
||||
readonly=False):
|
||||
"""Creates a new field, should be subclassed.
|
||||
|
||||
:param name: Ldb field name.
|
||||
:param many: If true always convert field to a list when loaded.
|
||||
:param default: Default value or callback method (obj is first argument)
|
||||
:param hidden: If this is True, exclude the field when calling as_dict()
|
||||
:param readonly: If true don't write this value when calling save.
|
||||
"""
|
||||
self.name = name
|
||||
self.many = many
|
||||
self.hidden = hidden
|
||||
self.readonly = readonly
|
||||
|
||||
# This ensures that fields with many=True are always lists.
|
||||
# If this is inconsistent anywhere, it isn't so great to use.
|
||||
|
@ -336,7 +336,7 @@ class Model(metaclass=ModelMeta):
|
||||
|
||||
message = Message(dn=self.dn)
|
||||
for attr, field in self.fields.items():
|
||||
if attr != "dn":
|
||||
if attr != "dn" and not field.readonly:
|
||||
value = getattr(self, attr)
|
||||
try:
|
||||
db_value = field.to_db_value(ldb, value, FLAG_MOD_ADD)
|
||||
@ -361,7 +361,7 @@ class Model(metaclass=ModelMeta):
|
||||
# Any fields that are set to None or an empty list get unset.
|
||||
message = Message(dn=self.dn)
|
||||
for attr, field in self.fields.items():
|
||||
if attr != "dn":
|
||||
if attr != "dn" and not field.readonly:
|
||||
value = getattr(self, attr)
|
||||
old_value = getattr(existing_obj, attr)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user