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

« back to all changes in this revision

Viewing changes to ivle/webapp/tutorial/service.py

  • Committer: Matt Giuca
  • Date: 2009-02-24 02:02:03 UTC
  • mto: This revision was merged to the branch mainline in revision 1119.
  • Revision ID: matt.giuca@gmail.com-20090224020203-aqdcjnsj6y7wl32o
Added a new look to the IVLE header bar. Mmmm... Web 2.0.
Added top-level directory image-source, containing SVG and script files for
    generating the images.
ivle/webapp/coremedia/images: Added 'chrome' directory containing the rendered
    images.
Modified ivle/webapp/base/ivle-headings.html and
    ivle/webapp/coremedia/ivle.css to support the new images.
    Note that the H1 and H2 at the top of the page are no longer displayed
    (and their custom styles have been removed). There is a heading image
    instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
209
209
        return {"result": "ok"}
210
210
 
211
211
 
 
212
def generate_exerciselist(worksheet, req, worksheetdata):
 
213
    """Runs through the worksheetstream, generating the appropriate
 
214
    WorksheetExercises, and de-activating the old ones."""
 
215
    exercises = []
 
216
    # Turns the worksheet into an xml stream, and then finds all the 
 
217
    # exercise nodes in the stream.
 
218
    worksheetdata = genshi.XML(worksheetdata)
 
219
    for kind, data, pos in worksheetdata:
 
220
        if kind is genshi.core.START:
 
221
            # Data is a tuple of tag name and a list of name->value tuples
 
222
            if data[0] == 'exercise':
 
223
                src = ""
 
224
                optional = False
 
225
                for attr in data[1]:
 
226
                    if attr[0] == 'src':
 
227
                        src = attr[1]
 
228
                    if attr[0] == 'optional':
 
229
                        optional = attr[1] == 'true'
 
230
                if src != "":
 
231
                    exercises.append((src, optional))
 
232
    ex_num = 0
 
233
    # Set all current worksheet_exercises to be inactive
 
234
    db_worksheet_exercises = req.store.find(WorksheetExercise,
 
235
        WorksheetExercise.worksheet_id == worksheet.id)
 
236
    for worksheet_exercise in db_worksheet_exercises:
 
237
        worksheet_exercise.active = False
 
238
    
 
239
    for exerciseid, optional in exercises:
 
240
        worksheet_exercise = req.store.find(WorksheetExercise,
 
241
            WorksheetExercise.worksheet_id == worksheet.id,
 
242
            Exercise.id == WorksheetExercise.exercise_id,
 
243
            Exercise.id == exerciseid).one()
 
244
        if worksheet_exercise is None:
 
245
            exercise = req.store.find(Exercise,
 
246
                Exercise.id == exerciseid
 
247
            ).one()
 
248
            if exercise is None:
 
249
                raise NotFound()
 
250
            worksheet_exercise = WorksheetExercise()
 
251
            worksheet_exercise.worksheet_id = worksheet.id
 
252
            worksheet_exercise.exercise_id = exercise.id
 
253
            req.store.add(worksheet_exercise)
 
254
        worksheet_exercise.active = True
 
255
        worksheet_exercise.seq_no = ex_num
 
256
        worksheet_exercise.optional = optional
 
257
 
212
258
 
213
259
# Note that this is the view of an existing worksheet. Creation is handled
214
260
# by OfferingRESTView (as offerings have worksheets)
220
266
        # XXX: Lecturers should be allowed to add worksheets Only to subjects
221
267
        #      under their control
222
268
        if user is not None:
223
 
            if user.admin:
 
269
            if user.rolenm == 'admin':
224
270
                return set(['save'])
225
271
            else:
226
272
                return set()
249
295
    @named_operation('save')
250
296
    def save(self, req, name, assessable, data, format):
251
297
        """Takes worksheet data and saves it."""
 
298
        generate_exerciselist(self.context, req, data)
 
299
        
252
300
        self.context.name = unicode(name)
253
301
        self.context.assessable = self.convert_bool(assessable)
254
302
        self.context.data = unicode(data)
255
303
        self.context.format = unicode(format)
256
 
        ivle.worksheet.update_exerciselist(self.context)
257
304
        
258
305
        return {"result": "ok"}
259
306
 
265
312
        # XXX: Lecturers should be allowed to add worksheets Only to subjects
266
313
        #      under their control
267
314
        if user is not None:
268
 
            if user.admin:
 
315
            if user.rolenm == 'admin':
269
316
                return set(['edit'])
270
317
            else:
271
318
                return set()
306
353
        # This call is added for clarity, as the worksheet is implicitly added.        
307
354
        req.store.add(new_worksheet)
308
355
        
309
 
        ivle.worksheet.update_exerciselist(new_worksheet)
 
356
        generate_exerciselist(new_worksheet, req, data)
310
357
        
311
358
        return {"result": "ok"}
312
359