Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

django-mptt tree sortable #146

Closed
mishbahr opened this issue Sep 10, 2013 · 17 comments
Closed

django-mptt tree sortable #146

mishbahr opened this issue Sep 10, 2013 · 17 comments

Comments

@mishbahr
Copy link

I tried to follow the doc example for django-mptt tree sortable

model.py

    class FooterLink(MPTTModel):
        link_text = models.CharField(max_length=120, blank=True,
                        help_text=_('With this field you can overwrite the title'
                                    ' that is displayed in the footer menu.'))
        page_link = PageField(null=True, blank=True,
                         related_name='footer_links')
        parent = TreeForeignKey('self', null=True,
                                blank=True, related_name='children',
                                verbose_name=_('Parent Link'))
        order = models.PositiveIntegerField()

        class MPTTMeta:
            order_insertion_by = ['order']

        def save(self, *args, **kwargs):
            super(FooterLink, self).save(*args, **kwargs)
            FooterLink.objects.rebuild()

        def __unicode__(self):
            if self.link_text:
                return self.link_text
            if page_link:
                page_link.get_page_title()
            return u'%s %s' % (self._meta.verbose_name.title(), self.pk)

admin.py

    from django.contrib import admin

    from suit.admin import SortableModelAdmin
    from mptt.admin import MPTTModelAdmin

    from .models import FooterLink

    class FooterLinkAdmin(MPTTModelAdmin, SortableModelAdmin):
        mptt_level_indent = 20
        list_display = ('link_text', 'page_link')
        sortable = 'order'

    admin.site.register(FooterLink, FooterLinkAdmin)

But its not being displayed correctly in django admin

screen shot 2013-09-10 at 14 32 04

Please Help

[django-suit==0.2.4]

@darklow
Copy link
Owner

darklow commented Sep 10, 2013

Please post which version of Django and django-mptt

@mishbahr
Copy link
Author

Django==1.5.2
django-mptt==0.6.0

Thanks for such a quick response

@darklow
Copy link
Owner

darklow commented Sep 10, 2013

Check browser debug console, and see if you haven't any javascript errors or static files missing.

@mishbahr
Copy link
Author

I'm running it locally with debug=True

Just used Firefox.

[14:54:13.985] ReferenceError: reference to undefined property v.event.triggered @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:13.985] ReferenceError: reference to undefined property e.returnValue @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:13.986] ReferenceError: reference to undefined property n.result @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.790] TypeError: function An does not always return a value @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.790] TypeError: function Fn does not always return a value @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.790] TypeError: function In does not always return a value @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.791] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.791] TypeError: function o does not always return a value @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.791] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.791] SyntaxError: test for equality (==) mistyped as assignment (=)? @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.792] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.792] SyntaxError: test for equality (==) mistyped as assignment (=)? @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.792] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.792] SyntaxError: test for equality (==) mistyped as assignment (=)? @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.792] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.793] SyntaxError: test for equality (==) mistyped as assignment (=)? @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.793] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.793] SyntaxError: test for equality (==) mistyped as assignment (=)? @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.793] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.793] SyntaxError: test for equality (==) mistyped as assignment (=)? @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.793] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.794] SyntaxError: test for equality (==) mistyped as assignment (=)? @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.794] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.801] ReferenceError: reference to undefined property v.valHooks[this] @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.805] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:376
[14:54:15.805] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:416
[14:54:15.805] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:406
[14:54:15.805] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:496
[14:54:15.805] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:1013
[14:54:15.805] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:1039
[14:54:15.805] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:1127
[14:54:15.805] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:1137
[14:54:15.806] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:1797
[14:54:15.806] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:2036
[14:54:15.806] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:2076
[14:54:15.806] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:2201
[14:54:15.806] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:2209
[14:54:15.806] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:2199
[14:54:15.806] TypeError: function testChange does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:2277
[14:54:15.806] TypeError: function testChange does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:2256
[14:54:15.806] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:2285
[14:54:15.806] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:2295
[14:54:15.806] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:2430
[14:54:15.806] TypeError: function liveHandler does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:2587
[14:54:15.806] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:3003
[14:54:15.806] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:3009
[14:54:15.807] TypeError: variable i redeclares argument @ http://127.0.0.1:8000/static/admin/js/jquery.js:3203
[14:54:15.807] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:3193
[14:54:15.807] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:3214
[14:54:15.807] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:3304
[14:54:15.807] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:3453
[14:54:15.807] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:3564
[14:54:15.807] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:3750
[14:54:15.807] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:4088
[14:54:15.807] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:4100
[14:54:15.807] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:4261
[14:54:15.808] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:4565
[14:54:15.808] SyntaxError: in strict mode code, functions may be declared only at top level or immediately within another function @ http://127.0.0.1:8000/static/admin/js/jquery.js:4628
[14:54:15.808] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:4956
[14:54:15.808] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:5105
[14:54:15.808] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:5155
[14:54:15.808] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:5298
[14:54:15.808] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/jquery.js:5378
[14:54:15.814] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/actions.js:107
[14:54:15.814] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/admin/js/actions.js:112
[14:54:15.815] SyntaxError: in strict mode code, functions may be declared only at top level or immediately within another function @ http://127.0.0.1:8000/static/suit/js/sortables.js:16
[14:54:15.815] SyntaxError: in strict mode code, functions may be declared only at top level or immediately within another function @ http://127.0.0.1:8000/static/suit/js/sortables.js:20
[14:54:15.817] TypeError: anonymous function does not always return a value @ http://127.0.0.1:8000/static/suit/bootstrap/js/bootstrap.min.js:7
[14:54:15.819] ReferenceError: reference to undefined property g.delegateType @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.820] ReferenceError: assignment to undeclared variable SuitAfterInline @ http://127.0.0.1:8000/static/suit/js/suit.js:23
[14:54:15.873] ReferenceError: reference to undefined property v.event.triggered @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:15.875] ReferenceError: reference to undefined property ret[i] @ http://127.0.0.1:8000/static/admin/js/jquery.js:4492
[14:54:15.876] ReferenceError: assignment to undeclared variable lastChecked @ http://127.0.0.1:8000/static/admin/js/actions.js:82
--
[14:54:30.248] ReferenceError: reference to undefined property v.event.triggered @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:30.248] ReferenceError: reference to undefined property e.returnValue @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2
[14:54:30.248] ReferenceError: reference to undefined property s.disabled @ http://127.0.0.1:8000/static/suit/js/jquery-1.8.3.min.js:2

