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

Allow non-existent menus in templates #34

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
If you have installed treemenus, created a template that renders a menu but 
that menu is not in the system, the templates throw a "Menu matching query 
does not exist" error, which in some use cases (e.g. in mine), this is not 
desirable and instead if the exception was ignored it would be a preferred 
result.

I have included a diff to make the show_menu templatetag catch the 
exception and pass off the context if the menu doesn't exist.

The main advantage of this is you could include menus in a template that 
doesn't exist yet, but allowing for them to be added in once they are created 
in the admin.

Original issue reported on code.google.com by woodman....@gmail.com on 1 Dec 2009 at 5:16

Attachments:

GoogleCodeExporter commented 9 years ago
Thank you for the report. I understand your use case, however at this stage I 
prefer
to let it raise an exception if the menu does not exist. You can always write 
your
own custom template tag to allow this behaviour.

If you, or someone else, has a compelling reason for letting it fail silently, 
then
please re-open this ticket and I'll re-consider it.

An alternative could also be to add an extra argument to the template tag:

def show_menu(context, menu_name, menu_type=None, fail_silently=False):
    try:
        context['menu'] = menu
        if menu_type:
            context['menu_type'] = menu_type
        return context
    except Menu.DoesNotExist:
        if fail_silently:
            return context
        else:
            raise

Original comment by jpha...@gmail.com on 6 Dec 2009 at 5:59

GoogleCodeExporter commented 9 years ago
Sounds good, I respect your opinion. Love the tool, it's great work!

Cheers

Original comment by woodman....@gmail.com on 7 Dec 2009 at 8:17