#-*- coding: utf-8 # Copyright 2005 by Vahur Rebas from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import BaseContent from Products.Archetypes.public import registerType from Products.Archetypes.public import StringField, StringWidget from Products.Archetypes.public import TextField, VisualWidget, IdWidget from AccessControl import ClassSecurityInfo from config import PROJECT_NAME from PhaseBase import PhaseBase from Permissions import * import copy my_base = BaseSchema + Schema(( StringField('id', required=0, mode = "r", widget= IdWidget(visible = -1), ), StringField('title', required = 0, mode = "r", widget = StringWidget(visible = -1), accessor = "getPhTitle", ), )) schema = my_base class PhaseI(PhaseBase, BaseContent): """ different phases """ meta_type = "PhaseI" archetype_name = "PhaseI" filter_content_types = 1 global_allow = 0 exclude_from_nav = True isPrincipiaFolderish = 0 security = ClassSecurityInfo() security.declareObjectPublic() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/prog_phaseI_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/prog_phaseI_edit', 'permissions': ('ModifyPortalContent',), }, ) def muuda_phaas(self): """ muuda """ self._phaseStatus = 1 def setPublish(self, ready, whole): if ready: self._phaseStatus = 2 else: self._phaseStatus = 0 if whole: klass = self.aq_parent.aq_parent massiiv = klass.objectValues('ProgressUserFolder') for opilane in massiiv: faas = opilane.PhaseI faas._phaseStatus = copy.copy(self._phaseStatus) def manage_afterAdd(self, item, container): """ init """ self.answers = {'1':['Jah/Ei',['Jah','Ei'],'1'], '2':['Tekstivastus',['tekst'],'0']} self.questions = {'id1':['Näidis küsimus','1']} def getAnswers(self): """ returns answers """ return self.answers def setAnswers(self, id, pname, answs, ansType, kas_koigile): """ id - id for answers pname - pretty name answs - answers(list) ansType - 0:free text(textarea), 1:one choice(radio button), 2:multiple choice(checkbox) """ try: self.answers.pop(id) except KeyError: pass if id == '0': # id is 0 and we create new import random, string id = "" chars = string.ascii_lowercase for x in range(5): nr = 0 while chr(nr) not in chars: nr = random.randint(65,122) id += chr(nr) if answs: self.answers[id] = [pname,answs,ansType] self._p_changed = True # kõigile salvestamine if kas_koigile: klass = self.aq_parent.aq_parent massiiv = klass.objectValues('ProgressUserFolder') for opilane in massiiv: faas = opilane.PhaseI faas.answers = copy.copy(self.answers) faas.questions = copy.copy(self.questions) return 1 def getQuestions(self): """ return self.questions """ return self.questions def setQuestions(self, nr, req, kas_koigile): """ data from request. saves questions """ self.questions = {} for x in range(nr): anstype = req.get('ansForQuiz'+str(x), None) question = req.get('question'+str(x), None) if (anstype is not None and question is not None) and (question): self.questions['id'+str(x)] = [question,anstype] self._p_changed = True # kõigile salvestamine if kas_koigile: klass = self.aq_parent.aq_parent massiiv = klass.objectValues('ProgressUserFolder') for opilane in massiiv: faas = opilane.PhaseI faas.questions = copy.copy(self.questions) faas.answers = copy.copy(self.answers) return 1 def getResponseType(self, quiz): """ tells if we deal with textarea, radio or check buttons """ x = self.getQuestions() y = self.getAnswers() try: result = y[x[quiz][1]][2] except KeyError: return -1 #answers[quizes[quiz][1]][2] return result def getResponseData(self, quiz): """ return possible answers """ y = self.getQuestions() x = self.getAnswers() return x[y[quiz][1]][1] def getPhTitle(self): return "Õpilase enesehinnang" def setUserResponses(self, REQUEST): self.userResp = {} for x in self.getQuestions(): #print x,REQUEST.get(x,'vastamata') self.userResp[x] = REQUEST.get(x,'vastamata') #print self.userResp[x] self.muuda_phaas() return 1 def getUserResponses(self, REQUEST): pass def getUserResp(self, quiz): return self.userResp[quiz] def getPhaseOwner(self): return self.aq_parent.getId() registerType(PhaseI, PROJECT_NAME) schema = my_base + Schema(( TextField('Contents', searchable = 0, required = 0, default_output_type = "text/html", allowable_content_types = ("text/plain", "text/restructured", "text/html", "application/msword"), widget = VisualWidget, write_permission = 'Edit phase content', #widget = VisualWidget(label="Contents", label_msgid="Contents", i18n_domain="plone"), ), )) class PhaseII(PhaseBase, BaseContent): """ different phases """ meta_type = "PhaseII" archetype_name = "PhaseII" filter_content_types = 1 global_allow = 0 exclude_from_nav = True isPrincipiaFolderish = 0 security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/base_view', 'permissions': ('Edit phase content',), }, ) def taasta_phaas(self): """ muuda """ self._phaseStatus = 0 def muuda_phaas(self): """ muuda """ self._phaseStatus = 1 def getPhTitle(self): return "Kiri lapsevanemale" registerType(PhaseII, PROJECT_NAME) class PhaseIII(PhaseBase, BaseContent): """ different phases """ meta_type = "PhaseIII" archetype_name = "PhaseIII" filter_content_types = 1 global_allow = 0 exclude_from_nav = True isPrincipiaFolderish = 0 security = ClassSecurityInfo() schema = schema allow_discussion = 1 actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/base_view', 'permissions': ('View phase content',), }, ) def taasta_phaas(self): """ muuda """ self._phaseStatus = 0 def muuda_phaas(self): """ muuda """ self._phaseStatus = 1 def getPhTitle(self): return "Taustateave" registerType(PhaseIII, PROJECT_NAME) class PhaseIV(PhaseBase, BaseContent): """ different phases """ meta_type = "PhaseIV" archetype_name = "PhaseIV" filter_content_types = 1 global_allow = 0 exclude_from_nav = True isPrincipiaFolderish = 0 security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/base_view', 'permissions': ('Edit phase content',), }, ) def taasta_phaas(self): """ muuda """ self._phaseStatus = 0 def muuda_phaas(self): """ muuda """ self._phaseStatus = 1 def getPhTitle(self): return "Arenguvestlus õpilasega" registerType(PhaseIV, PROJECT_NAME) class PhaseV(PhaseBase, BaseContent): """ different phases """ meta_type = "PhaseV" archetype_name = "PhaseV" filter_content_types = 1 global_allow = 0 exclude_from_nav = True isPrincipiaFolderish = 0 security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/base_view', 'permissions': ('Edit phase content',), }, ) def taasta_phaas(self): """ muuda """ self._phaseStatus = 0 def muuda_phaas(self): """ muuda """ self._phaseStatus = 1 def getPhTitle(self): return "Arenguvestlus lapsevanemaga" registerType(PhaseV, PROJECT_NAME) class PhaseVI(PhaseBase, BaseContent): """ different phases """ meta_type = "PhaseVI" archetype_name = "PhaseVI" filter_content_types = 1 global_allow = 0 exclude_from_nav = True isPrincipiaFolderish = 0 security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/base_view', 'permissions': ('Edit phase content',), }, ) def muuda_phaas(self): """ muuda """ self._phaseStatus = 1 def taasta_phaas(self): """ muuda """ self._phaseStatus = 0 def getPhTitle(self): return "Kokkuvõte" registerType(PhaseVI, PROJECT_NAME)