1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """
23 Decorators for use with the webclient application.
24 """
25
26 import logging
27
28 import omeroweb.decorators
29
30 from django.http import HttpResponse, HttpResponseServerError, Http404
31 from django.utils.http import urlencode
32 from django.conf import settings
33 from django.core.urlresolvers import reverse
34
35 from omeroweb.webgateway import views as webgateway_views
36 from omeroweb.connector import Server
37 from omeroweb.webclient.webclient_http import HttpLoginRedirect
38
39 logger = logging.getLogger('omeroweb.webclient.decorators')
40
42 """
43 webclient specific extension of the OMERO.web login_required() decorator.
44 """
45
46 - def __init__(self, ignore_login_fail=False, setGroupContext=False, login_redirect=None, **kwargs):
47 """
48 Initialises the decorator.
49 """
50 super(login_required, self).__init__(**kwargs)
51 self.ignore_login_fail = ignore_login_fail
52 self.setGroupContext = setGroupContext
53 self.login_redirect = login_redirect
54
64
66 """ This can be used to fail silently (not return 403, 500 etc. E.g. keepalive ping)"""
67 if self.ignore_login_fail:
68 return HttpResponse("Connection Failed")
69 if self.login_redirect is not None:
70 try:
71 url = reverse(self.login_redirect)
72 except:
73 pass
74 return super(login_required, self).on_not_logged_in(request, url, error)
75
93
95 """ Subclass for adding additional data to the 'context' dict passed to templates """
96
97 - def prepare_context(self, request, context, *args, **kwargs):
98 """
99 This allows templates to access the current eventContext and user from the L{omero.gateway.BlitzGateway}.
100 E.g. <h1>{{ ome.user.getFullName }}</h1>
101 If these are not required by the template, then they will not need to be loaded by the Blitz Gateway.
102 The results are cached by Blitz Gateway, so repeated calls have no additional cost.
103 We also process some values from settings and add these to the context.
104 """
105
106
107 if 'conn' not in kwargs:
108 return
109 conn = kwargs['conn']
110
111 context.setdefault('ome', {})
112 context['ome']['eventContext'] = conn.getEventContext
113 context['ome']['user'] = conn.getUser
114 context['ome']['basket_counter'] = request.session.get('basket_counter', 0)
115 context['ome']['user_id'] = request.session.get('user_id', None)
116 context['ome']['group_id'] = request.session.get('group_id', None)
117 context['ome']['active_group'] = request.session.get('active_group', conn.getEventContext().groupId)
118 if settings.WEBSTART:
119 context['ome']['insight_url'] = request.build_absolute_uri(reverse("webstart_insight"))
120 self.load_settings(request, context, conn)
121
122
124
125
126 ping_interval = settings.PING_INTERVAL
127 if ping_interval > 0:
128 context['ping_interval'] = ping_interval
129
130 top_links = settings.TOP_LINKS
131 links = []
132 for tl in top_links:
133 label = tl[0]
134 link_id = tl[1]
135 try:
136 link = reverse(link_id)
137 links.append( {"label":label, "link":link} )
138 except:
139
140 links.append( {"label":label, "link":link_id} )
141 context['ome']['top_links'] = links
142
143 right_plugins = settings.RIGHT_PLUGINS
144 r_plugins = []
145 for rt in right_plugins:
146 label = rt[0]
147 include = rt[1]
148 plugin_id = rt[2]
149 r_plugins.append( {"label":label, "include":include, "plugin_id": plugin_id} )
150 context['ome']['right_plugins'] = r_plugins
151
152 center_plugins = settings.CENTER_PLUGINS
153 c_plugins = []
154 for cp in center_plugins:
155 label = cp[0]
156 include = cp[1]
157 plugin_id = cp[2]
158 c_plugins.append( {"label":label, "include":include, "plugin_id": plugin_id} )
159 context['ome']['center_plugins'] = c_plugins
160