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

« back to all changes in this revision

Viewing changes to ivle/database.py

  • Committer: William Grant
  • Date: 2009-01-19 03:28:41 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: grantw@unimelb.edu.au-20090119032841-xi3tumooiurvz80u
ivle.database: Add ProjectSet, Project, ProjectGroup, ProjectGroupMembership
    database classes, and methods and properties to get a User's groups.

Show diffs side-by-side

added added

removed removed

Lines of Context:
139
139
            Offering.id == Enrolment.offering_id,
140
140
            Subject.id == Offering.subject_id).config(distinct=True)
141
141
 
 
142
    # TODO: Invitations should be listed too?
 
143
    def get_groups(self, offering=None):
 
144
        preds = [
 
145
            ProjectGroupMembership.user_id == self.id,
 
146
            ProjectGroup.id == ProjectGroupMembership.project_group_id,
 
147
        ]
 
148
        if offering:
 
149
            preds.extend([
 
150
                ProjectSet.offering_id == offering.id,
 
151
                ProjectGroup.project_set_id == ProjectSet.id,
 
152
            ])
 
153
        return Store.of(self).find(ProjectGroup, *preds)
 
154
 
 
155
    @property
 
156
    def groups(self):
 
157
        return self.get_groups()
 
158
 
142
159
    @property
143
160
    def active_enrolments(self):
144
161
        '''A sanely ordered list of the user's active enrolments.'''
226
243
    def __repr__(self):
227
244
        return "<%s %r in %r>" % (type(self).__name__, self.user,
228
245
                                  self.offering)
 
246
 
 
247
class ProjectSet(Storm):
 
248
    __storm_table__ = "project_set"
 
249
 
 
250
    id = Int(name="projectsetid", primary=True)
 
251
    offering_id = Int(name="offeringid")
 
252
    offering = Reference(offering_id, Offering.id)
 
253
    max_students_per_group = Int()
 
254
 
 
255
    __init__ = _kwarg_init
 
256
 
 
257
    def __repr__(self):
 
258
        return "<%s %d in %r>" % (type(self).__name__, self.id,
 
259
                                  self.offering)
 
260
 
 
261
class Project(Storm):
 
262
    __storm_table__ = "project"
 
263
 
 
264
    id = Int(name="projectid", primary=True)
 
265
    synopsis = Unicode()
 
266
    url = Unicode()
 
267
    project_set_id = Int(name="projectsetid")
 
268
    project_set = Reference(project_set_id, ProjectSet.id)
 
269
    deadline = DateTime()
 
270
 
 
271
    __init__ = _kwarg_init
 
272
 
 
273
    def __repr__(self):
 
274
        return "<%s '%s' in %r>" % (type(self).__name__, self.synopsis,
 
275
                                  self.project_set.offering)
 
276
 
 
277
class ProjectGroup(Storm):
 
278
    __storm_table__ = "project_group"
 
279
 
 
280
    id = Int(name="groupid", primary=True)
 
281
    name = Unicode(name="groupnm")
 
282
    project_set_id = Int(name="projectsetid")
 
283
    project_set = Reference(project_set_id, ProjectSet.id)
 
284
    nick = Unicode()
 
285
    created_by_id = Int(name="createdby")
 
286
    created_by = Reference(created_by_id, User.id)
 
287
    epoch = DateTime()
 
288
 
 
289
    __init__ = _kwarg_init
 
290
 
 
291
    def __repr__(self):
 
292
        return "<%s %s in %r>" % (type(self).__name__, self.name,
 
293
                                  self.project_set.offering)
 
294
 
 
295
class ProjectGroupMembership(Storm):
 
296
    __storm_table__ = "group_member"
 
297
    __storm_primary__ = "user_id", "project_group_id"
 
298
 
 
299
    user_id = Int(name="loginid")
 
300
    user = Reference(user_id, User.id)
 
301
    project_group_id = Int(name="groupid")
 
302
    project_group = Reference(project_group_id, ProjectGroup.id)
 
303
 
 
304
    __init__ = _kwarg_init
 
305
 
 
306
    def __repr__(self):
 
307
        return "<%s %r in %r>" % (type(self).__name__, self.user,
 
308
                                  self.project_group)
 
309
 
 
310