@darklow
Copy link
Owner

darklow commented Sep 10, 2013

To investigate further i will resulting html source for whole page, i tested using same versions and same classes and it worked for me.

@mishbahr
Copy link
Author

Do you want me to copy the sourcecode of the page, here?

@darklow
Copy link
Owner

darklow commented Sep 10, 2013

Use some http://dpaste.com/ site and post the link with the resulting html source.
If you don't wont to share the link in public, you can send me an email with the link.

@mishbahr
Copy link
Author

@mishbahr mishbahr reopened this Sep 10, 2013
@darklow
Copy link
Owner

darklow commented Sep 10, 2013

Just noticed you changed previous answer adding these JS errors.
Can you figure out where do they come from?
Do you see same errors on Chrome?

@mishbahr
Copy link
Author

No errors on Chrome.

Just Firefox.

@ecstaticpeon
Copy link

Having the same issue using the example from the doc (I'm using the same version as Mishbah). It looks like the HTML classes defined on the order widget by SortableModelAdmin are getting lost when the form class used is changed. So if you take the following examples:

# This works fine.
class CategoryAdmin(SortableModelAdmin):
    mptt_level_indent = 20
    list_display = ('name', )
# This works fine too.
from django import forms

class CategoryAdmin(SortableModelAdmin):
    mptt_level_indent = 20
    list_display = ('name', )
    form = forms.ModelForm
# This does not.
from django import forms

class CustomForm(forms.ModelForm):
    pass

class CategoryAdmin(SortableModelAdmin):
    mptt_level_indent = 20
    list_display = ('name', )
    form = CustomForm

Since MPTTModelAdmin modifies the form attribute, it breaks SortableModelAdmin. The resulting HTML for the input is:

<input class="vIntegerField" id="id_form-0-order" name="form-0-order"
        value="1" type="text">

Just for the sake of testing, I tried redefining the widget as such:

from django import forms

class CustomForm(forms.ModelForm):

    class Meta:
        widgets = {
            'order': forms.TextInput(
                attrs={'class': 'hide input-mini suit-sortable'})
        }

class CategoryAdmin(SortableModelAdmin):
    mptt_level_indent = 20
    list_display = ('name', )
    form = CustomForm

To not available.
I tried to figure out where the widget gets overriden, but haven't found out yet.

@darklow
Copy link
Owner

darklow commented Sep 10, 2013

There is a possiblity this issue is related to recent changes in chis commit: 12e517f
Could somebody check previous version v0.2.3 (pip install django-suit==0.2.3) and see if errors occurs too?

@ecstaticpeon
Copy link

Tried 0.2.3, and that fixes the issue. I also tried again with 0.2.4, but reverting the changes you mentioned in 12e517f, and that works too.

@darklow
Copy link
Owner

darklow commented Sep 11, 2013

Ok, it means we found the problem. Thanks.
@mishbahr, @ecstaticpeon please use v0.2.3 version until i'll deal with this issue.
I think i need to write some more tests for the mptt support feature, since mptt app also changes quite often.

@ecstaticpeon
Copy link

Good. Thanks for you help.

@mishbahr
Copy link
Author

Thanks for all your help guys! Really appreciated.

darklow added a commit that referenced this issue Sep 23, 2013
when using sortable in combination with latest django-mptt.
Refactored that now form Meta widgets are applied in
get_change_list_form() method, which means any form will get
required Meta class widgets.
@darklow
Copy link
Owner

darklow commented Sep 23, 2013

Could you please check latest develop branch and confirm that issue is fixed? Thank you.

pip uninstall django-suit
pip install https://github.com/darklow/django-suit/tarball/develop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants