def test_format_label(self): tree = get_tree_from_queryset(get_tree_queryset(Country), item_label_field_name='code') root = tree[0] continents = root['children'] african_countries = continents[0]['children'] self.assertEqual(african_countries[0]['name'], 'DZ')
def test_format_label(self): tree = get_tree_from_queryset(get_tree_queryset(Country), item_label_field_name="code") root = tree[0] continents = root["children"] african_countries = continents[0]["children"] self.assertEqual(african_countries[0]["name"], "DZ")
def test_get_tree_from_queryset(self): tree = get_tree_from_queryset(get_tree_queryset(Country)) root = tree[0] self.assertEqual(root['name'], 'root') continents = root['children'] self.assertEqual(len(continents), 7) self.assertEqual(continents[0]['name'], 'Africa') african_countries = continents[0]['children'] self.assertEqual(african_countries[0]['name'], 'Algeria') # format label tree = get_tree_from_queryset(get_tree_queryset(Country), item_label_field_name='code') root = tree[0] continents = root['children'] african_countries = continents[0]['children'] self.assertEqual(african_countries[0]['name'], 'DZ')
def test_default(self): tree = get_tree_from_queryset(get_tree_queryset(Country)) root = tree[0] self.assertEqual(root['name'], 'root') continents = root['children'] self.assertEqual(len(continents), 7) self.assertEqual(continents[0]['name'], 'Africa') african_countries = continents[0]['children'] self.assertEqual(african_countries[0]['name'], 'Algeria')
def get_tree_data(self, qs, max_level): pk_attname = self.model._meta.pk.attname def handle_create_node(instance, node_info): pk = quote(getattr(instance, pk_attname)) node_info.update( # url=self.get_admin_url('change', (quote(pk),)), url=reverse('xadmin:duck_personnel_personnel_change', args=(quote(pk),)), move_url=self.get_admin_url('move', (quote(pk),)) ) return util.get_tree_from_queryset(qs, handle_create_node, max_level)
def test_default(self): tree = get_tree_from_queryset(get_tree_queryset(Country)) root = tree[0] self.assertEqual(root["name"], "root") continents = root["children"] self.assertEqual(len(continents), 7) self.assertEqual(continents[0]["name"], "Africa") african_countries = continents[0]["children"] self.assertEqual(african_countries[0]["name"], "Algeria")
def get_tree_data(self, qs, max_level): pk_attname = self.model._meta.pk.attname def handle_create_node(instance, node_info): pk = quote(getattr(instance, pk_attname)) if Item.objects.filter(place_id=pk).count(): node_info.update( view_url=reverse("admin:base_place_item_changelist", args=[pk]), transfer_url=reverse("admin:base_item_movement_filtered_changelist", args=[pk]), ) node_info.update( url=self.get_admin_url('change', (quote(pk),)), move_url=self.get_admin_url('move', (quote(pk),)) ) return util.get_tree_from_queryset(qs, handle_create_node, max_level)
def get_tree_data(self, qs, max_level): pk_attname = self.model._meta.pk.attname def handle_create_node(instance, node_info): pk = quote(getattr(instance, pk_attname)) node_info.update( url=self.get_admin_url('change', (quote(pk),)), move_url=self.get_admin_url('move', (quote(pk),)), label='<span class="ex-category %(clazz)s %(visible)s">%(label)s <span class="ex-label">%(clazz_display)s</span> <i class="fa fa-eye"></i> <span class="path">%(path)s</span></span>' % { 'label': node_info['label'], 'clazz': instance._meta.object_name.lower(), 'clazz_display': instance._meta.verbose_name, 'visible': 'on' if instance.visible else 'off', 'path': instance.path, } ) return get_tree_from_queryset(qs, handle_create_node, max_level)
def get_tree_data(self, qs, max_level): pk_attname = self.model._meta.pk.attname def handle_create_node(instance, node_info): pk = quote(getattr(instance, pk_attname)) if Item.objects.filter(category_id=pk).count(): node_info.update( view_url=reverse("admin:base_category_item_changelist", args=[pk]), transfer_url=reverse("admin:base_item_movement_filtered_changelist", args=[0, pk]), ) node_info.update( url=self.get_admin_url('change', (quote(pk),)), storage_url=reverse( 'admin:base_place_item_changelist', args=(settings.APP_FILTERS["PLACE_STORAGE_ID"],) ) + "?category__id__in=%s" % pk, move_url=self.get_admin_url('move', (quote(pk),)) ) return util.get_tree_from_queryset(qs, handle_create_node, max_level)
def get_tree_data(self, qs, max_level): pk_attname = self.model._meta.pk.attname def handle_create_node(instance, node_info): pk = quote(getattr(instance, pk_attname)) node_info.update( url=self.get_admin_url('change', (quote(pk),)), move_url=self.get_admin_url('move', (quote(pk),)), label='<span class="ex-rubric %(method)s %(active)s%(is_characteristic)s%(is_mark)s%(is_relation)s%(has_system_flags)s">%(label)s <i class="fa fa-exclamation-triangle ex-has-system-flags"></i> <i class="fa fa-list ex-characteristic"></i> <i class="fa fa-tags ex-mark"></i> <i class="fa fa-link ex-relation"></i><span class="ex-label">%(method_display)s</span> <i class="fa fa-power-off"></i> %(tags)s<span class="path">%(path)s</span></span>' % { 'label': node_info['label'], 'method': instance.get_classification_method(), 'method_display': instance.get_classification_method_display(), 'active': 'on' if instance.active else 'off', 'is_characteristic': ' is-characteristic' if instance.attribute_mode == Rubric.ATTRIBUTE_IS_CHARACTERISTIC else '', 'is_mark': ' is-mark' if instance.attribute_mode == Rubric.ATTRIBUTE_IS_MARK else '', 'is_relation': ' is-relation' if instance.attribute_mode == Rubric.ATTRIBUTE_IS_RELATION else '', 'has_system_flags': ' has-system-flags' if instance.system_flags else '', 'path': instance.path, 'tags': ''.join(['<span class="ex-label tag">%s</span>' % tag for tag in instance.tags.split()]) if instance.tags else '' } ) return get_tree_from_queryset(qs, handle_create_node, max_level)
def get_tree_data(self, qs, max_level, filters_params=None): """ Создает дерево витрины данных """ def handle_create_node(instance, node_info): """ Вспомогательная функция создания дерева витрины данных. Возвращает обновленную html-страницу дерева """ if six.PY3: node_info['label'] = node_info['name'] mptt_admin_node_info_update_with_template( admin_instance=self, template=get_mptt_admin_node_template(instance), instance=instance, node_info=node_info) args = [qs, handle_create_node, max_level] if six.PY3: args.append('name') return get_tree_from_queryset(*args)