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

« back to all changes in this revision

Viewing changes to ivle/webapp/admin/subject.py

  • Committer: Matt Giuca
  • Date: 2010-02-23 03:27:05 UTC
  • Revision ID: matt.giuca@gmail.com-20100223032705-gfkugy2f4g2g9x6x
ivle.makeuser: In rebuild_svn_[group_]config, encode strings being written out as UTF-8 so they don't fail explosively on non-ASCII characters. This allows submissions with non-ASCII filenames. Fixes Launchpad bug #524172.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import urllib
28
28
import urlparse
29
29
import cgi
30
 
import datetime
31
30
 
32
31
from storm.locals import Desc, Store
33
32
import genshi
34
33
from genshi.filters import HTMLFormFiller
35
 
from genshi.template import Context
 
34
from genshi.template import Context, TemplateLoader
36
35
import formencode
37
36
import formencode.validators
38
37
 
39
 
from ivle.webapp.base.forms import (BaseFormView, URLNameValidator,
40
 
                                    DateTimeValidator)
 
38
from ivle.webapp.base.forms import BaseFormView
41
39
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
42
40
from ivle.webapp.base.xhtml import XHTMLView
43
 
from ivle.webapp.base.text import TextView
44
41
from ivle.webapp.errors import BadRequest
45
42
from ivle.webapp import ApplicationRoot
46
43
 
49
46
from ivle import util
50
47
import ivle.date
51
48
 
 
49
from ivle.webapp.admin.projectservice import ProjectSetRESTView
 
50
from ivle.webapp.admin.offeringservice import OfferingRESTView
52
51
from ivle.webapp.admin.publishing import (root_to_subject, root_to_semester,
53
52
            subject_to_offering, offering_to_projectset, offering_to_project,
54
53
            offering_to_enrolment, subject_url, semester_url, offering_url,
55
54
            projectset_url, project_url, enrolment_url)
56
55
from ivle.webapp.admin.breadcrumbs import (SubjectBreadcrumb,
57
56
            OfferingBreadcrumb, UserBreadcrumb, ProjectBreadcrumb,
58
 
            ProjectsBreadcrumb, EnrolmentBreadcrumb)
 
57
            EnrolmentBreadcrumb)
59
58
from ivle.webapp.core import Plugin as CorePlugin
60
59
from ivle.webapp.groups import GroupsView
61
60
from ivle.webapp.media import media_url
65
64
    '''The view of the list of subjects.'''
66
65
    template = 'templates/subjects.html'
67
66
    tab = 'subjects'
68
 
    breadcrumb_text = "Subjects"
69
67
 
70
68
    def authorize(self, req):
71
69
        return req.user is not None
75
73
        ctx['user'] = req.user
76
74
        ctx['semesters'] = []
77
75
 
78
 
        for semester in req.store.find(Semester).order_by(
79
 
            Desc(Semester.year), Desc(Semester.display_name)):
 
76
        for semester in req.store.find(Semester).order_by(Desc(Semester.year),
 
77
                                                     Desc(Semester.semester)):
80
78
            if req.user.admin:
81
79
                # For admins, show all subjects in the system
82
80
                offerings = list(semester.offerings.find())
98
96
    def populate(self, req, ctx):
99
97
        ctx['req'] = req
100
98
        ctx['mediapath'] = media_url(req, CorePlugin, 'images/')
101
 
        ctx['SubjectView'] = SubjectView
102
99
        ctx['SubjectEdit'] = SubjectEdit
103
100
        ctx['SemesterEdit'] = SemesterEdit
104
101
 
105
102
        ctx['subjects'] = req.store.find(Subject).order_by(Subject.name)
106
103
        ctx['semesters'] = req.store.find(Semester).order_by(
107
 
            Semester.year, Semester.display_name)
108
 
 
109
 
 
110
 
class SubjectUniquenessValidator(formencode.FancyValidator):
111
 
    """A FormEncode validator that checks that a subject attribute is unique.
 
104
            Semester.year, Semester.semester)
 
105
 
 
106
 
 
107
class SubjectShortNameUniquenessValidator(formencode.FancyValidator):
 
108
    """A FormEncode validator that checks that a subject name is unused.
