Ejemplo n.º 1
0
    def __init__(self, parent, idevice):
        """
        Pre-create our field ids
        """
        Block.__init__(self, parent, idevice)

        # to compensate for the strange unpickling timing when objects are
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.instructionsForLearners.idevice is None:
            idevice.instructionsForLearners.idevice = idevice
        if idevice.content.idevice is None:
            idevice.content.idevice = idevice
        if idevice.feedback.idevice is None:
            idevice.feedback.idevice = idevice

        self.instructionElement = \
            TextAreaElement(idevice.instructionsForLearners)
        self.DropDownElement = DropDownElement(idevice.content)
        self.feedbackElement = \
            TextAreaElement(idevice.feedback)
        self.previewing = False  # In view or preview render
        if not hasattr(self.idevice, 'undo'):
            self.idevice.undo = True
Ejemplo n.º 2
0
    def __init__(self, parent, idevice):
        """
        Pre-create our field ids
        """
        Block.__init__(self, parent, idevice)

        # to compensate for the strange unpickling timing when objects are 
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.instructionsForLearners.idevice is None: 
            idevice.instructionsForLearners.idevice = idevice
        if idevice.content.idevice is None: 
            idevice.content.idevice = idevice
        if idevice.feedback.idevice is None: 
            idevice.feedback.idevice = idevice

        self.instructionElement = \
            TextAreaElement(idevice.instructionsForLearners)
        self.DropDownElement = DropDownElement(idevice.content)
        self.feedbackElement = \
            TextAreaElement(idevice.feedback)
        self.previewing        = False # In view or preview render
        if not hasattr(self.idevice,'undo'): 
            self.idevice.undo = True
Ejemplo n.º 3
0
class DropDownBlock(Block):
    """
    Renders a paragraph where the content creator can choose which words the
    student must fill in.
    """
    def __init__(self, parent, idevice):
        """
        Pre-create our field ids
        """
        Block.__init__(self, parent, idevice)

        # to compensate for the strange unpickling timing when objects are 
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.instructionsForLearners.idevice is None: 
            idevice.instructionsForLearners.idevice = idevice
        if idevice.content.idevice is None: 
            idevice.content.idevice = idevice
        if idevice.feedback.idevice is None: 
            idevice.feedback.idevice = idevice

        self.instructionElement = \
            TextAreaElement(idevice.instructionsForLearners)
        self.DropDownElement = DropDownElement(idevice.content)
        self.feedbackElement = \
            TextAreaElement(idevice.feedback)
        self.previewing        = False # In view or preview render
        if not hasattr(self.idevice,'undo'): 
            self.idevice.undo = True

    def process(self, request):
        """
        Handles changes in the paragraph text from editing
        """
        is_cancel = common.requestHasCancel(request)

        if "title"+self.id in request.args \
        and not is_cancel:
            self.idevice.title = request.args["title"+self.id][0]
        object = request.args.get('object', [''])[0]
        action = request.args.get('action', [''])[0]
        self.instructionElement.process(request)
        self.DropDownElement.process(request)
        #self.feedbackElement.process(request)
        Block.process(self, request)

    def renderEdit(self, style):
        """
        Renders a screen that allows the user to enter paragraph text and choose
        which words are hidden.
        """
        html = [
            u'<div class="iDevice">',
            u'<div class="block">',
            common.textInput("title"+self.id, self.idevice.title),
            u'</div>',
            self.instructionElement.renderEdit(),
            self.DropDownElement.renderEdit(),
            #self.feedbackElement.renderEdit(),
            self.renderEditButtons(),
            u'</div>'
            ]
        return u'\n    '.join(html)
    
    def renderPreview(self, style):
        """ 
        Remembers if we're previewing or not, 
        then implicitly calls self.renderViewContent (via Block.renderPreview) 
        """ 
        self.previewing = True 
        return Block.renderPreview(self, style)

    def renderView(self, style):
        """ 
        Remembers if we're previewing or not, 
        then implicitly calls self.renderViewContent (via Block.renderPreview) 
        """ 
        self.previewing = False 
        return Block.renderView(self, style)

    def renderViewContent(self):
        """
        Returns an XHTML string for this block
        """
        # Only show feedback button if feedback is present
#        if self.feedbackElement.field.content.strip():
#            # Cloze Idevice needs id of div for feedback content
#            feedbackID = self.feedbackElement.id
#            if self.previewing: 
#                clozeContent = self.DropDownElement.renderPreview(feedbackID)
#            else: 
#                clozeContent = self.DropDownElement.renderView(feedbackID)
#        else:
        if self.previewing: 
            clozeContent = self.DropDownElement.renderPreview()
        else:
            clozeContent = self.DropDownElement.renderView()
        instruction_html = ""
        if self.previewing: 
            instruction_html = self.instructionElement.renderPreview()
        else:
            instruction_html = self.instructionElement.renderView()
        html = [
            u'<script type="text/javascript" src="common.js"></script>\n',
            u'<div class="iDevice_inner">\n',
            instruction_html,
            clozeContent]
