~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 05:32:23 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:1158
ivle.database.User: Add an 'active_enrolments' property, which returns a list
     of nicely ordered active enrolments.

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, ReferenceSet, Bool, Storm
 
31
                         Reference, ReferenceSet, Bool, Storm, Desc
32
32
 
33
33
import ivle.conf
34
34
import ivle.caps
121
121
        fieldval = self.acct_exp
122
122
        return fieldval is not None and datetime.datetime.now() > fieldval
123
123
 
 
124
    @property
 
125
    def active_enrolments(self):
 
126
        '''A sanely ordered list of the user's active enrolments.'''
 
127
        return Store.of(self).find(Enrolment,
 
128
            Enrolment.user_id == self.id,
 
129
            Enrolment.active == True,
 
130
            Enrolment.offering_id == Offering.id,
 
131
            Offering.semester_id == Semester.id,
 
132
            Offering.subject_id == Subject.id).order_by(
 
133
                Desc(Semester.year),
 
134
                Desc(Semester.semester),
 
135
                Desc(Subject.code)
 
136
            )
 
137
 
 
138
 
124
139
    @staticmethod
125
140
    def hash_password(password):
126
141
        return md5.md5(password).hexdigest()