<commit_before>import datetime
import collections
from itertools import groupby
from operator import itemgetter
from urlparse import parse_qs

from django.http import HttpResponse
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_http_methods

from billy.core import user_db
from billy.core import mdb
import billy.utils
from .utils import templatename


class Favorites(dict):
    '''This class wraps the favorites dict and provides convenience
    methods.
    '''

    def favorites_exist(self, type_):
        if type_ not in self:
            return False
        for obj in self[type_]:
            if obj['is_favorite']:
                return True
        return False

    def has_bills(self):
        return self.favorites_exist('bill')

    def has_legislators(self):
        return self.favorites_exist('legislator')

    def has_committees(self):
        return self.favorites_exist('committee')

    def has_searches(self):
        return self.favorites_exist('search')

    def legislator_objects(self):
        return [obj['obj'] for obj in self.get('legislator', [])]

    def committee_objects(self):
        return [obj['obj'] for obj in self.get('committee', [])]


class FavoritedSearch(dict):

    def __init__(self, *args, **kwargs):
        dict.__init__(self, *args, **kwargs)
        self.params = parse_qs(self['search_params'])
        if 'search_text' in self.params:
            self.text = self.params.pop('search_text')
        else:
            self.text = None

    def scope(self):
        '''Return a comma-separated list of human readable equivalents
        for things passed in the query string: California, Session 1...
        '''<commit_msg>get first item from search_text<commit_after>import datetime
import collections
from itertools import groupby
from operator import itemgetter
from urlparse import parse_qs

from django.http import HttpResponse
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_http_methods

from billy.core import user_db
from billy.core import mdb
import billy.utils
from .utils import templatename


class Favorites(dict):
    '''This class wraps the favorites dict and provides convenience
    methods.
    '''

    def favorites_exist(self, type_):
        if type_ not in self:
            return False
        for obj in self[type_]:
            if obj['is_favorite']:
                return True
        return False

    def has_bills(self):
        return self.favorites_exist('bill')

    def has_legislators(self):
        return self.favorites_exist('legislator')

    def has_committees(self):
        return self.favorites_exist('committee')

    def has_searches(self):
        return self.favorites_exist('search')

    def legislator_objects(self):
        return [obj['obj'] for obj in self.get('legislator', [])]

    def committee_objects(self):
        return [obj['obj'] for obj in self.get('committee', [])]


class FavoritedSearch(dict):

    def __init__(self, *args, **kwargs):
        dict.__init__(self, *args, **kwargs)
        self.params = parse_qs(self['search_params'])
        if 'search_text' in self.params:
            self.text = self.params.pop('search_text').pop()
        else:
            self.text = None

    def scope(self):
        '''Return a comma-separated list of human readable equivalents
        for things passed in the query string: California, Session 1...
        '''
{'fraction_non_alphanumeric': 0.09088366890380313, 'fraction_numerical': 0.0005592841163310962, 'mean_word_length': 3.0281531531531534, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4133511', 'n_tokens_mistral': 1029, 'n_tokens_neox': 986, 'n_words': 304}