122
122
ctx['format_submission_principal'] = format_submission_principal
123
123
ctx['format_datetime'] = ivle.date.make_date_nice
124
124
ctx['format_datetime_short'] = ivle.date.format_datetime_for_paragraph
125
ctx['OfferingEdit'] = OfferingEdit
126
127
# As we go, calculate the total score for this subject
127
128
# (Assessable worksheets only, mandatory problems only)
146
147
problems_done, problems_total))
150
class OfferingSchema(formencode.Schema):
151
description = formencode.validators.UnicodeString(
152
if_missing=None, not_empty=False)
153
url = formencode.validators.URL(if_missing=None, not_empty=False)
156
class OfferingEdit(XHTMLView):
157
"""A form to edit an offering's details."""
158
template = 'templates/offering-edit.html'
161
def filter(self, stream, ctx):
162
return stream | HTMLFormFiller(data=ctx['data'])
164
def populate(self, req, ctx):
165
if req.method == 'POST':
166
data = dict(req.get_fieldstorage())
168
validator = OfferingSchema()
169
data = validator.to_python(data, state=req)
171
self.context.url = unicode(data['url']) if data['url'] else None
172
self.context.description = data['description']
174
req.throw_redirect(req.publisher.generate(self.context))
175
except formencode.Invalid, e:
176
errors = e.unpack_errors()
179
'url': self.context.url,
180
'description': self.context.description,
184
ctx['data'] = data or {}
185
ctx['context'] = self.context
186
ctx['errors'] = errors
149
189
class UserValidator(formencode.FancyValidator):
150
190
"""A FormEncode validator that turns a username into a user.
318
358
views = [(ApplicationRoot, ('subjects', '+index'), SubjectsView),
319
359
(Offering, '+index', OfferingView),
360
(Offering, '+edit', OfferingEdit),
320
361
(Offering, ('+enrolments', '+index'), EnrolmentsView),
321
362
(Offering, ('+enrolments', '+new'), EnrolView),
322
363
(Offering, ('+projects', '+index'), OfferingProjectsView),