Beispiel #1
0
 def isReport(self, name):
     """ See IMailinDispatcher.
     """
     root = find_root(self.context)
     if name in root.list_aliases:
         return True
     pd = find_peopledirectory(self.context)
     tokens = name.split('+')
     try:
         find_model(pd, tokens)
     except KeyError:
         return False
     return True
Beispiel #2
0
 def isReport(self, name):
     """ See IMailinDispatcher.
     """
     root = find_root(self.context)
     if name in root.list_aliases:
         return True
     pd = find_peopledirectory(self.context)
     tokens = name.split('+')
     try:
         find_resource(pd, tokens)
     except KeyError:
         return False
     return True
Beispiel #3
0
def _searchresults_view(context, request, page_title, calendar_search, show_search_knobs):
    api = TemplateAPI(context, request, page_title)

    # The layout is decided independently of whether we are a
    # calendar search or not. What is taken in consideration: if we are
    # in a community. The /offices section is considered a non-community
    # and will use the wide layout.
    if ICommunity.providedBy(context):
        if calendar_search:
            # We are either in /communities, or in /offices. In the first case:
            # we use the community layout. For offices: we need the wide layout
            # with the generic layout.
            context_path = resource_path(context)
            wide = context_path.startswith('/offices')
            if wide:
                layout = api.generic_layout
            else:
                layout = api.community_layout
        else:
            layout = api.community_layout
        community = context.title
    else:
        layout = api.generic_layout
        community = None

    request.unicode_errors = 'ignore'
    batch = None
    terms = ()
    error = None
    params = request.params.copy()
    if 'batch_start' in params:
        del params['batch_start']
    if 'batch_size' in params:
        del params['batch_size']

    kind_knob = []
    selected_kind = params.get('kind')

    scope_path = request.params.get('scopePath', '')

    # We show the scope knob, but in a limited way.
    # We only have a path here, so we show that path
    # and a single option to go back to All KARL.
    # If we are on all karl already, this knob group
    # will not show at all, defaulting to KARL's legacy
    # behaviour.
    scope_label = request.params.get('scopeLabel', '')
    if scope_path:
        scope_knob = []
        scope_knob.append({
            'name': scope_label,
            'title': scope_label,
            'description': scope_label,
            'icon': None,
            'url': None,
            'selected': True,
        })
        query = params.copy()
        query.update(scopePath='', scopeLabel='All KARL')
        scope_knob.append({
            'name': 'All KARL',
            'title': 'All KARL',
            'description': 'All KARL',
            'icon': None,
            'url': resource_url(find_root(context), request, request.view_name, query=query),
            'selected': False,
        })
    else:
        # The knob will not show at all
        scope_knob = None

    # There is a mapping needed between the livesearch
    # and the advanced search "kind" identifiers. This artifact is
    # a bit of annoyance but it's the easiest to do this
    # transformation here. Previously this was done from js.
    # Currently, if you click on livesearch results to
    # get into the advanced search, the livesearch kinds
    # will be submitted: which is why we convert from here.
    selected_kind = {
        'pages': 'wiki',
        'posts': 'blog',
        }.get(selected_kind, selected_kind)

    # In case we have a calendar search:
    # we will use events only as the content type.
    if calendar_search and selected_kind is None:
        # This means: filter events only in the result.
        selected_kind = 'events'

    for o in get_listitems(IGroupSearchFactory):
        component = o['component']
        if not component.advanced_search:
            continue
        kind = o['name']
        query = params.copy()
        query['kind'] = kind
        kind_knob.append({
            'name': kind,
            'title': o['title'],
            'icon': component.icon,
            'url': resource_url(context, request, request.view_name,
                             query=query),
            'selected': kind == selected_kind,
        })
    query = params.copy()
    if 'kind' in query:
        del query['kind']
    kind_knob.insert(0, {
        'name': 'all_content',
        'title': 'All Content',
        'description': 'All Content',
        'icon': None,
        'url': resource_url(context, request, request.view_name, query=query),
        'selected': not selected_kind,
    })

    since_knob = []
    selected_since = params.get('since')
    for id in since_order:
        option = since_options[id].copy()
        query = params.copy()
        if id is not None:
            query['since'] = id
        elif 'since' in query:
            del query['since']
        option['url'] = resource_url(context, request, request.view_name,
                                  query=query)
        option['selected'] = id == selected_since
        since_knob.append(option)

    sort_knob = []
    selected_sort = params.get('sort')
    for id in sort_order:
        option = sort_options[id].copy()
        query = params.copy()
        if id is not None:
            query['sort'] = id
        elif 'sort' in query:
            del query['sort']
        option['url'] = resource_url(context, request, request.view_name,
                                  query=query)
        option['selected'] = id == selected_sort
        sort_knob.append(option)

    start_time = time.time()
    try:
        batch, terms = get_batch(context, request)
    except ParseError, e:
        error = 'Error: %s' % e
