# -*- coding: utf-8 # Copyright 2006 by Pjotr Savitski from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import StringField, LinesField, DateTimeField, TextField, FileField from Products.Archetypes.public import LinesWidget, TextAreaWidget, IdWidget, StringWidget, SelectionWidget, CalendarWidget, MultiSelectionWidget, RichWidget, FileWidget, LabelWidget from Products.Archetypes.public import BaseContent, registerType, BaseContentMixin, ExtensibleMetadata from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME schema = BaseSchema + Schema(( TextField('iToolDesc', required=0, accessor="getiToolDesc", searchable=0, isMetadata=0, default='', default_output_type='text/html', widget=TextAreaWidget( cols=40, rows=5, label="Description", label_msgid='label_itooldesc', i18n_domain="plone"), ), TextField('iOpsys', required=0, accessor="getiOpsys", searchable=0, isMetadata=0, default='', default_output_type='text/html', widget=TextAreaWidget( cols=40, rows=3, label="Operating system platform", label_msgid='label_iopsys', i18n_domain="plone"), ), TextField('iDevelplatform', required=0, accessor="getiDevelplatform", searchable=0, isMetadata=0, default='', default_output_type='text/html', widget=TextAreaWidget( cols=40, rows=3, label="Development platform (programming language)", label_msgid='label_idevelplatform', i18n_domain="plone"), ), TextField('iLicense', required=0, accessor="getiLicense", searchable=0, isMetadata=0, default='', default_output_type='text/html', widget=TextAreaWidget( cols=40, rows=3, label="License", label_msgid='label_ilicense', i18n_domain="plone"), ), TextField('iDatamansys', required=0, accessor="getiDatamansys", searchable=0, isMetadata=0, default='', default_output_type='text/html', widget=TextAreaWidget( cols=40, rows=3, label="Data management system (database)", label_msgid='label_idatamansys', i18n_domain="plone"), ), TextField('iAppserv', required=0, accessor="getiAppserv", searchable=0, isMetadata=0, default='', default_output_type='text/html', widget=TextAreaWidget( cols=40, rows=3, label="Application server", label_msgid='label_iappserv', i18n_domain="plone"), ), TextField('iSsidewebtec', required=0, accessor="getiSsidewebtec", searchable=0, isMetadata=0, default='', default_output_type='text/html', widget=TextAreaWidget( cols=40, rows=3, label="Server-side web technologies", label_msgid='label_issidewebtec', i18n_domain="plone"), ), TextField('iCsidewebtec', required=0, accessor="getiCsidewebtec", searchable=0, isMetadata=0, default='', default_output_type='text/html', widget=TextAreaWidget( cols=40, rows=3, label="Client-side web technologies (browser)", label_msgid='label_icsidewebtec', i18n_domain="plone"), ), TextField('iPortplat', required=0, accessor="getiPortplat", searchable=0, isMetadata=0, default='', default_output_type='text/html', widget=TextAreaWidget( cols=40, rows=3, label="Portal platform", label_msgid='label_iportplat', i18n_domain="plone"), ), TextField('iDataex', required=0, accessor="getiDataex", searchable=0, isMetadata=0, default='', default_output_type='text/html', widget=TextAreaWidget( cols=40, rows=3, label="Data exchange / syndication standards", label_msgid='label_idataex', i18n_domain="plone"), ), TextField('iMetadatastand', required=0, accessor="getiMetadatastand", searchable=0, isMetadata=0, default='', default_output_type='text/html', widget=TextAreaWidget( cols=40, rows=3, label="Metadata standards", label_msgid='label_imetadatastand', i18n_domain="plone"), ), TextField('iSecuritymod', required=0, accessor="getiSecuritymod", searchable=0, isMetadata=0, default='', default_output_type='text/html', widget=TextAreaWidget( cols=40, rows=3, label="Security model", label_msgid='label_isecuritymod', i18n_domain="plone"), ), TextField('iExtendabl', required=0, accessor="getiExtendabl", searchable=0, isMetadata=0, default='', default_output_type='text/html', widget=TextAreaWidget( cols=40, rows=3, label="Extendability / modularity", label_msgid='label_iextendabl', i18n_domain="plone"), ), TextField('iLoc', required=0, accessor="getiLoc", searchable=0, isMetadata=0, default='', default_output_type='text/html', widget=TextAreaWidget( cols=40, rows=3, label="Localisation", label_msgid='label_iloc', i18n_domain="plone"), ), TextField('iExtacc', required=0, accessor="getiExtacc", searchable=0, isMetadata=0, default='', default_output_type='text/html', widget=TextAreaWidget( cols=40, rows=3, label="External access to functionality", label_msgid='label_iextacc', i18n_domain="plone"), ), TextField('iUserbase', required=0, accessor="getiUserbase", searchable=0, isMetadata=0, default='', default_output_type='text/html', widget=TextAreaWidget( cols=40, rows=3, label="User base (who is using)", label_msgid='label_iuserbase', i18n_domain="plone"), ), )) class iCampTool(BaseContent): """ iCampTool object addable in the iCampFolio folder """ meta_type = "iCampTool" archetype_name = "iCampTool" global_allow = 0 exclude_from_nav = True allow_discussion = True allowed_content_types = [] security = ClassSecurityInfo() _at_rename_after_creation = True schema = schema content_icon='icamptool_icon.gif' # Define data holder for parameter values given by users # Structure {'userID':{'paramID':'paramValue', ...}, ...} # Structure example {'pjotr':{'aabbccdd':'5', 'ddccaabb':'5', ...}, 'juku':{'ddccbbaa':,'1', ...}, ...} paramData = {} actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/tool_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/tool_edit', 'permissions': ('Manage Portal',) }, {'id':'evaluate', 'name':'Evaluate', 'action':'string:${object_url}/evaluate_tool', 'permissions': ('View',), }, ) # Need to initialize value as soon as tool is created (or it'll be trying to take the same values as previously saved) def __init__(self, oid, **kwargs): BaseContentMixin.__init__(self, oid, **kwargs) ExtensibleMetadata.__init__(self) # Initialize our own data container self.paramData = {} # This method returns a list form 0 to 10 for value selections def getValuesForLists(self): """ get values for lists """ valuesForLists = ['0','1','2','3','4','5','6','7','8','9','10'] return valuesForLists def getParametersByUser(self): """ Gives list of parameter data""" ptool = getToolByName(self, 'portal_membership') user_id = ptool.getAuthenticatedMember().getId() user_param_data = self.paramData parameters = self.getAllParameters() results = [] # Check if there are any parameters if parameters: # For every parameter make an array ['UID','Title','Description','Value'] for p in parameters: one_param = [] one_param.append(p.UID()) one_param.append(p.Title()) one_param.append(p.getiDescription()) # Check if user has saved something; else - append 0 if user_id in user_param_data.keys(): # Get infor by user temp = user_param_data[user_id] if p.UID() in temp.keys(): # If current UID in keys, then take the value and append that to array; else - append 0 value = temp[p.UID()] one_param.append(value) else: one_param.append(0) else: one_param.append(0) # Append values for one parameter to returned array results.append(one_param) else: # If there are no parameters, then empty array will be given as a result return results return results def setParametersByUser(self, REQUEST): """ Saves parameters given by user """ ptool = getToolByName(self, 'portal_membership') parameters = self.getAllParameters() user_id = ptool.getAuthenticatedMember().getId() user_stuff = {} # Do not let anonymous user save anything if user_id == None: return REQUEST.RESPONSE.redirect(self.absolute_url()) # Taking values from REQUEST for existing parameters for p in parameters: # If REQUEST has a value for parameter, then we get that; else - value is set to 0 if REQUEST.has_key(p.UID()): value = REQUEST.get(p.UID()) else: value = 0 # Add value to list, using UID as a key user_stuff[p.UID()] = value # Add usr data to main data container or replace existing one with new self.paramData[user_id] = user_stuff self.paramData = self.paramData return REQUEST.RESPONSE.redirect(self.absolute_url()) def redirectBackToTool(self): """ Redirects back to tool """ REQUEST = self.REQUEST return REQUEST.RESPONSE.redirect(self.absolute_url()) # This method will get all values of tools and return that in a way Java applet can use def getToolParameterValues(self): """ Returns a average parameter values for tool """ parameters = self.getAllParameters() user_param_data = self.paramData all_param_values = {} devide_by = 1 values_returned = '' # If no users have saved the information, we devide value by 1, so that there would not be any devision by Zero if len(user_param_data.keys())>0: devide_by = len(user_param_data.keys()) # We get values by all users for every parameter for p in parameters: param_values = [] # We add an empty array all_param_values[p.UID()] = param_values for u in user_param_data: # If current UID has value assigned by user, then we get that; if not - we just set it to be 0 if p.UID() in user_param_data[u].keys(): all_param_values[p.UID()].append(user_param_data[u][p.UID()]) else: all_param_values[p.UID()].append(0) # Now we calculate an average for every parameter for t in parameters: # Get array of values for a parameter vals = all_param_values[t.UID()] # If there will be no values, then the final value will be set as 0 final_value = 0 # Sum all values for val in vals: final_value = final_value + int(val) # Make a float devision by 1 or a number of users, that have saved their information final_value = final_value / float(devide_by) # Add final value to returned string, also round it (value is converted to string) values_returned+= '\t'+str(round(final_value, 2)) return values_returned registerType(iCampTool, PROJECT_NAME)