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

« back to all changes in this revision

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

MergedĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
from ivle.database import Subject, Offering, Semester, Exercise, \
39
39
                          ExerciseSave, WorksheetExercise
40
40
from ivle.database import Worksheet as DBWorksheet
41
 
import ivle.worksheet
 
41
import ivle.worksheet.utils
42
42
from ivle.webapp.base.views import BaseView
43
43
from ivle.webapp.base.xhtml import XHTMLView
44
44
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
45
45
from ivle.webapp.media import BaseMediaFileView, media_url
46
46
from ivle.webapp.errors import NotFound, Forbidden
47
 
from ivle.webapp.tutorial.rst import rst as rstfunc
 
47
from ivle.worksheet.rst import rst as rstfunc
48
48
from ivle.webapp.tutorial.service import AttemptsRESTView, AttemptRESTView, \
49
49
            WorksheetExerciseRESTView, WorksheetRESTView, WorksheetsRESTView
50
50
from ivle.webapp.tutorial.exercise_service import ExercisesRESTView, \
71
71
class OfferingView(XHTMLView):
72
72
    '''The view of the index of worksheets for an offering.'''
73
73
    template = 'templates/subjectmenu.html'
74
 
    appname = 'tutorial' # XXX
 
74
    tab = 'subjects' # XXX
75
75
    permission = 'view'
76
76
 
77
77
    def __init__(self, req, subject, year, semester):
108
108
            if new_worksheet.assessable:
109
109
                # Calculate the user's score for this worksheet
110
110
                mand_done, mand_total, opt_done, opt_total = (
111
 
                    ivle.worksheet.calculate_score(req.store, req.user,
 
111
                    ivle.worksheet.utils.calculate_score(req.store, req.user,
112
112
                        worksheet))
113
113
                if opt_total > 0:
114
114
                    optional_message = " (excluding optional exercises)"
148
148
class WorksheetView(XHTMLView):
149
149
    '''The view of a worksheet with exercises.'''
150
150
    template = 'templates/worksheet.html'
151
 
    appname = 'tutorial' # XXX
 
151
    tab = 'subjects'
152
152
    permission = 'view'
153
153
 
154
154
    def __init__(self, req, subject, year, semester, worksheet):
178
178
        ctx['worksheet'] = self.context
179
179
        ctx['semester'] = self.semester
180
180
        ctx['year'] = self.year
181
 
        if self.context.format == 'rst':
182
 
            ws_xml = '<worksheet>' + rstfunc(self.context.data) + '</worksheet>'
183
 
        else:
184
 
            ws_xml = self.context.data
185
 
        ctx['worksheetstream'] = genshi.Stream(list(genshi.XML(ws_xml)))
 
181
 
 
182
        ctx['worksheetstream'] = genshi.Stream(list(genshi.XML(self.context.get_xml())))
186
183
 
187
184
        generate_worksheet_data(ctx, req, self.context)
188
185
 
349
346
    # an attempt, then use that text instead of the supplied "partial".
350
347
    # Get exercise stored text will return a save, or the most recent attempt,
351
348
    # whichever is more recent
352
 
    save = ivle.worksheet.get_exercise_stored_text(
 
349
    save = ivle.worksheet.utils.get_exercise_stored_text(
353
350
                        req.store, req.user, worksheet_exercise)
354
351
 
355
352
    # Also get the number of attempts taken and whether this is complete.
356
353
    complete, curctx['attempts'] = \
357
 
            ivle.worksheet.get_exercise_status(req.store, req.user, 
 
354
            ivle.worksheet.utils.get_exercise_status(req.store, req.user, 
358
355
                                               worksheet_exercise)
359
356
    if save is not None:
360
357
        curctx['exercisesave'] = save.text
366
363
    #Save the exercise details to the Table of Contents
367
364
 
368
365
    loader = genshi.template.TemplateLoader(".", auto_reload=True)
369
 
    tmpl = loader.load(os.path.join(os.path.dirname(__file__), "exercise.html"))
 
366
    tmpl = loader.load(os.path.join(os.path.dirname(__file__),
 
367
        "templates/exercise.html"))
370
368
    ex_stream = tmpl.generate(curctx)
371
369
    return {'name': exercise.name,
372
370
            'complete': curctx['complete_class'],
388
386
    into XML directly from RST."""
389
387
    permission = "edit"
390
388
    template = "templates/worksheet_edit.html"
391
 
    appname = "Edit Worksheet"
 
389
    tab = "subjects"
392
390
 
393
391
    def __init__(self, req, **kwargs):
394
392