We're Hiring!

OMERO.web NoReverseMatch

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

OMERO.web NoReverseMatch

Postby bhcho » Fri Apr 22, 2011 1:59 pm

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
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: OMERO.web NoReverseMatch

Postby cxallan » Tue Apr 26, 2011 8:45 am

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.
cxallan
Site Admin
 
Posts: 509
Joined: Fri May 01, 2009 8:07 am

Re: OMERO.web NoReverseMatch

Postby bhcho » Tue Apr 26, 2011 2:15 pm

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
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: OMERO.web NoReverseMatch

Postby cxallan » Tue Apr 26, 2011 2:36 pm

Great. No problem at all.
cxallan
Site Admin
 
Posts: 509
Joined: Fri May 01, 2009 8:07 am


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest