def test_getInterfaceRoot_when_root_reached(self): obj = self.set_parent( self.stub(), self.portal) self.replay() self.assertEqual(utils.getInterfaceRoot(obj, ITagRoot), self.portal)
def __init__(self, context, request, view, manager, data): self.context = context self.data = data self.request = request tags = getTagRootTags(context) tag_root = getInterfaceRoot(context, ITagRoot) root_path ='/'.join(tag_root.getPhysicalPath()) catalog_tool = getToolByName(context, "portal_catalog") query = {} query['object_provides'] = ITaggable.__identifier__ query['path'] = root_path tag_occurrence = {} for tag in tags: query['tags'] = safe_utf8(tag) tag_occurrence[tag] = len(catalog_tool(query)) weight_list = tag_occurrence.values() weight_list.sort() if weight_list: minimal = weight_list[:1][0] maximal = weight_list[-1:][0] maxsize = float(self.data.maxsize) minsize = float(self.data.minsize) tag_cloud = [] for tag in tags: try: size = float((maxsize * \ (tag_occurrence[tag] - minimal))) / \ float((maximal - minimal)) except ZeroDivisionError: size = 1 if tag_occurrence[tag] <= minimal or size < minsize: size = float(self.data.minsize) info = dict(title=tag, font_size=round(size, 1)) tag_cloud.append(info) tag_cloud.sort(lambda x, y: cmp(x['title'].lower(), y['title'].lower())) self.tag_cloud = tag_cloud else: self.tag_cloud = [] self.tag_root_url = tag_root.absolute_url()
def __init__(self, context, request, view, manager, data): self.context = context self.data = data self.request = request tags = getTagRootTags(context) tag_root = getInterfaceRoot(context, ITagRoot) root_path = '/'.join(tag_root.getPhysicalPath()) catalog_tool = getToolByName(context, "portal_catalog") query = {} query['object_provides'] = ITaggable.__identifier__ query['path'] = root_path tag_occurrence = {} for tag in tags: query['tags'] = tag.decode('utf-8') tag_occurrence[tag] = len(catalog_tool(query)) weight_list = tag_occurrence.values() weight_list.sort() if weight_list: minimal = weight_list[:1][0] maximal = weight_list[-1:][0] maxsize = float(self.data.maxsize) minsize = float(self.data.minsize) tag_cloud = [] for tag in tags: try: size = float((maxsize * \ (tag_occurrence[tag] - minimal))) / \ float((maximal - minimal)) except ZeroDivisionError: size = 1 if tag_occurrence[tag] <= minimal or size < minsize: size = float(self.data.minsize) info = dict(title=tag, font_size=round(size, 1)) tag_cloud.append(info) tag_cloud.sort(lambda x, y: cmp(x['title'], y['title'])) self.tag_cloud = tag_cloud else: self.tag_cloud = [] self.tag_root_url = tag_root.absolute_url()
def test_getInterfaceRoot(self): root = self.providing_stub([ITagRoot]) obj = self.set_parent( self.stub(), self.set_parent( self.stub(), self.set_parent( root, self.portal))) self.replay() self.assertEqual(utils.getInterfaceRoot(obj, ITagRoot), root)
def __call__(self): self.tag_root = getInterfaceRoot(self.context, ITagRoot) return self.template()
def update(self): context = aq_inner(self.context).aq_explicit self.tags = getattr(context, 'tags', []) self.tag_root_url = getInterfaceRoot(context, ITagRoot).absolute_url()