def _get_user_home_path(context, request): """If currently authenticated user has a 'home_path' set, create a response redirecting user to that path. Otherwise return None. """ userid = authenticated_userid(request) if userid is None: return None, None site = find_site(context) profiles = find_profiles(site) profile = profiles.get(userid, None) if profile is None: return None, None home_path = getattr(profile, 'home_path', None) if home_path: # OSI sets this to a single space to mean None home_path = home_path.strip() if not home_path: return None, None tdict = traverse(site, home_path) target = tdict['context'] view_name = tdict['view_name'] subpath = list(tdict['subpath']) if view_name: subpath.insert(0, view_name) return target, subpath
def traverse_view(self, path, REQUEST=None): viewdef = traverse(self, path) if REQUEST is None: REQUEST = self._request() request = REQUEST #gsm = registry._registry #/gsm = zope.component.getSiteManager() try: reg = request.registry except AttributeError: reg = get_current_registry() context = viewdef['context'] name = viewdef['view_name'] provides = map(providedBy, (request, context)) #BREAKPOINT() #view = gsm.getMultiAdapter((c,REQUEST),repoze.bfg.interfaces.IView,n) view = reg.adapters.lookup(provides, repoze.bfg.interfaces.IView, name=name) return view(context, request)
def batch_images(context, request, get_image_info=get_image_info, # unittest get_images_batch=get_images_batch): # unittest include_image_url = request.params.get('include_image_url', None) # include_image_url is a special case. include_info = None if include_image_url is not None: # Note, we must use the path only, as IE submits the full domain # and without the next line IE would fail. path = urlparse.urlparse(include_image_url)[2] include_context = traverse(context, path)['context'] if IImage.providedBy(include_context): # We have a good image to include. include_info = get_image_info(include_context, request) # Find query parameters based on the 'source' param, # which signifies the selection index of the source button # in the imagedrawer dialog. source = request.params.get('source') assert source in ('myrecent', 'thiscommunity', 'allkarl') if source == 'myrecent': creator = authenticated_userid(request) community_path = None elif source == 'thiscommunity': creator = None community = find_community(context) # batching api requires the community path community_path = model_path(community) else: # All Karl creator = None community_path = None # batching # Decide start and size here, don't let the lower levels # apply their default. This allows us to enforce # a MINIMAL_BATCH size. batch_start = int(request.params.get('start', '0')) batch_size = int(request.params.get('limit', '0')) # there is a minimal batch size to enforce, if the client # does not ask for one # Just pass the values to lower levels where sensible # defaults will be applied. sort_index = request.params.get('sort_on', None) reverse = request.params.get('reverse', None) # XXX include_image will now be inserted in the first # position, as extra image. insert_extra = False if include_info is not None: if batch_start == 0: batch_size -= 1 insert_extra = True else: batch_start -= 1 # Enforce the minimal batch size batch_size = max(batch_size, MINIMAL_BATCH) search_params = dict( creator=creator, community=community_path, batch_start=batch_start, batch_size=batch_size, ) if sort_index: search_params['sort_index'] = sort_index if reverse: search_params['reverse'] = bool(int(reverse)) batch_info = get_images_batch( context, request, **search_params ) records = [get_image_info(image, request) for image in batch_info['entries']] start = batch_info['batch_start'] totalRecords = batch_info['total'] # add the fake included image if include_info is not None: totalRecords += 1 if insert_extra: records.insert(0, include_info) else: start += 1 return dict( records = records, start = start, totalRecords = totalRecords, )