# -*- coding: utf-8 # Copyright 2005 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import StringField, LinesField from Products.Archetypes.public import LinesWidget, TextAreaWidget, IdWidget, StringWidget, SelectionWidget from Products.Archetypes.public import BaseContent, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from Permissions import * from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME, MODULE_LIST schema = BaseSchema + Schema(( #StringField('title', # required=1, # searchable=1, # isMetadata=1, # default='', # accessor='getTitle', # widget=StringWidget( # label_msgid='label_title', # description_msgid='help_title', # i18n_domain="krihvel"), # ), # LinesField('Target', # required=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', # visible={'view' : 'visible'}, # i18n_domain="krihvel"), # ), LinesField('Exercise', required=1, accessor="getExercise", isMetadata=1, vocabulary='getExercises', widget=SelectionWidget( format="radio", label="Exercise", label_msgid='label_ex', description="Which exercise you wish to use", description_msgid='desc_exercise', visible={'view' : 'visible'}, i18n_domain="krihvel"), ), )) class BaseTask(BaseContent): """ Template tasks. """ meta_type = "BaseTask" archetype_name = "BaseTask" global_allow = 1 allowed_content_types = [] security = ClassSecurityInfo() _at_rename_after_creation = True content_icon='task_icon.gif' schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/base_view', 'permissions': ('Manage portal',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/task_choice', 'permissions': ('View',), }, ) # def _renameAfterCreation(self, check_auto_id=False): # """ manage_afterPortalFactoryCreate """ # typestool = getToolByName(self, 'portal_types') # puf_type = getattr(typestool, self.getExercise()[0], None) # if not puf_type: # return 0 # puf_type.global_allow = 1 # self.aq_parent._delObject(self.id) # new_id = self.invokeFactory(self.getExercise()[0], id=self.id, title=self.title) # puf_type.global_allow = 0 # new_obj = getattr(self, new_id) # if self.getExercise()[0]=="WordMap": # new_obj.initializeVariables() # return self.aq_parent def createTask(self, REQUEST): """ manage_afterPortalFactoryCreate """ exercise = REQUEST.get("choice") typestool = getToolByName(self, 'portal_types') puf_type = getattr(typestool, exercise, None) if not puf_type: return 0 puf_type.global_allow = 1 self.aq_parent._delObject(self.id) new_id = self.invokeFactory(exercise, id=self.id, title="") puf_type.global_allow = 0 new_obj = getattr(self, new_id) if exercise=="WordMap": new_obj.initializeVariables() return new_obj def getInfo(self): """ Tere """ return "Tere!" def getClasses(self): """ Classes massive """ classes = ['I','II'] return classes def getExercises(self): """ All Exercises list """ return MODULE_LIST def getAllImages(self): """ Gets all images from users homefolder and returns list of them """ #query_string = {'Type': ('Image')} #pcatalog = getToolByName(self, 'portal_catalog') #results = pcatalog.searchResults(query_string) #return results user = str(REQUEST.AUTHENTICATED_USER) homefolder = self.portal_membership.getHomeFolder(user) return id def getImagesFromUsersHomeFolder(self, user): """ Gets all images from users homefolder and returns list of them """ user=str(user) homefolder = self.portal_membership.getHomeFolder(user) result =[] for img in homefolder.objectValues('ATImage'): result.append(img) return result def getExerciseJS(self, ex): """ Exercise JS""" return "javascript:setChoice('"+ex+"');" def renderStringForJS(self, string): """ render string for JS""" return "'"+str(string)+"'" def renderString2ForJS(self, string1, string2): """ render string for JS""" return "'"+str(string1)+str(string2)+"'" def getAnswers(self, target): """ Answers """ query_string = {'Type': ('PaperAnswer','CrosswordAnswer', 'WordMap'), 'SearchableText': {'operator': 'or', 'query': (target,)}} pcatalog = getToolByName(self, 'portal_catalog') results = pcatalog.searchResults(query_string) return results def getRemoteUrl(self): return self.absolute_url() def getFullName(self, username): return self.portal_membership.getMemberById(username).fullname # def saveAnswer(self, answers): # user = 'metz' # homefolder = self.portal_membership.getHomeFolder(user) # id = homefolder.invokeFactory("Answer", id=self.id+'aaa', title="Vastus", Answer=answers) # return 1 registerType(BaseTask, PROJECT_NAME) #InitializeClass(BaseTask)