google-code-export / django-mptt

Automatically exported from code.google.com/p/django-mptt
Other
0 stars 0 forks source link

Markup generated using the tree_info template tag has more closing levels than opening ones (has patch) #59

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Markup generated using the tree_info template tag has more closing levels
than opening ones (has patch)

Original issue reported on code.google.com by matthias...@gmail.com on 26 Aug 2009 at 7:05

Attachments:

GoogleCodeExporter commented 9 years ago
I've stumbled other this too then building a tree for some 
node.get_descendants() -
not right from the root node. Here is mine patchy for this.

Original comment by aenor.realm on 23 Sep 2009 at 12:07

Attachments:

GoogleCodeExporter commented 9 years ago
Your patches do not work with trunk guys. I see no difference, still more 
closing levels than opening ones.

Original comment by fmalina on 14 Jun 2010 at 5:04

GoogleCodeExporter commented 9 years ago
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.

Original comment by matthias...@gmail.com on 14 Jun 2010 at 7:22

GoogleCodeExporter commented 9 years ago
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 %}

Original comment by fmalina on 15 Jun 2010 at 8:49

GoogleCodeExporter commented 9 years ago
This is the commit which fixed it for me (exactly the same template code):
http://github.com/matthiask/django-mptt/commit/bc66234063193a9ebf059eb6103cd2a2a
7b10e59

Original comment by matthias...@gmail.com on 15 Jun 2010 at 8:57

GoogleCodeExporter commented 9 years ago
I am running your latest.

Original comment by fmalina on 15 Jun 2010 at 10:25

GoogleCodeExporter commented 9 years ago
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.

Original comment by matthias...@gmail.com on 15 Jun 2010 at 10:31

GoogleCodeExporter commented 9 years ago
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.

Original comment by fmalina on 15 Jun 2010 at 3:15

GoogleCodeExporter commented 9 years ago
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:
http://code.google.com/p/django-mptt/issues/detail?id=13
http://github.com/matthiask/feincms/blob/master/feincms/management/commands/rebu
ild_mptt.py

Original comment by matthias...@gmail.com on 15 Jun 2010 at 3:21

GoogleCodeExporter commented 9 years ago
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/bc66234063193a9ebf059eb6103cd2a
2a7b10e59

fmalina, did you get anywhere in the end?

Original comment by craig.ds@gmail.com on 4 Sep 2010 at 2:08

GoogleCodeExporter commented 9 years ago
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 :)

Original comment by craig.ds@gmail.com on 5 Sep 2010 at 12:57

GoogleCodeExporter commented 9 years ago
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.

Original comment by matthias...@gmail.com on 6 Sep 2010 at 7:01

GoogleCodeExporter commented 9 years ago
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 :)

Original comment by craig.ds@gmail.com on 6 Sep 2010 at 10:23