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

« back to all changes in this revision

Viewing changes to bin/ivle-cloneworksheets

  • Committer: Matt Giuca
  • Date: 2010-07-28 06:09:00 UTC
  • Revision ID: matt.giuca@gmail.com-20100728060900-6a0lcuexcv1juh5r
ivle/webapp/submit/submit.html: Rewrote error message when an offering could not be found to submit to. This can have one of several causes, and the old error assumed it was because you weren't in a subject dir. Now enumerates the possible reasons. (LP: #526853)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import os
22
22
import sys
23
23
 
 
24
import ivle.config
24
25
from ivle.database import get_store, Subject, Semester, Offering, Worksheet
25
26
import ivle.worksheet.utils
26
27
 
29
30
    sys.exit(1)
30
31
 
31
32
if len(sys.argv) != 7:
32
 
    print >> sys.stderr, "usage: %s <oldsubjectcode> <oldyear> <oldsemester> "\
33
 
                         "<newsubjectcode> <newyear> <newsemester>" \
 
33
    print >> sys.stderr, "usage: %s <oldsubjectcode> <oldyear> <oldsemestercode> "\
 
34
                         "<newsubjectcode> <newyear> <newsemestercode>" \
34
35
                         % os.path.basename(sys.argv[0])
35
36
    sys.exit()
36
37
 
37
 
store = get_store()
 
38
store = get_store(ivle.config.Config())
38
39
 
39
40
src = store.find(Offering,
40
41
                 Subject.code == unicode(sys.argv[1]),
41
42
                 Semester.year == unicode(sys.argv[2]),
42
 
                 Semester.semester == unicode(sys.argv[3]),
 
43
                 Semester.code == unicode(sys.argv[3]),
43
44
                 Offering.subject_id == Subject.id,
44
45
                 Offering.semester_id == Semester.id).one()
45
46
 
46
47
dst = store.find(Offering,
47
48
                 Subject.code == unicode(sys.argv[4]),
48
49
                 Semester.year == unicode(sys.argv[5]),
49
 
                 Semester.semester == unicode(sys.argv[6]),
 
50
                 Semester.code == unicode(sys.argv[6]),
50
51
                 Offering.subject_id == Subject.id,
51
52
                 Offering.semester_id == Semester.id).one()
52
53
 
53
54
if dst.worksheets.count() > 0:
54
55
    die('%r already has worksheets - doing nothing' % dst)
55
56
 
56
 
for oldws in src.worksheets:
57
 
    newws = Worksheet()
58
 
    newws.seq_no = oldws.seq_no
59
 
    newws.identifier = oldws.identifier
60
 
    newws.name = oldws.name
61
 
    newws.assessable = oldws.assessable
62
 
    newws.data = oldws.data
63
 
    newws.format = oldws.format
64
 
    newws.offering = dst
65
 
    store.add(newws)
66
 
    ivle.worksheet.utils.update_exerciselist(newws)
 
57
dst.clone_worksheets(src)
67
58
 
68
59
print >> sys.stderr, 'copied %d worksheets from %r to %r' \
69
60
                     % (dst.worksheets.count(), src, dst)