# -*- 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 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(( # This product only needs the Title field that comes from the BaseSchema )) class iCampFolio(OrderedBaseFolder): """ Folder for iCampTools """ meta_type = "iCampFolio" archetype_name = "iCampFolio" global_allow = 0 exclude_from_nav = False allowed_content_types = ('iCampTool') filter_content_types = True security = ClassSecurityInfo() _at_rename_after_creation = True schema = schema content_icon = 'icampfolio_icon.gif' # It has structure: [gnum, juku, kati, mati] allUsers = [] # It has structure: {'gnum':'1\t1\t1\t1\t1\t1\t1\t1\t1', 'juku':'0\t0\t0\t0\t0\t0\t0\t0\t0'} 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 = () # 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') if len(objs)>0: obj = objs[0] fields = obj.Schemata()['numeric'].fields() for x in fields: iGeneralDataHolder += '\t'+x.widget.Label(obj) iGeneralDataHolder += '\n' for obj in objs: iObjectDataLine = obj.Title() iObjectDataLine += '\t'+obj.absolute_url() for field in fields: iObjectDataLine += '\t'+field.get(obj) 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') f = self.userData.keys() if len(objs)>0: obj = objs[0] fields = obj.Schemata()['numeric'].fields() for x in fields: iGeneralUserHolder += '\t'+x.widget.Label(obj) iGeneralUserHolder += '\n' if len(f)>0: for y in f: iUserDataLine = y #iUserDataLine += '\t'+portal_url()+'/author/'+y iUserDataLine += '\tnone' iUserDataLine += '\t' iUserDataLine += self.userData[y] 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') f = self.userData.keys() if len(objs)>0: obj = objs[0] fields = obj.Schemata()['numeric'].fields() for x in fields: iGeneralDataHolder += '\t'+x.widget.Label(obj) iGeneralDataHolder += '\n' for obj in objs: iObjectDataLine = obj.Title() iObjectDataLine += '\t'+obj.absolute_url() for field in fields: iObjectDataLine += '\t'+str(float(field.get(obj))/10.0) iObjectDataLine += '\n' iGeneralDataHolder += iObjectDataLine if len(objs)>0: if len(f)>0: for y in f: iUserDataLine = y #iUserDataLine += '\t'+portal_url()+'/author/'+y iUserDataLine += '\tnone' iUserDataLine += '\t' iUserDataLine += self.userData[y] 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, REQUEST): """ Current user name to the applet """ uname = str(REQUEST.AUTHENTICATED_USER) # anonymous user should not be able to save if uname != 'Anonymous User': 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="" uname = str(REQUEST.AUTHENTICATED_USER) 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, REQUEST): """ Add current user to the list """ uname = str(REQUEST.AUTHENTICATED_USER) if uname not in self.allUsers: if uname != 'Anonymous User': 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="" #uname = str(REQUEST.AUTHENTICATED_USER) objs = self.objectValues('iCampTool') # a list for testing # theData = {'gnum':'1\t2\t3', 'juku':'3\t2\t1'} k = self.userData.keys() if uname in k: udat = self.userData[uname] impAll = udat.split('\t') for imp in impAll: t = t + str(imp) + " " else: if len(objs)>0: obj = objs[0] fields = obj.Schemata()['numeric'].fields() for x in fields: t = t + str(0) + " " return t # This method saves parameter values for Current User def setUserParameterValues(self, REQUEST, p=()): """ Let us save the userdata """ t="" uname = str(REQUEST.AUTHENTICATED_USER) objs = self.objectValues('iCampTool') i = 0 if len(objs)>0: obj = objs[0] fields = obj.Schemata()['numeric'].fields() if len(p) != len(fields):return "Data size not equal" for x in fields: if i == 0: t += str(p[i]) i += 1 else: t += "\t"+str(p[i]) i += 1 self.userData[uname] = t self.userData=self.userData return "Userdata saved" registerType(iCampFolio, PROJECT_NAME)