Beispiel #4
0
def _searchresults_view(context, request, page_title, calendar_search,
                        show_search_knobs):
    api = TemplateAPI(context, request, page_title)

    # The layout is decided independently of whether we are a
    # calendar search or not. What is taken in consideration: if we are
    # in a community. The /offices section is considered a non-community
    # and will use the wide layout.
    if ICommunity.providedBy(context):
        if calendar_search:
            # We are either in /communities, or in /offices. In the first case:
            # we use the community layout. For offices: we need the wide layout
            # with the generic layout.
            context_path = resource_path(context)
            wide = context_path.startswith('/offices')
            if wide:
                layout = api.generic_layout
            else:
                layout = api.community_layout
        else:
            layout = api.community_layout
        community = context.title
    else:
        layout = api.generic_layout
        community = None

    request.unicode_errors = 'ignore'
    batch = None
    terms = ()
    error = None
    params = request.params.copy()
    if 'batch_start' in params:
        del params['batch_start']
    if 'batch_size' in params:
        del params['batch_size']

    kind_knob = []
    selected_kind = params.get('kind')

    scope_path = request.params.get('scopePath', '')

    # We show the scope knob, but in a limited way.
    # We only have a path here, so we show that path
    # and a single option to go back to All KARL.
    # If we are on all karl already, this knob group
    # will not show at all, defaulting to KARL's legacy
    # behaviour.
    scope_label = request.params.get('scopeLabel', '')
    if scope_path:
        scope_knob = []
        scope_knob.append({
            'name': scope_label,
            'title': scope_label,
            'description': scope_label,
            'icon': None,
            'url': None,
            'selected': True,
        })
        query = params.copy()
        query.update(scopePath='', scopeLabel='All KARL')
        scope_knob.append({
            'name':
            'All KARL',
            'title':
            'All KARL',
            'description':
            'All KARL',
            'icon':
            None,
            'url':
            resource_url(find_root(context),
                         request,
                         request.view_name,
                         query=query),
            'selected':
            False,
        })
    else:
        # The knob will not show at all
        scope_knob = None

    # There is a mapping needed between the livesearch
    # and the advanced search "kind" identifiers. This artifact is
    # a bit of annoyance but it's the easiest to do this
    # transformation here. Previously this was done from js.
    # Currently, if you click on livesearch results to
    # get into the advanced search, the livesearch kinds
    # will be submitted: which is why we convert from here.
    selected_kind = {
        'pages': 'wiki',
        'posts': 'blog',
    }.get(selected_kind, selected_kind)

    # In case we have a calendar search:
    # we will use events only as the content type.
    if calendar_search and selected_kind is None:
        # This means: filter events only in the result.
        selected_kind = 'events'

    for o in get_listitems(IGroupSearchFactory):
        component = o['component']
        if not component.advanced_search:
            continue
        kind = o['name']
        query = params.copy()
        query['kind'] = kind
        kind_knob.append({
            'name':
            kind,
            'title':
            o['title'],
            'icon':
            component.icon,
            'url':
            resource_url(context, request, request.view_name, query=query),
            'selected':
            kind == selected_kind,
        })
    query = params.copy()
    if 'kind' in query:
        del query['kind']
    kind_knob.insert(
        0, {
            'name': 'all_content',
            'title': 'All Content',
            'description': 'All Content',
            'icon': None,
            'url': resource_url(
                context, request, request.view_name, query=query),
            'selected': not selected_kind,
        })

    since_knob = []
    selected_since = params.get('since')
    for id in since_order:
        option = since_options[id].copy()
        query = params.copy()
        if id is not None:
            query['since'] = id
        elif 'since' in query:
            del query['since']
        option['url'] = resource_url(context,
                                     request,
                                     request.view_name,
                                     query=query)
        option['selected'] = id == selected_since
        since_knob.append(option)

    sort_knob = []
    selected_sort = params.get('sort')
    for id in sort_order:
        option = sort_options[id].copy()
        query = params.copy()
        if id is not None:
            query['sort'] = id
        elif 'sort' in query:
            del query['sort']
        option['url'] = resource_url(context,
                                     request,
                                     request.view_name,
                                     query=query)
        option['selected'] = id == selected_sort
        sort_knob.append(option)

    start_time = time.time()
    try:
        batch, terms = get_batch(context, request)
    except ParseError, e:
        error = 'Error: %s' % e