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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2010-01-28 22:53:06 UTC
  • mfrom: (1451.1.8 offering-edit-ui)
  • Revision ID: me@williamgrant.id.au-20100128225306-mbdmnppoqtpoqxk5
Provide UI to edit an offering's URL and description.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
125
126
 
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))
147
148
 
148
149
 
 
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)
 
154
 
 
155
 
 
156
class OfferingEdit(XHTMLView):
 
157
    """A form to edit an offering's details."""
 
158
    template = 'templates/offering-edit.html'
 
159
    permission = 'edit'
 
160
 
 
161
    def filter(self, stream, ctx):
 
162
        return stream | HTMLFormFiller(data=ctx['data'])
 
163
 
 
164
    def populate(self, req, ctx):
 
165
        if req.method == 'POST':
 
166
            data = dict(req.get_fieldstorage())
 
167
            try:
 
168
                validator = OfferingSchema()
 
169
                data = validator.to_python(data, state=req)
 
170
 
 
171
                self.context.url = unicode(data['url']) if data['url'] else None
 
172
                self.context.description = data['description']
 
173
                req.store.commit()
 
174
                req.throw_redirect(req.publisher.generate(self.context))
 
175
            except formencode.Invalid, e:
 
176
                errors = e.unpack_errors()
 
177
        else:
 
178
            data = {
 
179
                'url': self.context.url,
 
180
                'description': self.context.description,
 
181
            }
 
182
            errors = {}
 
183
 
 
184
        ctx['data'] = data or {}
 
185
        ctx['context'] = self.context
 
186
        ctx['errors'] = errors
 
187
 
 
188
 
149
189
class UserValidator(formencode.FancyValidator):
150
190
    """A FormEncode validator that turns a username into a user.
151
191
 
317
357
 
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),