def test_bad_reverse_with_params_string(self, top_links): kwargs = top_links[0] with pytest.raises(TypeError) as excinfo: reverse_with_params(**kwargs) assert ('reverse_with_params() argument after ** must' ' be a mapping, not %s') % top_links[1] \ in str(excinfo.value)
def load_settings(self, request, context, conn): # Process various settings and add to the template context dict ping_interval = settings.PING_INTERVAL if ping_interval > 0: context['ping_interval'] = ping_interval top_links = settings.TOP_LINKS links = [] for tl in top_links: if len(tl) < 2: continue l = {} l["label"] = tl[0] link_id = tl[1] try: # test if complex dictionary view with args and query_string l["link"] = reverse_with_params(**link_id) except TypeError: # assume is only view name try: l["link"] = reverse(link_id) except NoReverseMatch: # assume we've been passed a url l["link"] = link_id # simply add optional attrs dict if len(tl) > 2: l['attrs'] = tl[2] links.append(l) context['ome']['top_links'] = links if settings.TOP_LOGO: context['ome']['logo_src'] = settings.TOP_LOGO if settings.TOP_LOGO_LINK: context['ome']['logo_href'] = settings.TOP_LOGO_LINK metadata_panes = settings.METADATA_PANES context['ome']['metadata_panes'] = metadata_panes right_plugins = settings.RIGHT_PLUGINS r_plugins = [] for rt in right_plugins: label = rt[0] include = rt[1] plugin_id = rt[2] r_plugins.append({ "label": label, "include": include, "plugin_id": plugin_id}) context['ome']['right_plugins'] = r_plugins center_plugins = settings.CENTER_PLUGINS c_plugins = [] for cp in center_plugins: label = cp[0] include = cp[1] plugin_id = cp[2] c_plugins.append({ "label": label, "include": include, "plugin_id": plugin_id}) context['ome']['center_plugins'] = c_plugins context['ome']['user_dropdown'] = settings.USER_DROPDOWN
def _find_first_selected(self): if len(self._initially_select) == 0: return None # tree hierarchy open to first selected object m = self.PATH_REGEX.match(self._initially_select[0]) if m is None: return None first_obj = m.group('object_type') # if we are showing any of map.value alias make sure # we are not in webclient if (first_obj in mapr_settings.CONFIG.keys() and self.menu not in mapr_settings.CONFIG): # redirect to menu/?value=VALUE link = { "viewname": "maprindex_%s" % first_obj, "query_string": { 'value': m.group('value') } } raise omeroweb_show.IncorrectMenuError(reverse_with_params(**link)) # if in mapr app hierachy is different if self.menu in mapr_settings.CONFIG: first_selected = None try: key = m.group('key') value = m.group('value') if key == 'id': value = int(value) attributes = {key: value} # Set context to 'cross-group' self.conn.SERVICE_OPTS.setOmeroGroup('-1') first_selected = self._load_first_selected( first_obj, attributes) except Exception: pass if first_obj not in self.TOP_LEVEL_PREFIXES: # Need to see if first item has parents if first_selected is not None: for p in first_selected.getAncestry(): # # we display images directly self._initially_open.insert( 0, "%s-%s" % (p.OMERO_CLASS.lower(), p.getId())) self._initially_open_owner = p.details.owner.id.val m = self.PATH_REGEX.match(self._initially_open[0]) if m.group('object_type') == 'image': self._initially_open.insert(0, "orphaned-0") return first_selected return super(MapShow, self)._find_first_selected()
def parse_url(lookup_view): if not lookup_view: raise ValueError("No lookup_view") url = None try: url = reverse_with_params(viewname=lookup_view['viewname'], args=lookup_view['args'], query_string=lookup_view['query_string']) except KeyError: # assume we've been passed a url try: resolve(lookup_view) url = lookup_view except: pass if url is None: logger.error("Reverse for '%s' not found." % lookup_view) raise NoReverseMatch("Reverse for '%s' not found." % lookup_view) return url
def parse_url(lookup_view): if not lookup_view: raise ValueError("No lookup_view") url = None try: url = reverse_with_params( viewname=lookup_view["viewname"], args=lookup_view.get("args", []), query_string=lookup_view.get("query_string", None), ) except KeyError: # assume we've been passed a url try: resolve(lookup_view) url = lookup_view except Exception: pass if url is None: logger.error("Reverse for '%s' not found." % lookup_view) raise NoReverseMatch("Reverse for '%s' not found." % lookup_view) return url
def test_reverse_with_params_string(self, top_links): top_link = top_links[0] assert reverse_with_params(top_link) == reverse( top_link) == top_links[1]
def test_reverse_with_params_dict(self, top_links): top_link = json.loads(top_links[0]) assert reverse_with_params(**top_link) == top_links[1]