Ejemplo n.º 1
0
    def as_display_dict(self, court_count_human):
        """Generate a displayable dictionary of the search form

        This can be useful for displaying on the front end, or converting into
        a useful string. The dictionary looks like:

            {
              'Case name': 'Foo',
              'Query': 'bar',
            }

        :param court_count_human: The number of courts being queried or "All",
        if all courts are being queried.
        :returns A dictionary of the data
        """
        display_dict = OrderedDict({"Courts": court_count_human})
        search_type = self.data["type"]
        for field_name, field in self.fields.items():
            if not hasattr(field, "as_str_types"):
                continue
            if search_type in field.as_str_types:
                value = self.cleaned_data.get(field_name)
                if value:
                    if isinstance(field, ChoiceField):
                        choices = flatten_choices(self.fields[field_name])
                        value = dict(choices)[value]
                    display_dict[field.label] = value

        return display_dict
Ejemplo n.º 2
0
    def as_display_dict(self, court_count_human):
        """Generate a displayable dictionary of the search form

        This can be useful for displaying on the front end, or converting into
        a useful string. The dictionary looks like:

            {
              'Case name': 'Foo',
              'Query': 'bar',
            }

        :param court_count_human: The number of courts being queried or "All",
        if all courts are being queried.
        :returns A dictionary of the data
        """
        # The search type is usually provided by cleaned data, but can be
        # missing when the form is invalid (and lacks it). If so, just give up.
        try:
            search_type = self.data["type"]
        except MultiValueDictKeyError:
            return {}
        display_dict = OrderedDict({"Courts": court_count_human})
        for field_name, field in self.fields.items():
            if not hasattr(field, "as_str_types"):
                continue
            if search_type in field.as_str_types:
                value = self.cleaned_data.get(field_name)
                if value:
                    if isinstance(field, ChoiceField):
                        choices = flatten_choices(self.fields[field_name])
                        value = dict(choices)[value]
                    display_dict[field.label] = value

        return display_dict
Ejemplo n.º 3
0
    def as_text(self, court_count, court_count_human):
        crumbs = []
        search_type = self.data['type']
        for field_name, field in self.base_fields.items():
            if not hasattr(field, 'as_str_types'):
                continue
            if search_type in field.as_str_types:
                value = self.cleaned_data.get(field_name)
                if value:
                    if isinstance(field, ChoiceField):
                        choices = flatten_choices(self.fields[field_name])
                        value = dict(choices)[value]
                    crumbs.append('%s: %s' % (field.label, value))

        if court_count_human != "All":
            pluralize = "s" if court_count > 1 else ""
            crumbs.append("%s Court%s" % (court_count, pluralize))
        return u" › ".join(crumbs)
Ejemplo n.º 4
0
    def as_text(self, court_count, court_count_human):
        crumbs = []
        search_type = self.data['type']
        for field_name, field in self.base_fields.items():
            if not hasattr(field, 'as_str_types'):
                continue
            if search_type in field.as_str_types:
                value = self.cleaned_data.get(field_name)
                if value:
                    if isinstance(field, ChoiceField):
                        choices = flatten_choices(self.fields[field_name])
                        value = dict(choices)[value]
                    crumbs.append('%s: %s' % (field.label, value))

        if court_count_human != "All":
            pluralize = "s" if court_count > 1 else ""
            crumbs.append("%s Court%s" % (court_count, pluralize))
        return u" › ".join(crumbs)