# -*- coding: utf-8 # Copyright 2005 by Vahur Rebas from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import StringField, LinesField, TextField from Products.Archetypes.public import LinesWidget, TextAreaWidget, IdWidget, StringWidget, SelectionWidget, RichWidget from AccessControl import ClassSecurityInfo from Products.Archetypes.public import registerType, BaseContent from Products.CMFCore.utils import getToolByName from Products.Krihvel.BaseTask import BaseTask from Products.Krihvel.BaseAnswer import BaseAnswer from Products.Krihvel.config import PROJECT_NAME schema = BaseSchema + Schema(( LinesField('Target', required=1, searchable=1, accessor="getTarget", isMetadata=1, vocabulary='getClasses', widget=SelectionWidget( format="select", label="Target", label_msgid='label_target', description="Target whos get that task.", description_msgid='desc_target', i18n_domain="krihvel"), ), TextField('Exercise', accessor="getExercise", isMetadata=0, widget=RichWidget( allow_file_upload=0, label="Exercise", label_msgid='label_exercise', description="", description_msgid='desc_exercise', i18n_domain="krihvel"), ), TextField('Answer', accessor="getAnswer", isMetadata=0, widget=RichWidget( allow_file_upload=0, label="Answer", label_msgid='label_answer', description="", description_msgid='desc_answer', i18n_domain="krihvel"), ), TextField('Grade', searchable=0, accessor="getGrade", isMetadata=0, default='Sinu tööd ei ole veel hinnatud', widget=StringWidget( label="Grade", label_msgid='label_grade', description="", description_msgid='desc_grade', i18n_domain="krihvel"), ), TextField('Comment', accessor="getComment", isMetadata=0, default='Sinu tööd ei ole veel kommenteeritud', widget=RichWidget( allow_file_upload=0, label="Comment", label_msgid='label_comment', description="", description_msgid='desc_comment', i18n_domain="krihvel"), ), )) 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_view', 'permissions': ('View',), }, ) def _renameAfterCreation(self, check_auto_id=False): pass def saveAnswer(self, REQUEST, answers): """ Saves Answer """ user = str(REQUEST.AUTHENTICATED_USER) homefolder = self.portal_membership.getHomeFolder(user) 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, Answer=answers, Target=self.id) puf_type.global_allow = 0 return id 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_view', 'permissions': ('View',), }, ) def _renameAfterCreation(self, check_auto_id=False): pass def saveComment(self, REQUEST, grade, comment): """ Saves Comments """ self.Grade = str(grade) self.Comment = comment return 1 registerType(PaperAnswer, PROJECT_NAME)