def fetch_hacks(self, req, data, types, releases): """Return a list of hacks in the form [votes, rank, resource, tags, title] """ tag_system = TagSystem(self.env) vote_system = VoteSystem(self.env) query = 'realm:wiki (%s) (%s)' % \ (' or '.join(releases), ' or '.join(types)) self.env.log.debug(query) tagged = tag_system.query(req, query) # Limit try: limit = int(req.args.get('limit', self.limit)) data['limit_message'] = 'top %s' % limit except ValueError: data['limit_message'] = 'all' limit = 9999 data['limit'] = limit # Query q = req.args.get('q', '') data['query'] = q query = Query(q.lower()) # Build hacks list hacks = [] for resource, tags in tagged: page = WikiPage(self.env, resource.id) if q: text = page.name.lower() + page.text.lower() + ' '.join(tags) if not query(text): continue _, count, _ = vote_system.get_vote_counts(resource) match = self.title_extract.search(page.text) count_string = pluralise(count, 'vote') if match: title = '%s (%s)' % (match.group(1).strip(), count_string) else: title = '%s' % count_string hacks.append([count, None, resource, tags, title]) # Rank total_hack_count = len(hacks) hacks = sorted(hacks, key=lambda i: -i[0]) remainder = hacks[limit:] hacks = hacks[:limit] + random.sample(remainder, min(limit, len(remainder))) # Navigation #if len(hacks) >= limit: # add_ctxtnav(req, builder.a('More', href='?action=more')) # limit = len(hacks) # data['limit'] = data['limit_message'] = limit #else: # add_ctxtnav(req, 'More') #if q or limit != self.limit: # add_ctxtnav(req, builder.a('Default', href='?action=default')) #else: # add_ctxtnav(req, 'Default') #if total_hack_count > limit: # add_ctxtnav(req, builder.a('All', href='?action=all')) #else: # add_ctxtnav(req, 'All') #if limit > 10: # limit = min(limit, len(hacks)) # add_ctxtnav(req, builder.a('Less', href='?action=less')) #else: # add_ctxtnav(req, 'Less') #for i, hack in enumerate(hacks): # hack[1] = i return hacks
def style(self, ticket, req, **style): votesystem = VoteSystem(self.env) votes = votesystem.get_vote_counts('ticket/%s' % ticket.id)[1] max_votes = votesystem.get_max_votes('ticket') size = self.marker_radius(votes, max_votes) return { 'pointRadius': str(int(size)) }