google-code-export / django-treemenus

Automatically exported from code.google.com/p/django-treemenus
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

default setup dies on move_down action in admin #10

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. run django-admin.py startproject testproj
2. add treemenus (svn) to installed apps, setup admin.autodiscover() in urls
3. syncdb, log in to admin, add menu, add two menuitems
4. all you can do is move menu items down, traceback is attached

What is the expected output? What do you see instead?
 * move an item down. reverse urls don't work either, they're empty.
 * does this work with autodiscover?

What version of the product are you using? On what operating system?
 * django-treemenus svn
 * django svn
 * Mac OS 10.5.4

Please provide any additional information below.

 Environment:

Request Method: GET
Request URL: http://localhost:8000/admin/treemenus/menu/1/items/2/move_down/
Django Version: 1.0-beta_1-SVN-8432
Python Version: 2.5.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'treemenus']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware')

Traceback:
File "/Library/Python/2.5/site-packages/django/core/handlers/base.py" in 
get_response
  86.                 response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.5/site-packages/django/contrib/admin/sites.py" in root
  172.                 return self.model_page(request, *url.split('/', 2))
File "/Library/Python/2.5/site-packages/django/views/decorators/cache.py" in 
_wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File "/Library/Python/2.5/site-packages/django/contrib/admin/sites.py" in 
model_page
  189.         return admin_obj(request, rest_of_url)
File "/Users/copelco/projects/myproj/treemenus/admin.py" in __call__
  124.                 return self.move_down_item(request, match.group('menu_pk'), match.group('menu_item_pk'))
File "/Users/copelco/projects/myproj/treemenus/admin.py" in move_down_item
  166.             move_item(menu_item, 1)
File "/Users/copelco/projects/myproj/treemenus/admin.py" in move_item
  26.     swapping_sibling = MenuItem.objects.get(parent=menu_item.parent, rank=old_rank+vector)
File "/Library/Python/2.5/site-packages/django/db/models/manager.py" in get
  81.         return self.get_query_set().get(*args, **kwargs)
File "/Library/Python/2.5/site-packages/django/db/models/query.py" in get
  300.                     % self.model._meta.object_name)

Exception Type: DoesNotExist at /admin/treemenus/menu/1/items/2/move_down/
Exception Value: MenuItem matching query does not exist.

Original issue reported on code.google.com by cope...@gmail.com on 18 Aug 2008 at 2:09

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the report. The doc currently assumes you use autodiscover. I'll 
work on a
patch for the doc and/or the code to fix this.

Original comment by jpha...@gmail.com on 24 Aug 2008 at 11:26

GoogleCodeExporter commented 9 years ago
Hi,

I think I found out what's wrong here - new menu items always get rank=0, which
messes things up afterwards, such as move_down/move_up operations (move_up 
button did
not appear for me at all, since you cannot move up with rank 0).

I attached a modified models.py with a fix for this, as well as a suggested 
model
method for menu items, called 'final_url' (temporary name), which returns the 
item's
url if exists, and if not - tries to get the url from item's named_url (if both 
don't
exist, return None).

Hope you find this helpful,

Ophir

Original comment by firt...@gmail.com on 26 Aug 2008 at 12:20

Attachments:

GoogleCodeExporter commented 9 years ago
i made a diff for this which also add's *args, **kwargs to the save() methods.
but i'm afraid it's not more usefull then the models.py by firtzel as everyline 
is
replaced because of the svn using non-unix style line endings :(

Original comment by v.oostv...@gmail.com on 8 Sep 2008 at 2:28

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks guys for your help on this. It is now fixed in trunk.
Firtzel, yours patch for the fix works great. Although it's a good idea I 
haven't
added the 'final_url' method. That's because I'm planning to make this app 
generic to
handle any kind of tree structure. In a later version (hopefully coming soon), 
it'll
be easier to add such extra methods.
Bas, thanks also for the suggestion on the save() method parameters. I've 
explicitly
put force_insert and force_update to keep things consistent with Django.

Cheers!

Original comment by jpha...@gmail.com on 9 Sep 2008 at 1:35