112
109
 
113
110
    The subject referenced by state.existing_subject is permitted
114
111
    to hold that name. If any other object holds it, the input is rejected.
115
 
 
116
 
    :param attribute: the name of the attribute to check.
117
 
    :param display: a string to identify the field in case of error.
118
112
    """
119
 
 
120
 
    def __init__(self, attribute, display):
121
 
        self.attribute = attribute
122
 
        self.display = display
 
113
    def __init__(self, matching=None):
 
114
        self.matching = matching
123
115
 
124
116
    def _to_python(self, value, state):
125
 
        if (state.store.find(Subject, **{self.attribute: value}).one() not in
 
117
        if (state.store.find(
 
118
                Subject, short_name=value).one() not in
126
119
                (None, state.existing_subject)):
127
120
            raise formencode.Invalid(
128
 
                '%s already taken' % self.display, value, state)
 
121
                'Short name already taken', value, state)
129
122
        return value
130
123
 
131
124
 
132
125
class SubjectSchema(formencode.Schema):
133
126
    short_name = formencode.All(
134
 
        SubjectUniquenessValidator('short_name', 'URL name'),
135
 
        URLNameValidator(not_empty=True))
136
 
    name = formencode.validators.UnicodeString(not_empty=True)
137
 
    code = formencode.All(
138
 
        SubjectUniquenessValidator('code', 'Subject code'),
 
127
        SubjectShortNameUniquenessValidator(),
139
128
        formencode.validators.UnicodeString(not_empty=True))
 
129
    name = formencode.validators.UnicodeString(not_empty=True)
 
130
    code = formencode.validators.UnicodeString(not_empty=True)
140
131
 
141
132
 
142
133
class SubjectFormView(BaseFormView):
153
144
    def validator(self):
154
145
        return SubjectSchema()
155
146
 
 
147
    def get_return_url(self, obj):
 
148
        return '/subjects'
 
149
 
156
150
 
157
151
class SubjectNew(SubjectFormView):
158
152
    """A form to create a subject."""
200
194
    """
201
195
    def _to_python(self, value, state):
202
196
        if (state.store.find(
203
 
                Semester, year=value['year'], url_name=value['url_name']
 
197
                Semester, year=value['year'], semester=value['semester']
204
198
                ).one() not in (None, state.existing_semester)):
205
199
            raise formencode.Invalid(
206
200
                'Semester already exists', value, state)
208
202
 
209
203
 
210
204
class SemesterSchema(formencode.Schema):
211
 
    year = URLNameValidator()
212
 
    code = formencode.validators.UnicodeString()
213
 
    url_name = URLNameValidator()
214
 
    display_name = formencode.validators.UnicodeString()
 
205
    year = formencode.validators.UnicodeString()
 
206
    semester = formencode.validators.UnicodeString()
215
207
    state = formencode.All(
216
208
        formencode.validators.OneOf(["past", "current", "future"]),
217
209
        formencode.validators.UnicodeString())
246
238
    def save_object(self, req, data):
247
239
        new_semester = Semester()
248
240
        new_semester.year = data['year']
249
 
        new_semester.code = data['code']
250
 
        new_semester.url_name = data['url_name']
251
 
        new_semester.display_name = data['display_name']
 
241
        new_semester.semester = data['semester']
252
242
        new_semester.state = data['state']
253
243
 
254
244
        req.store.add(new_semester)
265
255
    def get_default_data(self, req):
266
256
        return {
267
257
            'year': self.context.year,
268
 
            'code': self.context.code,
269
 
            'url_name': self.context.url_name,
270
 
            'display_name': self.context.display_name,
 
258
            'semester': self.context.semester,
271
259
            'state': self.context.state,
272
260
            }
273
261
 
274
262
    def save_object(self, req, data):
275
263
        self.context.year = data['year']
276
 
        self.context.code = data['code']
277
 
        self.context.url_name = data['url_name']
