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

« back to all changes in this revision

Viewing changes to ivle/database.py

  • Committer: William Grant
  • Date: 2009-04-23 03:36:48 UTC
  • Revision ID: grantw@unimelb.edu.au-20090423033648-da4wxhvvtd50qzkq
Remove ivle.conf.python_site_packages_override.

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
 
import hashlib
 
27
import md5
28
28
import datetime
29
29
 
30
30
from storm.locals import create_database, Store, Int, Unicode, DateTime, \
214
214
 
215
215
    @staticmethod
216
216
    def hash_password(password):
217
 
        return hashlib.md5(password).hexdigest()
 
217
        return md5.md5(password).hexdigest()
218
218
 
219
219
    @classmethod
220
220
    def get_by_login(cls, store, login):
256
256
                perms.add('edit')
257
257
        return perms
258
258
 
259
 
    def active_offerings(self):
260
 
        """Return a sequence of currently active offerings for this subject
261
 
        (offerings whose semester.state is "current"). There should be 0 or 1
262
 
        elements in this sequence, but it's possible there are more.
263
 
        """
264
 
        return self.offerings.find(Offering.semester_id == Semester.id,
265
 
                                   Semester.state == u'current')
266
 
 
267
 
    def offering_for_semester(self, year, semester):
268
 
        """Get the offering for the given year/semester, or None."""
269
 
        return self.offerings.find(Offering.semester_id == Semester.id,
270
 
                               Semester.year == unicode(year),
271
 
                               Semester.semester == unicode(semester)).one()
272
 
 
273
259
class Semester(Storm):
274
260
    __storm_table__ = "semester"
275
261
 
674
660
    def __repr__(self):
675
661
        return "<%s %s>" % (type(self).__name__, self.name)
676
662
 
 
663
    # XXX Refactor this - make it an instance method of Subject rather than a
 
664
    # class method of Worksheet. Can't do that now because Subject isn't
 
665
    # linked referentially to the Worksheet.
 
666
    @classmethod
 
667
    def get_by_name(cls, store, subjectname, worksheetname):
 
668
        """
 
669
        Get the Worksheet from the db associated with a given store, subject
 
670
        name and worksheet name.
 
671
        """
 
672
        return store.find(cls, cls.subject == unicode(subjectname),
 
673
            cls.name == unicode(worksheetname)).one()
 
674
 
677
675
    def remove_all_exercises(self):
678
676
        """
679
677
        Remove all exercises from this worksheet.