EduploneExam/userresponses SessionResponse.py,NONE,1.1 SimpleResponse.py,1.12,1.13

Jens Klein <[email protected]>
Newsgroups gmane.comp.web.zope.eduplone.cvs
Message-ID <[email protected]>
Update of /cvsroot/eduplone/EduploneExam/userresponses
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2254/userresponses

Modified Files:
	SimpleResponse.py 
Added Files:
	SessionResponse.py 
Log Message:
added response for session storage


Index: SimpleResponse.py
===================================================================
RCS file: /cvsroot/eduplone/EduploneExam/userresponses/SimpleResponse.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** SimpleResponse.py	15 Dec 2004 13:56:04 -0000	1.12
--- SimpleResponse.py	16 Dec 2004 11:01:22 -0000	1.13
***************
*** 105,109 ****
  
  
!     def getQuestion(self):
          '''
          returns the referenced question object
--- 105,109 ----
  
  
!     def getQuestion(self, instance):
          '''
          returns the referenced question object
***************
*** 138,142 ****
  
  
!     def getContext(self):
          '''
          returns the context object
--- 138,142 ----
  
  
!     def getContext(self,instance):
          '''
          returns the context object

--- NEW FILE: SessionResponse.py ---
# File: SessionResponse.py
"""\
response object for temporary session storage

RCS-ID $Id: SessionResponse.py,v 1.1 2004/12/16 11:01:22 yenzenz Exp $
"""
# Copyright (c) 2004 by eduplone Open Source Business Network EEIG, contributed
# by FH-Aargau, Switzerland
#
# GNU General Public Licence (GPL)
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA  02111-1307  USA
#
__author__  = 'Nils Haagen, Jens Klein <[email protected]>, <[email protected]>'
__docformat__ = 'plaintext'

from Products.EduploneExam.interfaces.IExamResponse import IExamResponse
from Products.CMFCore.utils import getToolByName
from Products.Archetypes.config import UID_CATALOG

class SessionResponse:

    __implements__ = (IExamResponse,)

    _questionTitle=''
    _questionType=''
    _questionMaxScore=0
    _questionuid=None
    _contextuid=None
    _responseValues={}
    _userScore=0


    def setQuestion(self, question):
        '''
        sets the question as a reference and buffers some important values
        '''
        self._questionuid = question.UID()
        self._questionTitle=question.Title()
        self._questionType=question.archetype_name
        self._questionMaxScore=question.getMaxScore()

    def getQuestion(self, instance):
        '''
        returns the referenced question object
        '''
        return self._lookupUID(self._questionuid, instance)

    def _lookupUID(self, uid, instance):
        tool = getToolByName(instance, UID_CATALOG)
        brains = tool(UID=uid)
        for brain in brains:
            obj = brain.getObject()
            if obj is not None:
                return obj
        else:
            return None

    def getQuestionTitle(self):
        '''
        returns title of question
        '''
        return self._questionTitle

    def getQuestionType(self):
        '''
        returns type of question
        '''
        return self._questionType

    def setContext(self,context):
        '''
        set context as a reference
        '''
        self._contextuid = context.UID()


    def getContext(self, instance):
        '''
        returns the context object
        '''
        return self._lookupUID(self._contextuid, instance)

    def setScore(self, score):
        '''
        sets the user score
        '''
        self._userScore=score


    def getScore(self):
        '''
        returns the user score
        '''
        return self._userScore


    def getMaxScore(self):
        '''
        returns the buffered maxscore value
        '''
        return self._questionMaxScore


    def getResponseValues(self):
        '''
        returns a dictionary where key is the AnswerUID and value is whats a
        user said.
        '''
        return self._responseValues


    def setResponseValues(self, **kwargs):
        '''
        kwargs is a dictionary where key is AnswerUID and value is what a
        user said.
        '''
        self._responseValues=kwargs


    def __getitem__(self, key):
        '''
        returns a specific response value
        '''
        if self._responseValues.has_key(key):
            return self._responseValues[key]
        else:
            raise KeyError("Invalid key '%s' in SessionResponse." % key)



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.