# -*- coding: utf-8 # Copyright 2006 by Pjotr Savitski 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 Products.Archetypes.public import OrderedBaseFolder, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME schema = BaseSchema + Schema(( TextField('folio_description', accessor='getFolio_description', isMetadata=False, required=False, searchable=False, validators = ('isTidyHtmlWithCleanup',), default_output_type = 'text/x-html-safe', allowable_content_types = ('text/html',), widget = RichWidget( label="Product description", description="", allow_file_upload = False, label_msgid="label_icampfolio_description", description_msgid="description_icampfolio_description", visible={'view':'visible','edit':'visible'}, i18n_domain="plone", rows=25 ) ), )) class iCampFolio(OrderedBaseFolder): """ Folder for iCampTools and Affordances """ meta_type = "iCampFolio" archetype_name = "iCampFolio" global_allow = 0 exclude_from_nav = False allowed_content_types = ('iCampTool', 'Affordance') filter_content_types = True security = ClassSecurityInfo() _at_rename_after_creation = True schema = schema content_icon = 'icampfolio_icon.gif' # A placeholder for all known users. Used by Java for populating the list of users. # Structure: [gnum, juku, kati, mati] allUsers = [] # A placeholder for usernames and their values for parameters (perspectives). Used by Java. # Structure: {'gnum':{'paramID':'paramValue', ...}, 'pjotr':{'paramID':'paramValue', ...}, ...} userData = {} actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/mainindex_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Manage Portal',), }, ) right_slots = () def getAllParameters(self): """ Returns all parameters in iCampFolio folder """ return self.objectValues('Affordance') def getAllParameterTitles(self): """ Returns all Titles of parameters in iCampFolio """ res = [] parameters = self.objectValues('Affordance') for p in parameters: res.append(p.Title()) return res def getAllTools(self): """ Returns all tools in iCampFolio folder """ return self.objectValues('iCampTool') # This method dynamically sends all data of "numeric" fields to Java (see - "ontofilelist.txt") def ToolView(self): """ sends tool values directly to Java """ iGeneralDataHolder = "\tlinks" objs = self.objectValues('iCampTool') param_titles = self.getAllParameterTitles() for x in param_titles: iGeneralDataHolder += '\t'+x iGeneralDataHolder += '\n' for obj in objs: iObjectDataLine = obj.Title() iObjectDataLine += '\t'+obj.absolute_url() iObjectDataLine += obj.getToolParameterValues() iObjectDataLine += '\n' iGeneralDataHolder += iObjectDataLine return iGeneralDataHolder # This one does about the same but the values from userData to Java (see - "ontofilelist.java") def UserView(self): """ sends user values to Java """ iGeneralUserHolder = "\tlinks" objs = self.objectValues('iCampTool') portal_url = getToolByName(self, 'portal_url').getPortalObject().absolute_url() param_titles = self.getAllParameterTitles() parameters = self.getAllParameters() f = self.userData.keys() for x in param_titles: iGeneralUserHolder += '\t'+x iGeneralUserHolder += '\n' if len(f)>0: for y in f: iUserDataLine = y iUserDataLine += '\t'+portal_url+'/author/'+y for p in parameters: if p.UID() in self.userData[y].keys(): iUserDataLine += '\t'+self.userData[y][p.UID()] else: iUserDataLine += '\t'+str(0) iUserDataLine += '\n' iGeneralUserHolder += iUserDataLine return iGeneralUserHolder # This method puts the data for Tools and Users together and then sends it to Java (see - "ontofilelist.java") def ToolsAndUsersView(self): """ sends tool and user values to java """ iGeneralDataHolder = "\tlinks" objs = self.objectValues('iCampTool') portal_url = getToolByName(self, 'portal_url').getPortalObject().absolute_url() param_titles = self.getAllParameterTitles() parameters = self.getAllParameters() f = self.userData.keys() for x in param_titles: iGeneralDataHolder += '\t'+x iGeneralDataHolder += '\n' for obj in objs: iObjectDataLine = obj.Title() iObjectDataLine += '\t'+obj.absolute_url() full_objects = obj.getToolParameterValues().split('\t') for x in full_objects: if x != '': iObjectDataLine += '\t'+str(float(x)/10.0) iObjectDataLine += '\n' iGeneralDataHolder += iObjectDataLine if len(f)>0: for y in f: iUserDataLine = y iUserDataLine += '\t'+portal_url+'/author/'+y for p in parameters: if p.UID() in self.userData[y].keys(): iUserDataLine += '\t'+self.userData[y][p.UID()] else: iUserDataLine += '\t'+str(0) iUserDataLine += '\n' iGeneralDataHolder += iUserDataLine return iGeneralDataHolder # This method sends Current User Name to Java, if user is Anonymous - then empty string is sent def getCurrentUserName(self): """ Current user name to the applet """ ptool = getToolByName(self, 'portal_membership') uname = ptool.getAuthenticatedMember().getId() # anonymous user should not be able to save if uname != None: cur_user = uname else: cur_user = " " return cur_user # This method gets all usernames form allUsers and sends it to Java as string def getUserNamesAsText(self, REQUEST): """ Send usernames to applet """ t="" for u in self.allUsers: t += u + " " return t # This method is called on the ionto_view template before Java, if the Current User is not in list - puts him there def addCurrentUser(self): """ Add current user to the list """ ptool = getToolByName(self, 'portal_membership') uname = ptool.getAuthenticatedMember().getId() if uname not in self.allUsers: if uname != None: self.allUsers.append(uname) self.allUsers=self.allUsers return "Username Added" # This method gets user parameter values from userData where uname is selected user name def getUserParameterValues(self, REQUEST, uname): """ Lets us get the userdata """ t="" parameters = self.getAllParameters() k = self.userData.keys() # Check if user has saved any information if uname in k: # Values for parameters should be separated by " " - Java applet data structure requirement for p in parameters: # If there is a value for parameters - use that, if not - just use 0 instead if p.UID() in self.userData[uname].keys(): t = t + str(self.userData[uname][p.UID()]) + " " else: t = t + str(0) + " " else: # If user has no data - use 0 as a value for every parameter for x in parameters: t = t + str(0) + " " return t # This method saves parameter values for Current User def setUserParameterValues(self, p=()): """ Let us save the userdata """ ptool = getToolByName(self, 'portal_membership') uname = ptool.getAuthenticatedMember().getId() user_data = {} i = 0 parameters = self.getAllParameters() # If length of what we get differs from the length of parameters - that data can not be saved if len(p) != len(parameters):return "Data size not equal" # Take value prom returned values for each parameter for param in parameters: user_data[param.UID()] = str(p[i]) i += 1 # Add user data into main container self.userData[uname] = user_data self.userData=self.userData return "Userdata saved" registerType(iCampFolio, PROJECT_NAME)