278
 
        self.context.display_name = data['display_name']
 
264
        self.context.semester = data['semester']
279
265
        self.context.state = data['state']
280
266
 
281
267
        return self.context
282
268
 
283
 
class SubjectView(XHTMLView):
284
 
    '''The view of the list of offerings in a given subject.'''
285
 
    template = 'templates/subject.html'
286
 
    tab = 'subjects'
287
 
 
288
 
    def authorize(self, req):
289
 
        return req.user is not None
290
 
 
291
 
    def populate(self, req, ctx):
292
 
        ctx['context'] = self.context
293
 
        ctx['req'] = req
294
 
        ctx['user'] = req.user
295
 
        ctx['offerings'] = list(self.context.offerings)
296
 
        ctx['permissions'] = self.context.get_permissions(req.user,req.config)
297
 
        ctx['SubjectEdit'] = SubjectEdit
298
 
        ctx['SubjectOfferingNew'] = SubjectOfferingNew
299
 
 
300
269
 
301
270
class OfferingView(XHTMLView):
302
271
    """The home page of an offering."""
317
286
        ctx['OfferingCloneWorksheets'] = OfferingCloneWorksheets
318
287
        ctx['GroupsView'] = GroupsView
319
288
        ctx['EnrolmentsView'] = EnrolmentsView
320
 
        ctx['Project'] = ivle.database.Project
321
289
 
322
290
        # As we go, calculate the total score for this subject
323
291
        # (Assessable worksheets only, mandatory problems only)
324
292
 
325
293
        ctx['worksheets'], problems_total, problems_done = (
326
294
            ivle.worksheet.utils.create_list_of_fake_worksheets_and_stats(
327
 
                req.config, req.store, req.user, self.context,
328
 
                as_of=self.context.worksheet_cutoff))
 
295
                req.store, req.user, self.context))
329
296
 
330
297
        ctx['exercises_total'] = problems_total
331
298
        ctx['exercises_done'] = problems_done
372
339
            year = semester = None
373
340
 
374
341
        semester = state.store.find(
375
 
            Semester, year=year, url_name=semester).one()
 
342
            Semester, year=year, semester=semester).one()
376
343
        if semester:
377
344
            return semester
378
345
        else:
402
369
    description = formencode.validators.UnicodeString(
403
370
        if_missing=None, not_empty=False)
404
371
    url = formencode.validators.URL(if_missing=None, not_empty=False)
405
 
    worksheet_cutoff = DateTimeValidator(if_missing=None, not_empty=False)
406
 
    show_worksheet_marks = formencode.validators.StringBoolean(
407
 
        if_missing=False)
408
372
 
409
373
 
410
374
class OfferingAdminSchema(OfferingSchema):
432
396
        super(OfferingEdit, self).populate(req, ctx)
433
397
        ctx['subjects'] = req.store.find(Subject).order_by(Subject.name)
434
398
        ctx['semesters'] = req.store.find(Semester).order_by(
435
 
            Semester.year, Semester.display_name)
436
 
        ctx['force_subject'] = None
 
399
            Semester.year, Semester.semester)
437
400
 
438
401
    def populate_state(self, state):
439
402
        state.existing_offering = self.context
442
405
        return {
443
406
            'subject': self.context.subject.short_name,
444
407
            'semester': self.context.semester.year + '/' +
445
 
                        self.context.semester.url_name,
 
408
                        self.context.semester.semester,
446
409
            'url': self.context.url,
447
410
            'description': self.context.description,
448
 
            'worksheet_cutoff': self.context.worksheet_cutoff,
449
 
            'show_worksheet_marks': self.context.show_worksheet_marks,
450
411
            }
451
412
 
452
413
    def save_object(self, req, data):
455
416
            self.context.semester = data['semester']
456
417
        self.context.description = data['description']
457
418
        self.context.url = unicode(data['url']) if data['url'] else None
458
 
        self.context.worksheet_cutoff = data['worksheet_cutoff']
459
 
        self.context.show_worksheet_marks = data['show_worksheet_marks']