#        if self.feedbackElement.field.content: 
#            if self.previewing: 
#                html.append(self.feedbackElement.renderPreview(False, 
#                                                     class_="feedback"))
#            else:
#                html.append(self.feedbackElement.renderView(False, 
#                                                     class_="feedback"))
        html += [
            u'</div>\n',
            ]
        return u'\n    '.join(html)

    def renderText(self): 
        
        """
        Returns an XHTML string for text file export.
        """
        
        if self.previewing: 
            html = '<p>' +  self.instructionElement.renderPreview() +'</p>'
        else:
            html = '<p>' +  self.instructionElement.renderView() +'</p>'
        html += '<p>' + self.DropDownElement.renderText() + '</p>'
#        if self.feedbackElement.field.content:
#            html += '<p>%s:</P>' % _(u"Feedback") 
#            if self.previewing: 
#                html += '<p>' +self.feedbackElement.renderPreview(False, 
#                                                        class_="feedback") 
#                html += '</p>'
#            else:
#                html += '<p>' +self.feedbackElement.renderView(False, 
#                                                        class_="feedback") 
#                html += '</p>'
        html += self.DropDownElement.renderAnswers()
        return html
Ejemplo n.º 4
0
class DropDownBlock(Block):
    """
    Renders a paragraph where the content creator can choose which words the
    student must fill in.
    """
    def __init__(self, parent, idevice):
        """
        Pre-create our field ids
        """
        Block.__init__(self, parent, idevice)

        # to compensate for the strange unpickling timing when objects are
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.instructionsForLearners.idevice is None:
            idevice.instructionsForLearners.idevice = idevice
        if idevice.content.idevice is None:
            idevice.content.idevice = idevice
        if idevice.feedback.idevice is None:
            idevice.feedback.idevice = idevice

        self.instructionElement = \
            TextAreaElement(idevice.instructionsForLearners)
        self.DropDownElement = DropDownElement(idevice.content)
        self.feedbackElement = \
            TextAreaElement(idevice.feedback)
        self.previewing = False  # In view or preview render
        if not hasattr(self.idevice, 'undo'):
            self.idevice.undo = True

    def process(self, request):
        """
        Handles changes in the paragraph text from editing
        """
        is_cancel = common.requestHasCancel(request)

        if "title"+self.id in request.args \
        and not is_cancel:
            self.idevice.title = request.args["title" + self.id][0]
        object = request.args.get('object', [''])[0]
        action = request.args.get('action', [''])[0]
        self.instructionElement.process(request)
        self.DropDownElement.process(request)
        #self.feedbackElement.process(request)
        Block.process(self, request)

    def renderEdit(self, style):
        """
        Renders a screen that allows the user to enter paragraph text and choose
        which words are hidden.
        """
        html = [
            u'<div class="iDevice">',
            u'<div class="block">',
            common.textInput("title" + self.id, self.idevice.title),
            u'</div>',
            self.instructionElement.renderEdit(),
            self.DropDownElement.renderEdit(),
            #self.feedbackElement.renderEdit(),
            self.renderEditButtons(),
            u'</div>'
        ]
        return u'\n    '.join(html)

    def renderPreview(self, style):
        """ 
        Remembers if we're previewing or not, 
        then implicitly calls self.renderViewContent (via Block.renderPreview) 
        """
        self.previewing = True
        return Block.renderPreview(self, style)

    def renderView(self, style):
        """ 
        Remembers if we're previewing or not, 
        then implicitly calls self.renderViewContent (via Block.renderPreview) 
        """
        self.previewing = False
        return Block.renderView(self, style)

    def renderViewContent(self):
        """
        Returns an XHTML string for this block
        """
        # Only show feedback button if feedback is present
        #        if self.feedbackElement.field.content.strip():
        #            # Cloze Idevice needs id of div for feedback content
        #            feedbackID = self.feedbackElement.id
        #            if self.previewing:
        #                clozeContent = self.DropDownElement.renderPreview(feedbackID)
        #            else:
        #                clozeContent = self.DropDownElement.renderView(feedbackID)
        #        else:
        if self.previewing:
            clozeContent = self.DropDownElement.renderPreview()
        else:
            clozeContent = self.DropDownElement.renderView()
        instruction_html = ""
        if self.previewing:
            instruction_html = self.instructionElement.renderPreview()
        else:
            instruction_html = self.instructionElement.renderView()
        html = [
            u'<script type="text/javascript" src="common.js"></script>\n',
            u'<div class="iDevice_inner">\n', instruction_html, clozeContent
        ]
        #        if self.feedbackElement.field.content:
        #            if self.previewing:
        #                html.append(self.feedbackElement.renderPreview(False,
        #                                                     class_="feedback"))
        #            else:
        #                html.append(self.feedbackElement.renderView(False,
        #                                                     class_="feedback"))
        html += [
            u'</div>\n',
        ]
        return u'\n    '.join(html)

    def renderText(self):
        """
        Returns an XHTML string for text file export.
        """

        if self.previewing:
            html = '<p>' + self.instructionElement.renderPreview() + '</p>'
        else:
            html = '<p>' + self.instructionElement.renderView() + '</p>'
        html += '<p>' + self.DropDownElement.renderText() + '</p>'
        #        if self.feedbackElement.field.content:
        #            html += '<p>%s:</P>' % _(u"Feedback")
        #            if self.previewing:
        #                html += '<p>' +self.feedbackElement.renderPreview(False,
        #                                                        class_="feedback")
        #                html += '</p>'
        #            else:
        #                html += '<p>' +self.feedbackElement.renderView(False,
        #                                                        class_="feedback")
        #                html += '</p>'
        html += self.DropDownElement.renderAnswers()
        return html