# -*- 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 BaseFunctions import BaseFunctions from AccessControl import ClassSecurityInfo, Unauthorized import string from config import PROJECT_NAME, MODULE_LIST schema = BaseSchema class TaskCollector(BaseContent, BaseFunctions): """ Template answers. """ meta_type = "TaskCollector" archetype_name = "TaskCollector" global_allow = 1 allowed_content_types = [] security = ClassSecurityInfo() content_icon='taskcollector_icon.gif' schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/task_collector_view', 'permissions': ('View',), }, ) security.declareProtected('View', 'getTasks') def getTasks(self, member, tags): """ Tasks """ tasks = [] groupstool = getToolByName(self, 'portal_groups') groups = groupstool.listGroupIds() targets = ['All users',] for target in groups: target2 = groupstool.getGroupById(target) for md in target2.getGroupMembers(): if md.id == str(member): targets.append(target) pc = getToolByName(self, 'portal_catalog') results = pc.searchResults() res = [x for x in results if x.meta_type in MODULE_LIST] for r in res: for target in targets: if target in r.getTarget: if tags and tags != 'all' and tags in r.getTags: tasks.append(r) elif tags == 'all': tasks.append(r) return tasks security.declareProtected('View', 'getMyGr') def getMyGr(self): """ Classes massive """ classes = [] member = str(self.REQUEST.AUTHENTICATED_USER) groupstool = getToolByName(self, 'portal_groups') groups = groupstool.listGroupIds() for target in groups: target2 = groupstool.getGroupById(target) for md in target2.getGroupMembers(): if md.id == member: classes.append(str(target)) return classes def makeTagCloud(self): """make tag cloud""" taglist = self.getTagListSortedByFrequency() if taglist != []: # find max and min frequency ranges = self.getRanges(taglist) # write out results to output, tags are written out alphabetically # with size indicating the relative frequency of their occurence return self.writeCloud(taglist, ranges) return "" def getTagListSortedByFrequency(self): raw_tags = {} pc = getToolByName(self, 'portal_catalog') res = pc({'portal_type':MODULE_LIST,}) for r in res: if hasattr(r, 'getTags'): for rt in r.getTags: if rt!='': rt = rt.strip() if raw_tags.has_key(rt): raw_tags[rt] = raw_tags[rt] + 1 else: raw_tags[rt] = 1 taglist = [] for ts in raw_tags: taglist.append((ts, raw_tags[ts])) # sort tagdict by count taglist.sort(lambda x, y: cmp(x[1], y[1])) return taglist def getRanges(self,taglist): mincount = taglist[0][1] maxcount = taglist[len(taglist) - 1][1] distrib = (maxcount - mincount) / 4; if (distrib == 0): distrib = 1 index = mincount ranges = [] while (index <= maxcount): range = (index, index + distrib) index = index + distrib ranges.append(range) return ranges def writeCloud(self, taglist, ranges): html = "" rangeStyle = ["smallestTag", "smallTag", "mediumTag", "largeTag", "largestTag"] # resort the tags alphabetically taglist.sort(lambda x, y: cmp(x[0], y[0])) for tag in taglist: rangeIndex = 0 for range in ranges: url = self.absolute_url()+"?show="+tag[0].strip() if (tag[1] >= range[0] and tag[1] <= range[1]): html+="" + tag[0] + ", " break rangeIndex = rangeIndex + 1 return html registerType(TaskCollector, PROJECT_NAME)