460
419
        return self.context
461
420
 
462
421
 
476
435
        super(OfferingNew, self).populate(req, ctx)
477
436
        ctx['subjects'] = req.store.find(Subject).order_by(Subject.name)
478
437
        ctx['semesters'] = req.store.find(Semester).order_by(
479
 
            Semester.year, Semester.display_name)
480
 
        ctx['force_subject'] = None
 
438
            Semester.year, Semester.semester)
481
439
 
482
440
    def populate_state(self, state):
483
441
        state.existing_offering = None
491
449
        new_offering.semester = data['semester']
492
450
        new_offering.description = data['description']
493
451
        new_offering.url = unicode(data['url']) if data['url'] else None
494
 
        new_offering.worksheet_cutoff = data['worksheet_cutoff']
495
 
        new_offering.show_worksheet_marks = data['show_worksheet_marks']
496
452
 
497
453
        req.store.add(new_offering)
498
454
        return new_offering
499
455
 
500
 
class SubjectOfferingNew(OfferingNew):
501
 
    """A form to create an offering for a given subject."""
502
 
    # Identical to OfferingNew, except it forces the subject to be the subject
503
 
    # in context
504
 
    def populate(self, req, ctx):
505
 
        super(SubjectOfferingNew, self).populate(req, ctx)
506
 
        ctx['force_subject'] = self.context
507
456
 
508
457
class OfferingCloneWorksheetsSchema(formencode.Schema):
509
458
    subject = formencode.All(
528
477
        super(OfferingCloneWorksheets, self).populate(req, ctx)
529
478
        ctx['subjects'] = req.store.find(Subject).order_by(Subject.name)
530
479
        ctx['semesters'] = req.store.find(Semester).order_by(
531
 
            Semester.year, Semester.display_name)
 
480
            Semester.year, Semester.semester)
532
481
 
533
482
    def get_default_data(self, req):
534
483
        return {}
641
590
        ctx['offering'] = self.context
642
591
        ctx['roles_auth'] = self.context.get_permissions(req.user, req.config)
643
592
        ctx['errors'] = errors
644
 
        # If all of the fields validated, set the global form error.
645
 
        if isinstance(errors, basestring):
646
 
            ctx['error_value'] = errors
647
593
 
648
594
 
649
595
class EnrolmentEditSchema(formencode.Schema):
708
654
 
709
655
    def populate(self, req, ctx):
710
656
        self.plugin_styles[Plugin] = ["project.css"]
 
657
        self.plugin_scripts[Plugin] = ["project.js"]
711
658
        ctx['req'] = req
712
659
        ctx['offering'] = self.context
713
660
        ctx['projectsets'] = []
 
661
        ctx['OfferingRESTView'] = OfferingRESTView
714
662
 
715
663
        #Open the projectset Fragment, and render it for inclusion
716
664
        #into the ProjectSets page
 
665
        #XXX: This could be a lot cleaner
 
666
        loader = genshi.template.TemplateLoader(".", auto_reload=True)
 
667
 
717
668
        set_fragment = os.path.join(os.path.dirname(__file__),
718
669
                "templates/projectset_fragment.html")
719
670
        project_fragment = os.path.join(os.path.dirname(__file__),
720
671
                "templates/project_fragment.html")
721
672
 
722
 
        for projectset in \
723
 
            self.context.project_sets.order_by(ivle.database.ProjectSet.id):
724
 
            settmpl = self._loader.load(set_fragment)
 
673
        for projectset in self.context.project_sets:
 
674
            settmpl = loader.load(set_fragment)
725
675
            setCtx = Context()
726
676
            setCtx['req'] = req
727
677
            setCtx['projectset'] = projectset
728
678
            setCtx['projects'] = []
729
679
            setCtx['GroupsView'] = GroupsView
730
 
            setCtx['ProjectSetEdit'] = ProjectSetEdit
731
 
            setCtx['ProjectNew'] = ProjectNew
 
680
            setCtx['ProjectSetRESTView'] = ProjectSetRESTView
732
681
 
