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

« back to all changes in this revision

Viewing changes to bin/ivle-enrol

  • Committer: Matt Giuca
  • Date: 2010-02-12 10:27:55 UTC
  • Revision ID: matt.giuca@gmail.com-20100212102755-ifsyo4qaqa2myvl5
docs: Added a new help page, Running and Serving.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import os
26
26
import sys
27
27
 
28
 
from ivle.database import get_store, Subject, Semester, Offering, User, \
29
 
                          AlreadyEnrolledError
 
28
from ivle.config import Config
 
29
from ivle.database import get_store, Subject, Semester, Offering, User
30
30
 
31
31
def die(error):
32
32
    print >> sys.stderr, '%s: %s' % (os.path.basename(sys.argv[0]), error)
33
33
    sys.exit(1)
34
34
 
35
 
if len(sys.argv) != 5:
36
 
    print >> sys.stderr, "usage: %s <login> <subjectcode> <year> <semester>" \
 
35
if len(sys.argv) not in (5, 6):
 
36
    print >> sys.stderr, '''usage: %s <login> <subjectcode> <year> <semester> [role]
 
37
 
 
38
'role' should be one of student (the default), tutor or lecturer.
 
39
If an enrolment already exists, it will be reactivated and its role set.''' \
37
40
                         % os.path.basename(sys.argv[0])
38
41
    sys.exit()
39
42
 
40
 
store = get_store()
 
43
store = get_store(Config())
41
44
 
42
45
user = User.get_by_login(store, sys.argv[1])
43
46
if user is None:
52
55
if not offering:
53
56
    die("subject offering not found")
54
57
 
55
 
if not offering.semester.active:
56
 
    die("cannot enrol - semester inactive")
57
 
    
 
58
role = unicode(sys.argv[5]) if len(sys.argv) == 6 else u'student'
 
59
 
58
60
try:
59
 
    offering.enrol(user)
 
61
    offering.enrol(user, role)
60
62
except AlreadyEnrolledError:
61
63
    die("already enrolled")
62
64