Page 1 of 1

OMERO.web NoReverseMatch

PostPosted: Fri Apr 22, 2011 1:59 pm
by bhcho
Hello,

I'm trying to modify OMERO.web UI a little for our purpose.
I tried to add another link at the bottom (footer) of "base_main.html" like
Code: Select all
<a href="{% url myapp %}" title="myapp ">{% trans "myapp" %}</a>

And I modified urls.py
Code: Select all
url( r'^myapp/$', views.myapp, name="myapp" ), 

and also views.py
Code: Select all
@isUserConnected   
def myapp( request, **kwargs):
    # get connection
    conn = None
    try:
        conn = kwargs["conn"]       
    except:
        logger.error(traceback.format_exc())
        return handlerInternalError("Connection is not available. Please contact your administrator.")

    session = conn.c.sf;
    class PARAM:
        eContext = {'breadcrumb': list()}
        containers = {'Positive_Dataset':list(), 'Negative_Dataset':list(), 'Test_Dataset':list()}

    param = PARAM
    param.containers['Positive_Dataset'] = [long(452)]
    param.containers['Negative_Dataset'] = [long(451)]
    param.containers['Test_Dataset'] = [long(455)]
    param.eContext['breadcrumb'] = ['myapp']

   
    menu = request.REQUEST.get("menu")
    if menu is not None:
        request.session['nav']['menu'] = menu
    else:
        menu = request.session['nav']['menu']
    try:
        url = reverse(viewname="load_template", args=[menu])
    except:
        url = reverse("webindex")
    context = {'nav':request.session['nav'], 'url':url, 'eContext':param.eContext, 'param':param}
    template = 'webclient/myapp/myapp.html'

    t = template_loader.get_template(template)
    c = Context(request,context)
    return HttpResponse(t.render(c))


And it basically works when I click the link.
But sometimes (like when I was in the "basket" page before) it gives me an error like

Traceback (most recent call last):

File "/.../base.py", line 92, in get_response
response = callback(request, *callback_args, **callback_kwargs)

File "/.../views.py", line 155, in wrapped
return f(request, *args, **kwargs)

File "/.../views.py", line 2840, in myapp
return HttpResponse(t.render(c))

NoReverseMatch: Reverse for 'load_template' with arguments '('basket',)' and keyword arguments '{}' not found.


Do you have any idea on this?

BK

Re: OMERO.web NoReverseMatch

PostPosted: Tue Apr 26, 2011 8:45 am
by cxallan
You're loading the navigation details, from the Django session into the reverse here:

Code: Select all
...
    menu = request.REQUEST.get("menu")
    if menu is not None:
        request.session['nav']['menu'] = menu
    else:
        menu = request.session['nav']['menu']
    try:
        url = reverse(viewname="load_template", args=[menu])
    except:
        url = reverse("webindex")
...


The context here is tricky, and I'd have to see a complete diff of all you're changes to be 100% certain but when you're on the basket page request.session['nav']['menu'] is set to basket. The infrastructure expects that target URLs are entered via the navigation buttons in the menu, not via links in the UI. So, you're going to have to remove adjust that logic you have in your view implementation to ensure the menu values are set correctly.

Re: OMERO.web NoReverseMatch

PostPosted: Tue Apr 26, 2011 2:15 pm
by bhcho
Thanks,

I see.

I changed my base_main.html
Code: Select all
<a href="{% url load_template "myapp" %}" title="myapp">{% trans "myapp" %}</a>


and also modified the urls.py for the load_template function
Code: Select all
url( r'^(?P<menu>((?i)userdata|public|history|search|importer|help|usertags|myapp))/$', views.load_template, name="load_template" ),


And it seems working now.

thanks again,
BK

Re: OMERO.web NoReverseMatch

PostPosted: Tue Apr 26, 2011 2:36 pm
by cxallan
Great. No problem at all.