~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-22 04:47:42 UTC
  • mfrom: (1080.1.93 storm)
  • Revision ID: grantw@unimelb.edu.au-20090122044742-sa8gnww0ma2bm2rv
Merge Storm branch. ivle.db is dead. Watch out for the schema change.

Show diffs side-by-side

added added

removed removed

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