733
 
            for project in \
734
 
                projectset.projects.order_by(ivle.database.Project.deadline):
735
 
                projecttmpl = self._loader.load(project_fragment)
 
682
            for project in projectset.projects:
 
683
                projecttmpl = loader.load(project_fragment)
736
684
                projectCtx = Context()
737
685
                projectCtx['req'] = req
738
686
                projectCtx['project'] = project
739
 
                projectCtx['ProjectEdit'] = ProjectEdit
740
 
                projectCtx['ProjectDelete'] = ProjectDelete
741
687
 
742
688
                setCtx['projects'].append(
743
689
                        projecttmpl.generate(projectCtx))
751
697
    permission = "view_project_submissions"
752
698
    tab = 'subjects'
753
699
 
 
700
    def build_subversion_url(self, svnroot, submission):
 
701
        princ = submission.assessed.principal
 
702
 
 
703
        if isinstance(princ, User):
 
704
            path = 'users/%s' % princ.login
 
705
        else:
 
706
            path = 'groups/%s_%s_%s_%s' % (
 
707
                    princ.project_set.offering.subject.short_name,
 
708
                    princ.project_set.offering.semester.year,
 
709
                    princ.project_set.offering.semester.semester,
 
710
                    princ.name
 
711
                    )
 
712
        return urlparse.urljoin(
 
713
                    svnroot,
 
714
                    os.path.join(path, submission.path[1:] if
 
715
                                       submission.path.startswith(os.sep) else
 
716
                                       submission.path))
 
717
 
754
718
    def populate(self, req, ctx):
755
719
        self.plugin_styles[Plugin] = ["project.css"]
756
720
 
757
721
        ctx['req'] = req
758
 
        ctx['permissions'] = self.context.get_permissions(req.user,req.config)
759
722
        ctx['GroupsView'] = GroupsView
760
723
        ctx['EnrolView'] = EnrolView
761
 
        ctx['format_datetime'] = ivle.date.make_date_nice
762
 
        ctx['format_datetime_short'] = ivle.date.format_datetime_for_paragraph
763
 
        ctx['project'] = self.context
764
 
        ctx['user'] = req.user
765
 
        ctx['ProjectEdit'] = ProjectEdit
766
 
        ctx['ProjectDelete'] = ProjectDelete
767
 
        ctx['ProjectExport'] = ProjectBashExportView
768
 
 
769
 
class ProjectBashExportView(TextView):
770
 
    """Produce a Bash script for exporting projects"""
771
 
    template = "templates/project-export.sh"
772
 
    content_type = "text/x-sh"
773
 
    permission = "view_project_submissions"
774
 
 
775
 
    def populate(self, req, ctx):
776
 
        ctx['req'] = req
777
 
        ctx['permissions'] = self.context.get_permissions(req.user,req.config)
778
 
        ctx['format_datetime'] = ivle.date.make_date_nice
779
 
        ctx['format_datetime_short'] = ivle.date.format_datetime_for_paragraph
780
 
        ctx['project'] = self.context
781
 
        ctx['user'] = req.user
782
 
        ctx['now'] = datetime.datetime.now()
783
 
        ctx['format_datetime'] = ivle.date.make_date_nice
784
 
        ctx['format_datetime_short'] = ivle.date.format_datetime_for_paragraph
785
 
 
786
 
class ProjectUniquenessValidator(formencode.FancyValidator):
787
 
    """A FormEncode validator that checks that a project short_name is unique
788
 
    in a given offering.
789
 
 
790
 
    The project referenced by state.existing_project is permitted to
791
 
    hold that short_name. If any other project holds it, the input is rejected.
792
 
    """
793
 
    def _to_python(self, value, state):
794
 
        if (state.store.find(
795
 
            Project,
796
 
            Project.short_name == unicode(value),
797
 
            Project.project_set_id == ProjectSet.id,
798
 
            ProjectSet.offering == state.offering).one() not in
799
 
            (None, state.existing_project)):
800
 
            raise formencode.Invalid(
801
 
                "A project with that URL name already exists in this offering."
802
 
                , value, state)
