EduploneExamPersistence/userresponses PersistentResponse.py,1.2,1.3
Nils Haagen <[email protected]> Sun, 15 May 2005 12:43:50 +0000
| Newsgroups | gmane.comp.web.zope.eduplone.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/eduplone/EduploneExamPersistence/userresponses
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7993/userresponses
Modified Files:
PersistentResponse.py
Log Message:
stores PersistentResponse as content-object in the Memberfolder. this is just temporarily - and should move to memberobject...
Index: PersistentResponse.py
===================================================================
RCS file: /cvsroot/eduplone/EduploneExamPersistence/userresponses/PersistentResponse.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PersistentResponse.py 25 Feb 2005 19:40:13 -0000 1.2
--- PersistentResponse.py 15 May 2005 12:43:48 -0000 1.3
***************
*** 29,42 ****
from Products.Archetypes.public import *
- from Products.EduploneExam.userresponses.SessionResponse import SessionResponse
-
- #from Products.EduploneExamPersistence.interfaces.IExamResponse import IExamResponse
- #from Products.EduploneExamPersistence.interfaces.IExamResponse import IExamResponse
##code-section module-header #fill in your manual code here
! ##/code-section module-header
! class PersistentResponse(SessionResponse):
security = ClassSecurityInfo()
portal_type = meta_type = 'PersistentResponse'
--- 29,43 ----
from Products.Archetypes.public import *
##code-section module-header #fill in your manual code here
! from Products.EduploneExam.interfaces.IExamResponse import IExamResponse
! from Products.CMFCore.utils import getToolByName
! from Products.Archetypes.config import UID_CATALOG
! from ExtensionClass import Base
+ ##/code-section module-header
! #class PersistentResponse(Base):
! class PersistentResponse(BaseContent):
security = ClassSecurityInfo()
portal_type = meta_type = 'PersistentResponse'
***************
*** 44,49 ****
allowed_content_types = []
! __implements__ = getattr(SessionResponse,'__implements__',())
##code-section class-header #fill in your manual code here
--- 45,60 ----
allowed_content_types = []
! security.declareObjectPublic()
! security.setDefaultAccess("allow")
+ __implements__ = (IExamResponse,)
+
+ _questionTitle=''
+ _questionType=''
+ _questionMaxScore=0
+ _questionuid=None
+ _contextuid=None
+ _responseValues={}
+ _userScore=0
##code-section class-header #fill in your manual code here
***************
*** 65,68 ****
--- 76,178 ----
#Methods
+ 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
+
+
+ security.declarePublic('getQuestionType')
+ 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
+ self._p_changed = 1
+
+
+ def __getitem__(self, key):
+ '''
+ returns a specific response value
+ '''
+ if self._responseValues.has_key(key):
+ return self._responseValues[key]
+ else:
+ return None
+
# uncomment lines below when you need
***************
*** 83,87 ****
! InitializeClass(PersistentResponse)
# end of class PersistentResponse
--- 193,198 ----
! #InitializeClass(PersistentResponse)
! registerType(PersistentResponse)
# end of class PersistentResponse
-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7393&alloc_id=16281&op=click