Exemplo n.º 1
0
def groupitems(query,
               facet,
               parent,
               link,
               links=0,
               buttons=0,
               perpage=coll.ITEMS_PER_GROUPED_PAGE,
               pergroup=coll.ITEMS_PER_GROUP,
               perrow=coll.ITEMS_PER_ROW,
               sort=None,
               order=None,
               **args):
    groups = db.groups(query, facet, parent, order=order)
    parents = db.parentlist(facet, [id for name, id, count in groups])

    totalcount = 0
    for name, id, count in groups:
        totalcount += count
    if totalcount <= perpage: limit = None
    elif len(groups) == 1: limit = perpage
    else: limit = pergroup

    rows = []
    for name, id, count in groups:
        term = (facet, id, 0)
        head = cls('grouphead', name or 'none')
        if links: head = link(head, term=term)
        rows.append((head, term, buttons and id and count > 1, count, limit))
    term = (facet, parent, 1)
    count = db.count(query + term)
    if count:
        name = [big(nbsp), groups and '(others)' or '(all)']
        rows.append((name, term, buttons and count > 1, count, pergroup))

    results = []
    for head, term, refine, count, limit in rows:
        q = query + term
        items = db.list(q, limit=limit, sort=sort)
        #if user clicks on all _number_ items, go to ungrouped view
        more = limit and count > limit and link(
            'all %d items...' % count, term=term, group=None)
        listing = itemtable(items, more=more, link=link, query=q, **args)
        if refine:
            tip = 'look only within these %d items' % count
            button = link(img(coll.DETAIL_SRC, alt=tip), term=term)
        else:
            button = nbsp
        results += [
            p,
            tablew(tr(
                td(head,
                   nbsp,
                   cls('count', '(%d)' % count),
                   nbsp * 2,
                   button,
                   c='facetbox')),
                   tr(td(listing, c='valuebox')),
                   c='facet_' + facet)
        ]
    return results
Exemplo n.º 2
0
def topic_data():
    rows = []
    for r in list(db.list('mapviews/sort', 'mapviews/topics', group=True))[1]['rows']:
        rows.append({'c': [{'v': r['key']}, {'v': r['value']}]})

    response = {
        'cols': __cols([('Topic', 'string'), ('Tweets', 'number')]),
        'rows': rows
    }

    return jsonify(response)
Exemplo n.º 3
0
def follower_data():
    rows = []
    for r in list(db.list('mapviews/sortMax', 'mapviews/followers', group=True))[1]['rows']:
        rows.append({'c': [{'v': r['key']}, {'v': r['value']['max']}]})

    response = {
        'cols': __cols([('Name', 'string'), ('Followers', 'number')]),
        'rows': rows
    }

    return jsonify(response)
Exemplo n.º 4
0
def topic_data():
    rows = []
    for r in list(db.list('mapviews/sort', 'mapviews/topics',
                          group=True))[1]['rows']:
        rows.append({'c': [{'v': r['key']}, {'v': r['value']}]})

    response = {
        'cols': __cols([('Topic', 'string'), ('Tweets', 'number')]),
        'rows': rows
    }

    return jsonify(response)
Exemplo n.º 5
0
def follower_data():
    rows = []
    for r in list(db.list('mapviews/sortMax', 'mapviews/followers',
                          group=True))[1]['rows']:
        rows.append({'c': [{'v': r['key']}, {'v': r['value']['max']}]})

    response = {
        'cols': __cols([('Name', 'string'), ('Followers', 'number')]),
        'rows': rows
    }

    return jsonify(response)
Exemplo n.º 6
0
def listitems(query,
              offset=0,
              perpage=coll.ITEMS_PER_UNGROUPED_PAGE,
              perrow=coll.ITEMS_PER_ROW,
              sort=None,
              maxnumdisplay=None,
              **args):
    print "SORT"
    print sort
    if maxnumdisplay is None:
        return itemtable(db.list(query, (offset, perpage), sort),
                         perrow,
                         query=query,
                         offset=offset,
                         **args)
    else:
        result = []
        numresults = len(db.list(query, (offset, perpage), sort))
        for i in range(maxnumdisplay):
            if i < numresults:
                result.append(db.list(query, (offset, perpage), sort)[i])
        #print len(result)
        return itemtable(result, perrow, query=query, offset=offset, **args)
Exemplo n.º 7
0
    def prepare(self):
        self.ip = self.request.remoteAddress()
        self.query = Query(db, text=self.form.get('q', ''))
        self.group = self.form.get('group', '')
        if 'oldq' in self.form:
            self.oldquery = Query(db, text=self.form.get('oldq', ''))
        else:
            self.oldquery = None
        self.item = self.form.get('item', '')
        self.history = self.form.get('history', '')
        self.searchhistory = self.form.get('searchhistory', '')
        self.searchsave = self.form.get('searchsave', '')
        self.favesave = self.form.get('favesave', '')
        self.manage = self.form.get('manage', '')
        self.task = self.form.get('task', '')
        self.taskcomplete = self.form.get('taskcomplete', '')
        self.managestart = self.form.get('managestart', '')
        self.createaccount = self.form.get('createaccount', '')
        self.managesearch = self.form.get('managesearch', '')
        self.managesave = self.form.get('managesave', '')
        self.renamegname = self.form.get('renamegname', '')

        self.logout = self.form.get('logout', '')
        self.help = self.form.get('help', '')
        self.searchname = self.form.get('searchname', '')
        self.groupid = self.form.get('groupid', '')
        self.action = self.form.get('action', '')
        self.facet = self.form.get('facet', '')

        self.sort = self.form.get('sort', '')
        self.sortkeys = db.keylist[:]
        if self.sort:
            self.sortkeys.remove(self.sort)
            self.sortkeys[:0] = [self.sort]
        self.offset = int(self.form.get('offset', '0'))
        self.index = None
        if 'index' in self.form:
            self.index = int(self.form.index)
        if self.form.get('survey'):
            log.log(self,
                    'survey',
                    closer=self.form.closer,
                    ipaddr=self.ip,
                    expected=self.form.expected,
                    useful=self.form.useful)
        if self.form.get('in') == 'all':
            self.query = Query(db)
        self.words = []
        if self.form.get('words', '').strip():
            self.words = []
            quoted = re.compile(r'"([^"]*)"')
            words = self.form.words.strip()
            while words:
                match = quoted.match(words)
                if match:
                    self.words.append(match.group(1))
                    words = words[match.end():].strip()
                else:
                    if words[:1] == '"': words = words[1:]
                    bits = words.strip().split(' ', 1) + ['']
                    self.words.append(bits[0])
                    words = bits[1].strip()
            for word in self.words:
                self.query += word
        self.values = {}
        for facet in db.facetlist:
            self.values[facet] = 0
        for facet, id, leaf in self.query.getterms():
            self.values[facet] = id
        if self.index is not None:
            self.results = db.list(self.query, sort=self.sortkeys)
            self.item = self.results[self.index]
            self.count = len(self.results)
        else:
            self.count = db.count(self.query)