803
 
        return value
804
 
 
805
 
class ProjectSchema(formencode.Schema):
806
 
    name = formencode.validators.UnicodeString(not_empty=True)
807
 
    short_name = formencode.All(
808
 
        URLNameValidator(not_empty=True),
809
 
        ProjectUniquenessValidator())
810
 
    deadline = DateTimeValidator(not_empty=True)
811
 
    url = formencode.validators.URL(if_missing=None, not_empty=False)
812
 
    synopsis = formencode.validators.UnicodeString(not_empty=True)
813
 
 
814
 
class ProjectEdit(BaseFormView):
815
 
    """A form to edit a project."""
816
 
    template = 'templates/project-edit.html'
817
 
    tab = 'subjects'
818
 
    permission = 'edit'
819
 
 
820
 
    @property
821
 
    def validator(self):
822
 
        return ProjectSchema()
823
 
 
824
 
    def populate(self, req, ctx):
825
 
        super(ProjectEdit, self).populate(req, ctx)
826
 
        ctx['projectset'] = self.context.project_set
827
 
 
828
 
    def populate_state(self, state):
829
 
        state.offering = self.context.project_set.offering
830
 
        state.existing_project = self.context
831
 
 
832
 
    def get_default_data(self, req):
833
 
        return {
834
 
            'name':         self.context.name,
835
 
            'short_name':   self.context.short_name,
836
 
            'deadline':     self.context.deadline,
837
 
            'url':          self.context.url,
838
 
            'synopsis':     self.context.synopsis,
839
 
            }
840
 
 
841
 
    def save_object(self, req, data):
842
 
        self.context.name = data['name']
843
 
        self.context.short_name = data['short_name']
844
 
        self.context.deadline = data['deadline']
845
 
        self.context.url = unicode(data['url']) if data['url'] else None
846
 
        self.context.synopsis = data['synopsis']
847
 
        return self.context
848
 
 
849
 
class ProjectNew(BaseFormView):
850
 
    """A form to create a new project."""
851
 
    template = 'templates/project-new.html'
852
 
    tab = 'subjects'
853
 
    permission = 'edit'
854
 
 
855
 
    @property
856
 
    def validator(self):
857
 
        return ProjectSchema()
858
 
 
859
 
    def populate(self, req, ctx):
860
 
        super(ProjectNew, self).populate(req, ctx)
861
 
        ctx['projectset'] = self.context
862
 
 
863
 
    def populate_state(self, state):
864
 
        state.offering = self.context.offering
865
 
        state.existing_project = None
866
 
 
867
 
    def get_default_data(self, req):
868
 
        return {}
869
 
 
870
 
    def save_object(self, req, data):
871
 
        new_project = Project()
872
 
        new_project.project_set = self.context
873
 
        new_project.name = data['name']
874
 
        new_project.short_name = data['short_name']
875
 
        new_project.deadline = data['deadline']
876
 
        new_project.url = unicode(data['url']) if data['url'] else None
877
 
        new_project.synopsis = data['synopsis']
878
 
        req.store.add(new_project)
879
 
        return new_project
880
 
 
881
 
class ProjectDelete(XHTMLView):
882
 
    """A form to delete a project."""
883
 
    template = 'templates/project-delete.html'
884
 
    tab = 'subjects'
885
 
    permission = 'edit'
886
 
 
887
 
    def populate(self, req, ctx):
888
 
        # If post, delete the project, or display a message explaining that
889
 
        # the project cannot be deleted
890
 
        if self.context.can_delete:
891
 
            if req.method == 'POST':
892
 
                self.context.delete()
893
 
                self.template = 'templates/project-deleted.html'
894
 
        else:
895
 
            # Can't delete
896
 
            self.template = 'templates/project-undeletable.html'
897
 
 
898
 
        # If get and can delete, display a delete confirmation page
899
 
 
900
 
        # Variables for the template
901
 
        ctx['req'] = req
902
 
        ctx['project'] = self.context
