Ejemplo n.º 1
0
def build_search_kwargs(user_q, request, types, staff, orderby):

    if not staff:
        user_q = And([
            user_q,
            Or([Term('public', 't'),
                Term('users', request.user.username)] + [
                    Term('groups', group.name)
                    for group in request.user.groups.all()
                ])
        ])

    if types and len(types) > 0:
        user_q = And([
            user_q,
            Or([Term('type', resource_type) for resource_type in types])
        ])

    orderby_f = FieldFacet(orderby.replace('-', ''),
                           reverse=orderby.find('-') > -1)

    search_kwargs = {
        'sortedby': [orderby_f],
        'collapse': FieldFacet('vendor_name'),
        'collapse_limit': 1,
        'collapse_order': FunctionFacet(order_by_version)
    }

    return (user_q, search_kwargs)
Ejemplo n.º 2
0
    def do_show(self, revid):
        """
        Show a blog item and a list of its blog entries below it.

        If tag GET-parameter is defined, the list of blog entries consists only
        of those entries that contain the tag value in their lists of tags.
        """
        # for now it is just one tag=value, later it could be tag=value1&tag=value2&...
        tag = request.values.get('tag')
        prefix = self.name + u'/'
        current_timestamp = int(time.time())
        terms = [
            Term(WIKINAME, app.cfg.interwikiname),
            # Only blog entry itemtypes
            Term(ITEMTYPE, ITEMTYPE_BLOG_ENTRY),
            # Only sub items of this item
            Prefix(NAME_EXACT, prefix),
        ]
        if tag:
            terms.append(Term(TAGS, tag))
        query = And(terms)

        def ptime_sort_key(searcher, docnum):
            """
            Compute the publication time key for blog entries sorting.

            If PTIME is not defined, we use MTIME.
            """
            fields = searcher.stored_fields(docnum)
            ptime = fields.get(PTIME, fields[MTIME])
            return ptime

        ptime_sort_facet = FunctionFacet(ptime_sort_key)

        revs = flaskg.storage.search(query,
                                     sortedby=ptime_sort_facet,
                                     reverse=True,
                                     limit=None)
        blog_entry_items = [
            Item.create(rev.name, rev_id=rev.revid) for rev in revs
        ]
        return render_template(
            'blog/main.html',
            item_name=self.name,
            fqname=split_fqname(self.name),
            blog_item=self,
            blog_entry_items=blog_entry_items,
            tag=tag,
            item=self,
        )