Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bill_text template #399

Merged
merged 6 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions chicago/management/commands/preview_search_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.core.management.base import BaseCommand
from chicago.models import ChicagoBill
from chicago.search_indexes import BillIndex
import pprint


class Command(BaseCommand):
"""A simple management command which clears the site-wide cache."""

help = "Preview the text template that will be used in the search."

def add_arguments(self, parser):
parser.add_argument(
"identifier",
help=("The identifier of the bill to preview"),
)

def handle(self, *args, **kwargs):

b = ChicagoBill.objects.get(identifier=kwargs["identifier"])

self.stdout.write(pprint.pformat(BillIndex().prepare(b), indent=4))
12 changes: 3 additions & 9 deletions chicago/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,15 @@ class BillIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(
document=True,
use_template=True,
template_name="search/indexes/councilmatic_core/bill_text.txt",
template_name="search/bill_text.txt",
)
slug = indexes.CharField(model_attr="slug", indexed=False)
id = indexes.CharField(model_attr="id", indexed=False)
bill_type = indexes.CharField(faceted=True)
identifier = indexes.CharField(model_attr="identifier")
description = indexes.CharField(model_attr="title", boost=1.25)
title = indexes.CharField(model_attr="title", boost=1.25)
source_url = indexes.CharField(model_attr="sources__url", indexed=False)
source_note = indexes.CharField(model_attr="sources__note")
abstract = indexes.CharField(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is always empty for chicago.

model_attr="abstracts__abstract", boost=1.25, default=""
)

friendly_name = indexes.CharField()
sort_name = indexes.CharField(faceted=True)
Expand All @@ -38,7 +35,7 @@ class BillIndex(indexes.SearchIndex, indexes.Indexable):
last_action_date = indexes.DateTimeField()
inferred_status = indexes.CharField(faceted=True)
legislative_session = indexes.CharField(faceted=True)
topics = indexes.MultiValueField(faceted=True)
topics = indexes.MultiValueField(model_attr="topics", faceted=True)

def get_model(self):
return ChicagoBill
Expand All @@ -60,9 +57,6 @@ def prepare(self, obj):

return data

def prepare_topics(self, obj):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can get it more directly with model_attr

return obj.topics

def prepare_last_action_date(self, obj):
if not obj.last_action_date:
action_dates = [a.date for a in obj.actions.all()]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{% load extras %}
{{ object.identifier | alternative_identifiers }}
{{ object.friendly_name }}
{{ object.classification }}
{{ object.description }}
{{ object.abstract }}
{% for identifier in object.other_identifiers.all %}
{{ identifier.identifier }}
{% endfor %}
{% for classification in object.classification %}
{{ classification }}
{% endfor %}
{{ object.title }}
{% for s in object.sponsorships.all %}
{% if s.primary %}
{{ s.person.name }}
Expand All @@ -16,4 +19,4 @@
{% for t in object.topics %}
{{t}}
{% endfor %}
{{ object.ocr_full_text|clean_html }}
{{ object.ocr_full_text }}
9 changes: 0 additions & 9 deletions chicago/templatetags/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,6 @@ def clean_html(text):
return re.sub(r"&(?:\w+|#\d+);", "", value)


@register.filter
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this filter was only used in bill_text.txt and we aren't using it anymore.

@stringfilter
def alternative_identifiers(id_original):
id_1 = re.sub(" ", " 0", id_original)
id_2 = re.sub(" ", "", id_original)
id_3 = re.sub(" ", "", id_1)
return " ".join(i for i in set([id_original, id_1, id_2, id_3]))


@register.filter
def get_item(dictionary, key):
return dictionary.get(key)
Expand Down