# -*- coding: utf-8 # Copyright 2005 by Vahur Rebas, Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import TextField from Products.Archetypes.public import RichWidget from AccessControl import ClassSecurityInfo from Products.Archetypes.public import registerType, BaseContent from Products.CMFCore.utils import getToolByName from Products.Krihvel.BaseTask import BaseTask, BaseAnswer from Products.Krihvel.config import PROJECT_NAME schema = BaseSchema + BaseTask.schema + Schema(( TextField('Exercise', accessor='getExercise', isMetadata=0, required=True, validators = ('isTidyHtmlWithCleanup',), default_output_type = 'text/x-html-safe', allowable_content_types = ('text/html',), widget = RichWidget( label="Exercise", description="", label_msgid='label_exercise', description_msgid='desc_exercise', visible={'view':'visible','edit':'visible'}, i18n_domain="krihvel", rows = 25) ), TextField('Answer', accessor='getAnswer', isMetadata=0, validators = ('isTidyHtmlWithCleanup',), default_output_type = 'text/x-html-safe', allowable_content_types = ('text/html',), widget = RichWidget( label="Answer", description="", label_msgid='label_answer', description_msgid='desc_answer', visible={'view':'visible','edit':'visible'}, i18n_domain="krihvel", rows = 25) ), )) class Paper(BaseTask): """ Paper module. """ meta_type = "Paper" archetype_name = "Paper" allowed_content_types = [] global_allow = 0 security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/paper_answer', 'permissions': ('View',), }, ) def saveAnswer(self, REQUEST): """ Saves Answer """ user = str(REQUEST.AUTHENTICATED_USER) homefolder = self.portal_membership.getHomeFolder(user) answers = REQUEST.get('answer') number = 1 typestool = getToolByName(self, 'portal_types') puf_type = getattr(typestool, 'PaperAnswer', None) if not puf_type: return 0 puf_type.global_allow = 1 while hasattr(homefolder, 'PaperAnswer-'+str(number)): number = number+1 newid = 'PaperAnswer-'+str(number) id = homefolder.invokeFactory("PaperAnswer", id=newid, title=self.title, Exercise=self.Exercise, Instruction=self.Instruction, Answer=answers, Target=self.id) copiedObj = getattr(homefolder,id) puf_type.global_allow = 0 return copiedObj registerType(Paper, PROJECT_NAME) class PaperAnswer(BaseAnswer): """ Paper module. """ meta_type = "PaperAnswer" archetype_name = "PaperAnswer" allowed_content_types = [] global_allow = 0 security = ClassSecurityInfo() content_icon='vastus.gif' schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/paper_answer', 'permissions': ('View',), }, ) def getRating(self): """ get Rating """ return 100 #here are nothing to calculate we just recommend best mark ;) registerType(PaperAnswer, PROJECT_NAME)