~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to lib/common/user.py

  • Committer: mattgiuca
  • Date: 2008-03-07 15:12:02 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:669
Timestamps are now stored within the program as Python "time" module's
    "struct_time" objects, rather than strings directly from the DB.
    They are parsed into struct_time objects when reading from the db.
    They are formatted into SQL Timestamp strings when writing to the db.
    This allows them to be manipulated and compared within the program.

common.db: _escape now accepts struct_time objects - it formats them into SQL
            time strings.
common.user: The User constructor now parses "acct_exp", "pass_exp" and
            "last_login" fields as timestamp strings, and stores them
            internally as struct_time.
tutorialservice: When recording a submission, the "date" field is now stored
            as a struct_time, not a formatted string.
login.py: When logging in, uncommented call to write last_login to the DB,
            passing the current local time. (This now works correctly).
            Note that this is done after retrieving the user details, so the
            value of last_login stored in the session is the _old_ last login,
            not the new one (this is intentional).

(With Tom Conway).

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
# user. Objects of this class are expected to be stored in the request
24
24
# session.
25
25
 
 
26
import db
 
27
import time
26
28
import common.caps
27
29
 
28
30
# Similar to db.login_fields_list but contains a different set of fields.
35
37
    "role", "studentid", "acct_exp", "pass_exp", "last_login",
36
38
    "svn_pass", "local_password",
37
39
)
 
40
timestamp_fields = frozenset((
 
41
    "acct_exp", "pass_exp", "last_login",
 
42
))
38
43
# Fields not included: passhash, last_login
39
44
 
40
45
class UserException(Exception):
70
75
                            "'fullname' missing")
71
76
                else:
72
77
                    self.__setattr__(r, None)
 
78
        for field in timestamp_fields:
 
79
            # Convert all timestamp fields from strings to Timestamp objects
 
80
            if hasattr(self, field):
 
81
                val = self.__getattribute__(field)
 
82
                if val is not None:
 
83
                    val = time.strptime(val, db.TIMESTAMP_FORMAT)
 
84
                    self.__setattr__(field, val)
 
85
 
73
86
    def __repr__(self):
74
87
        items = ["%s=%s" % (r, repr(self.__getattribute__(r)))
75
88
            for r in user_fields_list]