903
 
        ctx['OfferingProjectsView'] = OfferingProjectsView
904
 
 
905
 
class ProjectSetSchema(formencode.Schema):
906
 
    group_size = formencode.validators.Int(if_missing=None, not_empty=False)
907
 
 
908
 
class ProjectSetEdit(BaseFormView):
909
 
    """A form to edit a project set."""
910
 
    template = 'templates/projectset-edit.html'
911
 
    tab = 'subjects'
912
 
    permission = 'edit'
913
 
 
914
 
    @property
915
 
    def validator(self):
916
 
        return ProjectSetSchema()
917
 
 
918
 
    def populate(self, req, ctx):
919
 
        super(ProjectSetEdit, self).populate(req, ctx)
920
 
 
921
 
    def get_default_data(self, req):
922
 
        return {
923
 
            'group_size': self.context.max_students_per_group,
924
 
            }
925
 
 
926
 
    def save_object(self, req, data):
927
 
        self.context.max_students_per_group = data['group_size']
928
 
        return self.context
929
 
 
930
 
class ProjectSetNew(BaseFormView):
931
 
    """A form to create a new project set."""
932
 
    template = 'templates/projectset-new.html'
933
 
    tab = 'subjects'
934
 
    permission = 'edit'
935
 
    breadcrumb_text = "Projects"
936
 
 
937
 
    @property
938
 
    def validator(self):
939
 
        return ProjectSetSchema()
940
 
 
941
 
    def populate(self, req, ctx):
942
 
        super(ProjectSetNew, self).populate(req, ctx)
943
 
 
944
 
    def get_default_data(self, req):
945
 
        return {}
946
 
 
947
 
    def save_object(self, req, data):
948
 
        new_set = ProjectSet()
949
 
        new_set.offering = self.context
950
 
        new_set.max_students_per_group = data['group_size']
951
 
        req.store.add(new_set)
952
 
        return new_set
 
724
        ctx['format_datetime_short'] = ivle.date.format_datetime_for_paragraph
 
725
        ctx['build_subversion_url'] = self.build_subversion_url
 
726
        ctx['svn_addr'] = req.config['urls']['svn_addr']
 
727
        ctx['project'] = self.context
 
728
        ctx['user'] = req.user
953
729
 
954
730
class Plugin(ViewPlugin, MediaPlugin):
955
731
    forward_routes = (root_to_subject, root_to_semester, subject_to_offering,
964
740
             (ApplicationRoot, ('subjects', '+new'), SubjectNew),
965
741
             (ApplicationRoot, ('subjects', '+new-offering'), OfferingNew),
966
742
             (ApplicationRoot, ('+semesters', '+new'), SemesterNew),
967
 
             (Subject, '+index', SubjectView),
968
743
             (Subject, '+edit', SubjectEdit),
969
 
             (Subject, '+new-offering', SubjectOfferingNew),
970
744
             (Semester, '+edit', SemesterEdit),
971
745
             (Offering, '+index', OfferingView),
972
746
             (Offering, '+edit', OfferingEdit),
976
750
             (Enrolment, '+edit', EnrolmentEdit),
977
751
             (Enrolment, '+delete', EnrolmentDelete),
978
752
             (Offering, ('+projects', '+index'), OfferingProjectsView),
979
 
             (Offering, ('+projects', '+new-set'), ProjectSetNew),
980
 
             (ProjectSet, '+edit', ProjectSetEdit),
981
 
             (ProjectSet, '+new', ProjectNew),
982
753
             (Project, '+index', ProjectView),
983
 
             (Project, '+edit', ProjectEdit),
984
 
             (Project, '+delete', ProjectDelete),
985
 
             (Project, ('+export', 'project-export.sh'),
986
 
                ProjectBashExportView),
 
754
 
 
755
             (Offering, ('+projectsets', '+new'), OfferingRESTView, 'api'),
 
756
             (ProjectSet, ('+projects', '+new'), ProjectSetRESTView, 'api'),
987
757
             ]
988
758
 
989
759
    breadcrumbs = {Subject: SubjectBreadcrumb,