Example #1
0
 def type(self):
     if self._type is None:
         self._type = get_content_type_name(self.context)
     return self._type
Example #2
0
 def type(self):
     if self._type is None:
         self._type = get_content_type_name(self.context)
     return self._type
Example #3
0
File: tags.py Project: lslaz1/karl
def showtag_view(context, request, community=None, user=None, crumb_title=None):
    """Show a page for a particular tag, optionally refined by context."""

    page_title = 'Show Tag'
    api = TemplateAPI(context, request, page_title)

    # The tag screens (cloud, listing, and this view) each have a
    # "jump box" that allows you to quickly jump to another tag.  All
    # three will point here at /showtag?tag=tag1.  We detect this mode
    # and do a redirect.
    jump_tag = request.params.get('jumptag', False)
    if jump_tag:
        location = resource_url(context, request, request.view_name, jump_tag)
        return HTTPFound(location=location)

    # Our strategy is to support tag URLs that are like this:
    #     /showtag/tag1
    # ...instead of:
    #     /tagpage.html?tag=tag1
    # However, our tag data isn't traversable (it is site.tags and not
    # site['tags'].  So we have a view at /showtag that picks apart
    # the next hop in the URL.
    tag = request.subpath
    if not tag:
        # The user didn't provide anything beyond /showtag in the URL
        tag = None
        entries = related = []
    else:
        # Ahh, the good part.  Let's find some tag results and unpack
        # data into what the ZPT needs.
        tag = tag[0]

        catalog = find_catalog(context)
        dm = catalog.document_map
        tags = find_tags(context)

        if community is None and user is None:
            # Only show related tags portlet in global view
            related = tags.getRelatedTags(tag, user=user, community=community)
        else:
            related = []

        entries = []
        if user:
            users = (user,)
        else:
            users = None
        for docid in tags.getItems(tags=(tag,), users=users,
                                   community=community,
                                   ):
            # XXX Need to wire in batching
            address = dm.address_for_docid(int(docid))
            if address is None:
                raise KeyError(docid)
            resource = find_resource(context, address)

            # Skip documents which aren't viewable by authenticated user
            if not has_permission('view', resource, request):
                continue

            # Do a secondary query for each result to find the
            # per-user info
            users = tags.getUsers(tags=(tag,), items=(docid,),
                                  community=community)
            if len(users) == 1:
                tuh = '1 person'
            else:
                tuh = '%s people' % len(users)

            tuhref = resource_url(context, request, 'tagusers.html',
                                  query={'tag': tag, 'docid': docid})
            entry = {
                'title': resource.title,
                'description': getattr(resource, 'description', ''),
                'href': resource_url(resource, request),
                'type': get_content_type_name(resource),
                'tagusers_href': tuhref,
                'tagusers_count': tuh,
                }
            entries.append(entry)

    args = dict(
        api=api,
        tag=tag,
        entries=entries,
        related=related,
    )

    if crumb_title:
        # XXX Would context.title be a bit nicer for displaying to user?
        system_name = get_setting(context, 'title', 'KARL')
        args['crumbs'] = '%s / %s / %s' % (
            system_name, crumb_title, context.__name__)

    return dict(**args)
Example #4
0
def showtag_view(context, request, community=None, user=None, crumb_title=None):
    """Show a page for a particular tag, optionally refined by context."""

    layout = request.layout_manager.layout
    layout.page_title = 'Show Tag'
    api = TemplateAPI(context, request, layout.page_title)

    # The tag screens (cloud, listing, and this view) each have a
    # "jump box" that allows you to quickly jump to another tag.  All
    # three will point here at /showtag?tag=tag1.  We detect this mode
    # and do a redirect.
    jump_tag = request.params.get('jumptag', False)
    if jump_tag:
        location = resource_url(context, request, request.view_name, jump_tag)
        return HTTPFound(location=location)

    # Our strategy is to support tag URLs that are like this:
    #     /showtag/tag1
    # ...instead of:
    #     /tagpage.html?tag=tag1
    # However, our tag data isn't traversable (it is site.tags and not
    # site['tags'].  So we have a view at /showtag that picks apart
    # the next hop in the URL.
    tag = request.subpath
    if not tag:
        # The user didn't provide anything beyond /showtag in the URL
        tag = None
        entries = related = []
    else:
        # Ahh, the good part.  Let's find some tag results and unpack
        # data into what the ZPT needs.
        tag = tag[0]
        layout.page_title = 'Show Tag ' + tag

        catalog = find_catalog(context)
        dm = catalog.document_map
        tags = find_tags(context)

        if community is None and user is None:
            # Only show related tags portlet in global view
            related = tags.getRelatedTags(tag, user=user, community=community)
            layout.add_portlet('related_tags', related)
            layout.section_style = 'none'
        else:
            related = []

        entries = []
        if user:
            users = (user,)
        else:
            users = None
        for docid in tags.getItems(tags=(tag,), users=users,
                                   community=community,
                                   ):
            # XXX Need to wire in batching
            address = dm.address_for_docid(int(docid))
            if address is None:
                raise KeyError(docid)
            resource = find_resource(context, address)

            # Skip documents which aren't viewable by authenticated user
            if not has_permission('view', resource, request):
                continue

            # Do a secondary query for each result to find the
            # per-user info
            users = tags.getUsers(tags=(tag,), items=(docid,),
                                  community=community)
            if len(users) == 1:
                tuh = '1 person'
            else:
                tuh = '%s people' % len(users)

            tuhref = resource_url(context, request, 'tagusers.html',
                               query={'tag': tag, 'docid': docid})
            entry = {
                'title': resource.title,
                'description': getattr(resource, 'description', ''),
                'href': resource_url(resource, request),
                'type': get_content_type_name(resource),
                'tagusers_href': tuhref,
                'tagusers_count': tuh,
                }
            entries.append(entry)

    args = dict(
        api=api,  # deprecated in ux2
        tag=tag,
        entries=entries,
        related=related,  # deprecated in ux2
    )

    if crumb_title:
        # XXX Would context.title be a bit nicer for displaying to user?
        system_name = get_setting(context, 'system_name', 'KARL')
        args['crumbs'] = '%s / %s / %s' % (
            system_name, crumb_title, context.__name__)

    return dict(**args)
Example #5
0
        if not terms:
            error = "No Search Parameters Supplied."

    if batch:
        # Flatten the batch into data for use in the ZPT.
        results = []
        for result in batch["entries"]:
            try:
                description = result.description[0:300]
            except AttributeError:
                description = ""
            result = {
                "title": getattr(result, "title", "<No Title>"),
                "description": description,
                "url": model_url(result, request),
                "type": get_content_type_name(result),
            }
            results.append(result)
        total = batch["total"]
    else:
        batch = {"batching_required": False}
        results = ()
        total = 0

    return render_template_to_response(
        "templates/searchresults.pt",
        api=api,
        layout=layout,
        error=error,
        terms=terms,
        community=community,