def get_namespace(self, resource, context): namespace = {} allowed_to_edit = self.is_admin(resource, context) # Subsections (siblings) items = self.get_items(resource, context) namespace['items'] = items namespace['title'] = self.get_toc_title(resource, context) # Hide siblings box if the user is not authenticated and # submenu is empty # FIXME hide_if_only_one_item is defined on bar_item # But we call GET with resource=section min_limit = 1 #if resource.get_property('hide_if_only_one_item') else 0 hide_if_not_enough_items = len(items) <= min_limit if allowed_to_edit is False and hide_if_not_enough_items: self.set_view_is_empty(True) namespace['hide_if_not_enough_items'] = hide_if_not_enough_items namespace['limit'] = min_limit # Admin link admin_link = None if allowed_to_edit and is_navigation_mode(context) is False: section_path = context.get_link(resource) admin_link = {'href': '%s/;order_items' % section_path, 'title': MSG(u'Select & Order')} namespace['admin_link'] = admin_link return namespace
def edition_tabs(self): views = [] if self.show_edition_tabs is False: return [] context = self.context navigation_mode = is_navigation_mode(context) # edit mode views.append({'name': '/;fo_switch_mode?mode=1', 'label': MSG(u'On'), 'class': 'active' if not navigation_mode else None}) views.append({'name': '/;fo_switch_mode?mode=0', 'label': MSG(u'Off'), 'class': 'active' if navigation_mode else None}) return views
def edition_tabs(self): views = [] if self.show_edition_tabs is False: return [] context = self.context navigation_mode = is_navigation_mode(context) # edit mode views.append({ 'name': '/;fo_switch_mode?mode=1', 'label': MSG(u'On'), 'class': 'active' if not navigation_mode else None }) views.append({ 'name': '/;fo_switch_mode?mode=0', 'label': MSG(u'Off'), 'class': 'active' if navigation_mode else None }) return views
def get_namespace(self, resource, context): product = context.resource namespace = {} show_cover = resource.get_property('show_cover') show_loupe = resource.get_property('show_loupe') change_img_on_hover = resource.get_property('change_img_on_hover') activate_lightbox = resource.get_property('activate_lightbox') # Informations about product namespace['cover'] = product.get_cover_namespace(context) namespace['images'] = [namespace['cover']] if show_cover else [] namespace['images'] += product.get_images_namespace(context) namespace['has_more_than_one_image'] = len(namespace['images']) > 1 namespace['inject_fancybox'] = is_navigation_mode(context) # Configuration namespace['img_width'] = resource.get_property('big_img_width') namespace['img_height'] = resource.get_property('big_img_height') namespace['thumb_width'] = resource.get_property('thumb_img_width') namespace['thumb_height'] = resource.get_property('thumb_img_height') namespace['show_loupe'] = 'true' if show_loupe else 'false' namespace['change_on_click'] = 'false' if change_img_on_hover else 'true' namespace['activate_lightbox'] = 'true' if activate_lightbox else 'false' return namespace
def get_namespace(self, resource, context): tags_folder = self._get_tags_folder(resource, context) # description (help text) bo_description = False ac = tags_folder.get_access_control() if ac.is_allowed_to_edit(context.user, tags_folder): if is_navigation_mode(context) is False and \ self.show_description and \ type(context.resource) is type(tags_folder): bo_description = True tag_brains = tags_folder.get_tag_brains(context) tag_base_link = '%s/%%s' % context.get_link(tags_folder) if self.formats: query = {'format': self.formats} tag_base_link = '%s?%s' % (tag_base_link, encode_query(query)) # query root = context.root tags_query = tags_folder.get_tags_query_terms(state='public', formats=self.formats) tags_results = root.search(AndQuery(*tags_query)) items_nb = [] tags = [] for brain in tag_brains: if self.tags_to_show and len(items_nb) == self.tags_to_show: break sub_results = tags_results.search(PhraseQuery('tags', brain.name)) nb_items = len(sub_results) if nb_items: d = {} title = brain.title or brain.name if self.show_number: title = u'%s (%s)' % (title, nb_items) d['title'] = title d['xml_title'] = title.replace(u' ', u'\u00A0') d['link'] = tag_base_link % brain.name d['css'] = None items_nb.append(nb_items) d['nb_items'] = nb_items tags.append(d) if not tags: return {'tags': [], 'bo_description': bo_description} max_items_nb = max(items_nb) if items_nb else 0 min_items_nb = min(items_nb) if items_nb else 0 css_index_max = self.css_index_max delta = (max_items_nb - min_items_nb) or 1 percentage_per_item = float(css_index_max - 1) / delta # Special case of there is only one item default_css = 'tag-1' for tag in tags: if min_items_nb == max_items_nb: tag['css'] = default_css else: nb_items = tag['nb_items'] css_index = int(ceil(nb_items) * percentage_per_item) or 1 # FIXME sometimes css_index = 0, this should never append # set css_index to 1 css_index = abs(css_index_max - css_index + 1) or 1 tag['css'] = 'tag-%s' % css_index # Random if self.random_tags: shuffle(tags) return {'tags': tags, 'bo_description': bo_description}