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

« back to all changes in this revision

Viewing changes to ivle/pulldown_subj/__init__.py

  • Committer: William Grant
  • Date: 2009-01-19 23:29:19 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: grantw@unimelb.edu.au-20090119232919-4a6goyk6u1u1m58c
ivle.pulldown_subj: Use Storm, and kill ivle.db dependency. This means we use
    unicodes everywhere, so the pulldown module API has changed slightly.

ivle.pulldown_subj.dummy_subj: Return unicodes, not strs.

bin/ivle-enrolallusers: Remove ivle.db dependency, give enrol_user a store,
    and actually use the current year if one is not specified.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
from subjecterror import SubjectError
33
33
import ivle.conf
34
 
import ivle.db
 
34
 
 
35
from ivle.database import Subject, Offering, Semester, AlreadyEnrolledError
35
36
 
36
37
def get_subjects(login):
37
38
    """
45
46
            return result
46
47
    return []
47
48
 
48
 
def enrol_user(login, year=None):
 
49
def enrol_user(store, user, year=None):
49
50
    """
50
51
    Looks up the student in whatever modules are available.
51
52
    The pulldown does not tell us what year to enrol the student for, so the
62
63
    subjects outside the system, or subjects already enrolled).
63
64
    """
64
65
    count = 0
65
 
    db = ivle.db.DB()
66
 
    for subject, semester in get_subjects(login):
67
 
        count += db.add_enrolment(login, subject, semester, year)
 
66
    for subject, semester in get_subjects(user.login):
 
67
        offering = store.find(Offering,
 
68
                              Subject.code == subject,
 
69
                              Offering.subject_id == Subject.id,
 
70
                              Semester.year == year,
 
71
                              Semester.semester == semester,
 
72
                              Offering.semester_id == Semester.id).one()
 
73
 
 
74
        # We can't find a matching offering, so we don't care about it.
 
75
        if not offering:
 
76
            continue
 
77
 
 
78
        try:
 
79
            offering.enrol(user)
 
80
            count += 1
 
81
        except AlreadyEnrolledError:
 
82
            pass
68
83
    return count
69
84
 
70
85
# Allow imports to get files from this directory.