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

« back to all changes in this revision

Viewing changes to ivle/database.py

  • Committer: matt.giuca
  • Date: 2009-01-14 07:24:15 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:branches%2Fstorm:1129
ivle.database: Added User class.
    This is distinct from (and intended to replace) ivle.db.User.
    Sorry for the intermittent confusion.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
It also provides miscellaneous utility functions for database interaction.
25
25
"""
26
26
 
27
 
from storm.locals import create_database, Store
 
27
from storm.locals import create_database, Store, Int, Unicode, DateTime, \
 
28
                         Reference
28
29
 
29
30
import ivle.conf
 
31
import ivle.caps
30
32
 
31
33
def get_conn_string():
32
34
    """
42
44
    instance connected to the configured IVLE database.
43
45
    """
44
46
    return Store(create_database(get_conn_string()))
 
47
 
 
48
class User(object):
 
49
    """
 
50
    Represents an IVLE user.
 
51
    """
 
52
    __storm_table__ = "login"
 
53
 
 
54
    id = Int(primary=True, name="loginid")
 
55
    login = Unicode()
 
56
    passhash = Unicode()
 
57
    state = Unicode()
 
58
    rolenm = Unicode()
 
59
    unixid = Int()
 
60
    nick = Unicode()
 
61
    pass_exp = DateTime()
 
62
    acct_exp = DateTime()
 
63
    last_login = DateTime()
 
64
    svn_pass = Unicode()
 
65
    email = Unicode()
 
66
    fullname = Unicode()
 
67
    studentid = Unicode()
 
68
    settings = Unicode()
 
69
 
 
70
    def _get_role(self):
 
71
        if self.rolenm is None:
 
72
            return None
 
73
        return ivle.caps.Role(self.rolenm)
 
74
    def _set_role(self, value):
 
75
        if not isinstance(value, ivle.caps.Role):
 
76
            raise TypeError("role must be an ivle.caps.Role")
 
77
        self.rolenm = unicode(value)
 
78
    role = property(_get_role, _set_role)
 
79
 
 
80
    def __init__(self, **kwargs):
 
81
        """
 
82
        Create a new User object. Supply any columns as a keyword argument.
 
83
        """
 
84
        for k,v in kwargs.items():
 
85
            if k.startswith('_') or not hasattr(self, k):
 
86
                raise TypeError("User got an unexpected keyword argument '%s'"
 
87
                    % k)
 
88
            setattr(self, k, v)
 
89
 
 
90
    def __repr__(self):
 
91
        return "<%s '%s'>" % (type(self).__name__, self.login)