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

« back to all changes in this revision

Viewing changes to ivle/database.py

  • Committer: me at id
  • Date: 2009-01-15 04:44:54 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:1157
ivle.database: Add an Enrolment class, and reference(set)s between all of the
    current classes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
import datetime
29
29
 
30
30
from storm.locals import create_database, Store, Int, Unicode, DateTime, \
31
 
                         Reference, Bool
 
31
                         Reference, ReferenceSet, Bool, Storm
32
32
 
33
33
import ivle.conf
34
34
import ivle.caps
55
55
    """
56
56
    return Store(create_database(get_conn_string()))
57
57
 
58
 
class User(object):
 
58
class User(Storm):
59
59
    """
60
60
    Represents an IVLE user.
61
61
    """
77
77
    studentid = Unicode()
78
78
    settings = Unicode()
79
79
 
 
80
    enrolments = ReferenceSet(id, 'Enrolment.user_id')
 
81
 
80
82
    def _get_role(self):
81
83
        if self.rolenm is None:
82
84
            return None
131
133
        """
132
134
        return store.find(cls, cls.login == unicode(login)).one()
133
135
 
134
 
class Subject(object):
 
136
class Subject(Storm):
135
137
    __storm_table__ = "subject"
136
138
 
137
139
    id = Int(primary=True, name="subjectid")
140
142
    short_name = Unicode(name="subj_short_name")
141
143
    url = Unicode()
142
144
 
 
145
    offerings = ReferenceSet(id, 'Offering.subject_id')
 
146
 
143
147
    __init__ = _kwarg_init
144
148
 
145
149
    def __repr__(self):
146
150
        return "<%s '%s'>" % (type(self).__name__, self.short_name)
147
151
 
148
 
class Semester(object):
 
152
class Semester(Storm):
149
153
    __storm_table__ = "semester"
150
154
 
151
155
    id = Int(primary=True, name="semesterid")
153
157
    semester = Unicode()
154
158
    active = Bool()
155
159
 
 
160
    offerings = ReferenceSet(id, 'Offering.semester_id')
 
161
 
156
162
    __init__ = _kwarg_init
157
163
 
158
164
    def __repr__(self):
159
165
        return "<%s %s/%s>" % (type(self).__name__, self.year, self.semester)
160
166
 
161
 
class Offering(object):
 
167
class Offering(Storm):
162
168
    __storm_table__ = "offering"
163
169
 
164
170
    id = Int(primary=True, name="offeringid")
168
174
    semester = Reference(semester_id, Semester.id)
169
175
    groups_student_permissions = Unicode()
170
176
 
 
177
    enrolments = ReferenceSet(id, 'Enrolment.offering_id')
 
178
 
171
179
    __init__ = _kwarg_init
172
180
 
173
181
    def __repr__(self):
174
182
        return "<%s %r in %r>" % (type(self).__name__, self.subject,
175
183
                                  self.semester)
 
184
 
 
185
class Enrolment(Storm):
 
186
    __storm_table__ = "enrolment"
 
187
    __storm_primary__ = "user_id", "offering_id"
 
188
 
 
189
    user_id = Int(name="loginid")
 
190
    user = Reference(user_id, User.id)
 
191
    offering_id = Int(name="offeringid")
 
192
    offering = Reference(offering_id, Offering.id)
 
193
    notes = Unicode()
 
194
    active = Bool()
 
195
 
 
196
    __init__ = _kwarg_init
 
197
 
 
198
    def __repr__(self):
 
199
        return "<%s %r in %r>" % (type(self).__name__, self.user,
 
200
                                  self.offering)