<commit_before>from django import forms
from django.conf import settings
#from django.contrib.admin.widgets import FilteredSelectMultiple

from billy.models import db, Metadata


def get_state_select_form(data):
    states = map(Metadata.get_object, sorted(settings.ACTIVE_STATES))
    state_abbrs = [('', '')]
    state_abbrs += [(obj['_id'], obj['name']) for obj in states]

    class StateSelectForm(forms.Form):
        abbr = forms.ChoiceField(choices=state_abbrs, label="state")

    return StateSelectForm(data)


class FindYourLegislatorForm(forms.Form):
    address = forms.CharField()


def get_filter_bills_form(metadata):

    class FilterBillsForm(forms.Form):

        search_text = forms.CharField(required=False)

        # `metadata` will be None if the search is for all states.
        if metadata:
            _bill_types = metadata.distinct_bill_types()
            _bill_subjects = metadata.distinct_bill_subjects()
            _bill_sponsors = [(leg['_id'], leg.display_name()) for leg in
                              metadata.legislators()]
            _sessions = [(s['id'], s['name']) for s in metadata.sessions()]<commit_msg>fix for state select form if some states aren't loaded<commit_after>from django import forms
from django.conf import settings
#from django.contrib.admin.widgets import FilteredSelectMultiple

from billy.models import db, Metadata, DoesNotExist


def get_state_select_form(data):
    state_abbrs = [('', '')]
    for state in sorted(settings.ACTIVE_STATES):
        try:
            print state
            obj = Metadata.get_object(state)
            state_abbrs.append((obj['_id'], obj['name']))
        except DoesNotExist:
            # ignore missing states
            pass

    class StateSelectForm(forms.Form):
        abbr = forms.ChoiceField(choices=state_abbrs, label="state")

    return StateSelectForm(data)


class FindYourLegislatorForm(forms.Form):
    address = forms.CharField()


def get_filter_bills_form(metadata):

    class FilterBillsForm(forms.Form):

        search_text = forms.CharField(required=False)

        # `metadata` will be None if the search is for all states.
        if metadata:
            _bill_types = metadata.distinct_bill_types()
            _bill_subjects = metadata.distinct_bill_subjects()
            _bill_sponsors = [(leg['_id'], leg.display_name()) for leg in
                              metadata.legislators()]
            _sessions = [(s['id'], s['name']) for s in metadata.sessions()]
{'fraction_non_alphanumeric': 0.10332398878654385, 'fraction_numerical': 0.0, 'mean_word_length': 3.1018062397372743, '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': '2611162', 'n_tokens_mistral': 747, 'n_tokens_neox': 713, 'n_words': 172}