Skip to content

Commit

Permalink
Support ?path=image-123 across groups. See #8299
Browse files Browse the repository at this point in the history
This will load the parent Project & Dataset so that the tree hierarchy can be expanded.
Will also switch the webclient to the correct group for the data.
We don't need this logic in handling cross-group script results now.
  • Loading branch information
Will Moore committed Jul 24, 2012
1 parent 126cb6f commit 80b880a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 88 deletions.
1 change: 0 additions & 1 deletion components/tools/OmeroWeb/omeroweb/webclient/decorators.py
Expand Up @@ -35,7 +35,6 @@
from omeroweb.webgateway import views as webgateway_views
from omeroweb.webadmin.custom_models import Server
from omeroweb.webclient.webclient_http import HttpLoginRedirect
from omeroweb.webclient.webclient_utils import string_to_dict

logger = logging.getLogger('omeroweb.webclient.decorators')

Expand Down
Expand Up @@ -207,7 +207,7 @@
<!-- Browser to file in tree -->
{% if v.browse_url %}
<li class="btn_folder">
<a href='{% url change_active_group %}?active_group={{ v.group_id }}&url={{ v.browse_url }}' class='browse' title="Navigate to {{ v.type }} in the main window">
<a href='{{ v.browse_url }}' class='browse' title="Navigate to {{ v.type }} in the main window">
Go to {% ifequal v.type "FileAnnotation" %} Attachment {% else %} {{ v.type }} {% endifequal %}
</a>
</li>
Expand Down
111 changes: 44 additions & 67 deletions components/tools/OmeroWeb/omeroweb/webclient/views.py
Expand Up @@ -68,7 +68,6 @@
from django.core.servers.basehttp import FileWrapper

from webclient.webclient_gateway import OmeroWebGateway
from omeroweb.webclient.webclient_utils import string_to_dict

from webclient_http import HttpJavascriptRedirect, HttpJavascriptResponse, HttpLoginRedirect

Expand Down Expand Up @@ -256,21 +255,27 @@ def index_tag_cloud(request, conn=None, **kwargs):
@login_required()
def change_active_group(request, conn=None, url=None, **kwargs):
"""
Changes the active group of the OMERO connection, using conn.changeActiveGroup() with 'active_group' from request.REQUEST.
First we log out and log in again, to force closing of any processes?
TODO: This requires usage of request.session.get('password'), which should be avoided.
Simply changes the request.session['active_group'] which is then used by the
@login_required decorator to configure conn for any group-based queries.
Finally this redirects to the 'url'.
"""
#TODO: we need to handle exception while changing active group faild, see #

active_group = request.REQUEST.get('active_group')
request.session.modified = True
request.session['active_group'] = active_group
request.session['imageInBasket'] = set() # empty basket
request.session['basket_counter'] = 0
switch_active_group(request)
url = url or reverse("webindex")
return HttpResponseRedirect(url)

def switch_active_group(request, active_group=None):
"""
Simply changes the request.session['active_group'] which is then used by the
@login_required decorator to configure conn for any group-based queries.
"""
if active_group is None:
active_group = request.REQUEST.get('active_group')
if active_group != request.session['active_group']:
request.session.modified = True
request.session['active_group'] = active_group
request.session['imageInBasket'] = set() # empty basket
request.session['basket_counter'] = 0

@login_required()
def logout(request, conn=None, **kwargs):
""" Logout of the session and redirects to the homepage (will redirect to login first) """
Expand Down Expand Up @@ -313,20 +318,25 @@ def load_template(request, menu, conn=None, url=None, **kwargs):

#tree support
init = {'initially_open':[], 'initially_select': None}
# E.g. path=project=51|dataset=502|image=607:selected
for k,v in string_to_dict(request.REQUEST.get('path')).items():
if k.lower() in ('project', 'dataset', 'image', 'screen', 'plate'):
for i in v.split(","):
if ":selected" in str(i) and init['initially_select'] is None:
init['initially_select'] = k+"-"+i.replace(":selected", "") # E.g. image-607
else:
init['initially_open'].append(k+"-"+i) # E.g. ['project-51', 'dataset-502']

if init['initially_select'] is None:
sdict = string_to_dict(request.REQUEST.get('path'))
k = sdict.keys()[-1]
init['initially_select'] = k+"-"+sdict[k]

# E.g. path=project-51|dataset-502|image-607
path = request.REQUEST.get('path', '')
first_sel = None
init['initially_open'] = [str(i) for i in path.split("|") if i.split("-")[0] in ('project', 'dataset', 'image', 'screen', 'plate')]
if len(init['initially_open']) > 0:
init['initially_select'] = init['initially_open'][-1]
first_obj, first_id = init['initially_open'][0].split("-")
try:
first_sel = conn.getObject(first_obj, long(first_id))
except ValueError:
pass # invalid id
if first_obj not in ("project", "screen"):
# need to see if first item has parents
if first_sel is not None:
for p in first_sel.getAncestry():
init['initially_open'].insert(0, "%s-%s" % (p.OMERO_CLASS.lower(), p.getId()))
# need to be sure that tree will be correct omero.group
if first_sel is not None:
switch_active_group(request, first_sel.details.group.id.val)

