| Issue 59: | Markup generated using the tree_info template tag has more closing levels than opening ones (has patch) | |
| 3 people starred this issue and may be notified of changes. | Back to list |
Markup generated using the tree_info template tag has more closing levels than opening ones (has patch)
Jun 14, 2010
Your patches do not work with trunk guys. I see no difference, still more closing levels than opening ones.
Jun 14, 2010
Have a look at django-mptt on github. There are several forks of it, but we all merge from each other. http://github.com/matthiask/django-mptt django-mptt on google code is probably dead/unmaintained.
Jun 15, 2010
No luck, I am using:
{% for concept,structure in concepts|tree_info %}
{% if structure.new_level %}<ul><li>{% else %}</li><li>{% endif %}
{{ concept.name }}
{% for level in structure.closed_levels %}</li></ul>{% endfor %}
{% endfor %}
Jun 15, 2010
This is the commit which fixed it for me (exactly the same template code): http://github.com/matthiask/django-mptt/commit/bc66234063193a9ebf059eb6103cd2a2a7b10e59
Jun 15, 2010
I am running your latest.
Jun 15, 2010
Hmm, very strange. Are you sure there's no other mptt version lying around somewhere, f.e. installed with easy_install? Did you remove all .pyc files and try again? Maybe recompilation failed somewhere (happens from time to time). I can only say that we are using the tree_info tag all the time, and it does not show the behavior you see for some reason.
Jun 15, 2010
I've tried that, no dice. What are the other ways to template-out a nested unordered list or nested JSON? My trees can have many root nodes.
JSON example:
var json = {
"id": "347_0",
"name": "Nine Inch Nails",
"children": [{
"id": "126510_1",
"name": "Jerome Dillon",
"data": {
"band": "Nine Inch Nails",
"relation": "member of band"
},
"children": [{
"id": "52163_2",
"name": "Howlin' Maggie",
"data": {
"band": "Jerome Dillon",
"relation": "member of band"
},
"children": []
}, {
"id": "324134_3",
"name": "nearLY",
"data": {
"band": "Jerome Dillon",
"relation": "member of band"
},
"children": []
}]
}, {
"id": "173871_4",
"name": "Charlie Clouser",
"data": {
"band": "Nine Inch Nails",
"relation": "member of band"
},
"children": []
}],
"data": []
};
My mind code:
var json = {
"id": "{{ vocabulary.id }}",
"name": "{{ vocabulary.title }}",
"children": [
{% for concept,structure in vocabulary_concepts|tree_info %}
{
"id": "{{concept.id}}",
"name": "{{ concept.name }}",
"children": [.... recursively write concepts here.....],
"data": []
}{%if not forloop.last %}, {% endif %}
{% endfor %}
],
"data": []
};
Vocabulary is used as a root level. Concepts variable contains only concepts in the given vocabulary.
My models:
class Vocabulary(models.Model):
title = models.CharField(max_length=75)
description = models.TextField(max_length=200)
def __unicode__(self):
return self.title
class Concept(models.Model):
id = models.CharField(primary_key=True, max_length=80)
vocabulary = models.ForeignKey(Vocabulary)
name = models.CharField(max_length=150)
parent = models.ForeignKey('self', blank=True, null=True, related_name='children')
related = models.ManyToManyField('self', blank=True, null=True)
def __unicode__(self):
return self.name
What if my MPTT specific data is somehow corrupt. Is there a way to purge it and recalculate based on a parent.
Jun 15, 2010
I don't think there are any other sane ways except for tree_info if you want to use templating. On the other hand, if you do dict-mangling by hand... still, it's not too nice. Concerning the mptt rebuilding: https://code.google.com/p/django-mptt/issues/detail?id=13 http://github.com/matthiask/feincms/blob/master/feincms/management/commands/rebuild_mptt.py
Sep 3, 2010
I can't reproduce this bug with the latest source checkout. Looks like Matthias' patch fixed it in http://github.com/django-mptt/django-mptt/commit/bc66234063193a9ebf059eb6103cd2a2a7b10e59 fmalina, did you get anywhere in the end?
Status:
Chatting
Sep 5, 2010
If this ticket is still relevant, please try out the new recursive templatetags I've added in this branch: http://github.com/django-mptt/django-mptt/tree/templatetags-cleanup I'd like some feedback before merging them to master. I think they're a lot nicer to use than tree_info. However they will likely use more memory (recursive is nasty that way). Probably not suited to extra deep trees. Feedback welcome here, or preferably on the django-mptt-dev google group :)
Sep 6, 2010
As mentioned on django-mptt-dev, the recursive tags look much nicer than the tags here. Still, we use tree_info in many places in many variations and would not like to see it removed. The fix is tested on several pages around the 'net and I'm therefore quite confident it is correct.
Sep 6, 2010
Thanks for the feedback. I wasn't suggesting we should remove tree_info. Backward compatibility is important, and I'm aware tree_info is in wide use. Also, it no doubt has better memory performance than recursive tags, so those with low memory limits or unusually deep trees should keep using it. The recursive tags will be additional, but will probably become the 'main' documented way to do things. The goal is to make it easier to get up and running with django-mptt. Closing this ticket because as you said, this bug is fixed. More comments re the template tags are welcome on the mailing list :)
Status:
Fixed
|
1.1 KB View Download