changeset 1418:25f390d1c829

user.py enhancements: * profiles now can have their keys deleted * safeguard agaisnst rare error in User.__repr__() method
author "Miks Kalnins <MiksKalnins@MaikuMori.com>"
date Wed, 11 Jul 2012 11:35:45 +0300
parents 2a59cb0f0755
children 690fdcf93ac9
files MoinMoin/user.py
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/user.py	Mon Jul 09 12:15:16 2012 +0200
+++ b/MoinMoin/user.py	Wed Jul 11 11:35:45 2012 +0300
@@ -216,6 +216,13 @@
         if value != prev_value:
             self._changed = True
 
+    def __delitem__(self, name):
+        """
+        delete a value, update changed status
+        """
+        del self._meta[name]
+        self._changed = True
+
     def load(self, **q):
         """
         load a user profile, the query q can use any indexed (unique) field
@@ -299,9 +306,13 @@
             self.may = Default(self)
 
     def __repr__(self):
+        # In rare cases we might not have these profile settings when the __repr__ is called.
+        name = getattr(self, NAME, None)
+        itemid = getattr(self, ITEMID, None)
+
         return "<{0}.{1} at {2:#x} name:{3!r} itemid:{4!r} valid:{5!r} trusted:{6!r}>".format(
             self.__class__.__module__, self.__class__.__name__, id(self),
-            self.name, self.itemid, self.valid, self.trusted)
+            name, itemid, self.valid, self.trusted)
 
     def __getattr__(self, name):
         """