# search support
if menu == "search" and request.REQUEST.get('search_query'):
Expand Down Expand Up @@ -1905,7 +1915,7 @@ def getObjectUrl(conn, obj):
"""
This provides a url to browse to the specified omero.model.ObjectI P/D/I, S/P, FileAnnotation etc.
used to display results from the scripting service
E.g webclient/userdata/?path=project=1|dataset=5|image=12601
E.g webclient/userdata/?path=image-12601
If the object is a file annotation, try to browse to the parent P/D/I
"""
base_url = reverse(viewname="load_template", args=['userdata'])
Expand All @@ -1917,46 +1927,15 @@ def getObjectUrl(conn, obj):
fa = conn.getObject("Annotation", obj.id.val)
for ptype in ['project', 'dataset', 'image']:
links = fa.getParentLinks(ptype)
for l in links:
obj = l.parent

if isinstance(obj, omero.model.ImageI):
# return path from first Project we find, or None if no Projects
blitz_obj = conn.getObject("Image", obj.id.val)
for d in blitz_obj.listParents():
for p in d.listParents():
url = "%s?path=project=%d|dataset=%d|image=%d" % (base_url, p.id, d.id, blitz_obj.id)
if len(links) > 0:
obj = links[0].parent
break
if url is None:
url = "%s?path=dataset=%d|image=%d:selected" % (base_url, d.id, blitz_obj.id) # if Dataset is orphan
break

if isinstance(obj, omero.model.DatasetI):
blitz_obj = conn.getObject("Dataset", obj.id.val)
for p in blitz_obj.listParents():
url = "%s?path=project=%d|dataset=%d" % (base_url, p.id, blitz_obj.id)
break
if obj.__class__.__name__ in ("ImageI", "DatasetI", "ProjectI", "ScreenI", "PlateI"):
otype = obj.__class__.__name__[:-1].lower()
base_url += "?path=%s-%s" % (otype, obj.id.val)

if isinstance(obj, omero.model.ProjectI):
blitz_obj = conn.getObject("Project", obj.id.val)
url = "%s?path=project=%d" % (base_url, obj.id.val)

if isinstance(obj, omero.model.PlateI):
blitz_obj = conn.getObject("Plate", obj.id.val)
screen = blitz_obj.getParent()
if screen is not None:
url = "%s?path=screen=%d|plate=%d" % (base_url, screen.id, blitz_obj.id)
else:
url = "%s?path=plate=%d" % (base_url, obj.id.val)

if isinstance(obj, omero.model.ScreenI):
blitz_obj = conn.getObject("Screen", obj.id.val)
url = "%s?path=screen=%d" % (base_url, obj.id.val)

if blitz_obj is None:
return (url, None)
group_id = blitz_obj.getDetails().getGroup().id
return (url, group_id)
return base_url


######################
Expand Down Expand Up @@ -2077,9 +2056,7 @@ def activities(request, conn=None, **kwargs):
else:
if hasattr(v, "id"): # do we have an object (ImageI, FileAnnotationI etc)
obj_data = {'id': v.id.val, 'type': v.__class__.__name__[:-1]}
browse_url, group_id = getObjectUrl(conn, v)
obj_data['browse_url'] = browse_url
obj_data['group_id'] = group_id
obj_data['browse_url'] = getObjectUrl(conn, v)
if v.isLoaded() and hasattr(v, "file"):
#try:
mimetypes = {'image/png':'png', 'image/jpeg':'jpeg', 'image/tiff': 'tiff'}
Expand Down Expand Up @@ -2357,7 +2334,7 @@ def chgrp(request, conn=None, **kwargs):
return HttpResponse("OK")


@login_required()
@login_required(setGroupContext=True)
def script_run(request, scriptId, conn=None, **kwargs):
"""
Runs a script using values in a POST
Expand Down
19 changes: 0 additions & 19 deletions components/tools/OmeroWeb/omeroweb/webclient/webclient_utils.py
Expand Up @@ -51,23 +51,4 @@ def _purgeCallback(request):
if len(callbacks) > 200:
for (cbString, count) in zip(request.session.get('callback').keys(), range(0,len(callbacks)-200)):
del request.session['callback'][cbString]

def string_to_dict(string):
"""
Converts string e.g. path=project=51|dataset=502|image=607:selected to
dictionary that keeps its keys in the order in which they're inserted.
"""
kwargs = SortedDict()
if string is not None and len(string) > 0:
string = str(string)
if '|' not in string:
# ensure at least one ','
string += '|'
for arg in string.split('|'):
arg = arg.strip()
if arg == '': continue
kw, val = arg.split('=', 1)
kwargs[kw] = val
return kwargs


0 comments on commit 80b880a

Please sign in to comment.