def __delitem__(self, key):
del self._store[key]
+ def read_post_and_session(self, post, session, key):
+ '''Read an attribute into self, from either POST or the session,
+ and synchronize the session with the POST value when there is a POST
+ value.
+
+ post POST
+ session The session
+ key The attribute to read
+
+ Returns: Boolean. True when a value is set; the key is in
+ either POST or the session.
+ '''
+ if key in post:
+ self[key] = post[key]
+ self.session_put(key, self[key])
+ elif key in session:
+ self[key] = session[key]
+ else:
+ return False
+ return True
+
def read(self):
'''
In the children this loads form from pyramid self.uh.request
# Defaults are now in place in self._form for password
# and user. Ignore these since we want to know whether
# to go to the session for data values.
- if 'password' in post:
- self['password'] = post['password']
- self.session_put('password', self['password'])
- elif 'password' in session:
- self['password'] = session['password']
-
- if 'user' in post:
- self['user'] = post['user']
- self.session_put('user', self['user'])
- elif 'user' in session:
- self['user'] = session['user']
- else:
+ self.read_post_and_session(post, session, 'password')
+
+ if not self.read_post_and_session(post, session, 'user'):
self['user'] = ''
# Other, hidden, POST variables