Skip to content

Commit 3a39fc1

Browse files
committed
refactor: remove models __delattr__ methods
1 parent 8b3802d commit 3a39fc1

File tree

4 files changed

+6
-24
lines changed

4 files changed

+6
-24
lines changed

canaille/backends/ldap/ldapobject.py

-7
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,6 @@ def __setattr__(self, name, value):
181181
ldap_name = self.python_attribute_to_ldap(name)
182182
self.set_ldap_attribute(ldap_name, value)
183183

184-
def __delattr__(self, name):
185-
ldap_name = self.python_attribute_to_ldap(name)
186-
self.delete_ldap_attribute(ldap_name)
187-
188184
def has_ldap_attribute(self, name):
189185
return name in self.ldap_object_attributes() and (
190186
name in self.changes or name in self.state
@@ -213,9 +209,6 @@ def set_ldap_attribute(self, name, value):
213209
value = listify(value)
214210
self.changes[name] = value
215211

216-
def delete_ldap_attribute(self, name):
217-
self.changes[name] = [None]
218-
219212
@property
220213
def rdn_value(self):
221214
value = self.get_ldap_attribute(self.rdn_attribute)

canaille/backends/memory/models.py

-11
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,6 @@ def __setattr__(self, name, value):
208208
else:
209209
super().__setattr__(name, value)
210210

211-
def __delattr__(self, name):
212-
try:
213-
del self.state[name]
214-
except KeyError:
215-
pass
216-
217-
try:
218-
del self.cache[name]
219-
except KeyError:
220-
pass
221-
222211
@property
223212
def identifier(self):
224213
return getattr(self, self.identifier_attribute)

canaille/core/account.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def profile_create(current_app, form):
447447
setattr(user, attribute.name, data)
448448

449449
if "photo" in form and form["photo_delete"].data:
450-
del user.photo
450+
user.photo = None
451451

452452
given_name = user.given_name if user.given_name else ""
453453
family_name = user.family_name if user.family_name else ""
@@ -522,7 +522,7 @@ def profile_edition_main_form_validation(user, edited_user, profile_form):
522522
setattr(edited_user, attribute.name, data)
523523

524524
if "photo" in profile_form and profile_form["photo_delete"].data:
525-
del edited_user.photo
525+
edited_user.photo = None
526526

527527
if "preferred_language" in request.form:
528528
# Refresh the babel cache in case the lang is updated
@@ -731,7 +731,7 @@ def profile_settings(user, edited_user):
731731
and edited_user.locked
732732
):
733733
flash(_("The account has been unlocked"), "success")
734-
del edited_user.lock_date
734+
edited_user.lock_date = None
735735
edited_user.save()
736736

737737
return profile_settings_edit(user, edited_user)

tests/core/test_account.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def test_user_password_deleted_during_login(testclient, backend):
217217
res = res.form.submit().follow()
218218
res.form["password"] = "correct horse battery staple"
219219

220-
del u.password
220+
u.password = None
221221
u.save()
222222

223223
res = res.form.submit(status=302)
@@ -362,7 +362,7 @@ def test_account_locking(user, backend):
362362
"Your account has been locked.",
363363
)
364364

365-
del user.lock_date
365+
user.lock_date = None
366366
user.save()
367367
assert not user.locked
368368
assert not models.User.get(id=user.id).locked
@@ -416,7 +416,7 @@ def test_signin_locked_account(testclient, user):
416416
res = res.form.submit()
417417
res.mustcontain("Your account has been locked.")
418418

419-
del user.lock_date
419+
user.lock_date = None
420420
user.save()
421421

422422

0 commit comments

Comments
 (0)