Skip to content

Commit

Permalink
Merge branch 'main' into 4839-known-big-docs-retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
elisa-a-v authored Jan 9, 2025
2 parents 00eabb5 + 9f67ed6 commit bd3ce86
Show file tree
Hide file tree
Showing 27 changed files with 1,827 additions and 379 deletions.
3 changes: 2 additions & 1 deletion cl/alerts/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2392,7 +2392,7 @@ def test_es_alert_update_and_delete(self, mock_abort_audio):
user=self.user_profile.user,
rate=Alert.REAL_TIME,
name="Test Alert OA",
query="type=oa&docket_number=19-1010",
query="type=oa&docket_number=19-1010&order_by=score desc",
alert_type=SEARCH_TYPES.ORAL_ARGUMENT,
)

Expand All @@ -2402,6 +2402,7 @@ def test_es_alert_update_and_delete(self, mock_abort_audio):
response_str = str(doc.to_dict())
self.assertIn("'query': '19-1010'", response_str)
self.assertIn("'rate': 'rt'", response_str)
self.assertNotIn("function_score", response_str)

# Update Alert
search_alert_1.query = "type=oa&docket_number=19-1020"
Expand Down
8 changes: 7 additions & 1 deletion cl/alerts/tests/tests_recap_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2221,13 +2221,19 @@ def test_index_and_delete_recap_alerts_from_percolator(
user=self.user_profile.user,
rate=Alert.WEEKLY,
name="Test Alert Docket Only",
query='q="401 Civil"&type=r',
query='q="401 Civil"&type=r&order_by=score desc',
alert_type=SEARCH_TYPES.RECAP,
)
self.assertTrue(
RECAPPercolator.exists(id=docket_only_alert.pk),
msg=f"Alert id: {docket_only_alert.pk} was not indexed.",
)
alert_doc = RECAPPercolator.get(id=docket_only_alert.pk)
response_str = str(alert_doc.to_dict())
self.assertIn("401 Civil", response_str)
self.assertIn("'rate': 'wly'", response_str)
# function_score breaks percolator queries. Ensure it is never indexed.
self.assertNotIn("function_score", response_str)

docket_only_alert_id = docket_only_alert.pk
# Remove the alert.
Expand Down
2 changes: 1 addition & 1 deletion cl/favorites/api_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def validate(self, data):
)

# Check if the user is eligible to create a new prayer
if not async_to_sync(prayer_eligible)(user):
if not async_to_sync(prayer_eligible)(user)[0]:
raise ValidationError(
f"You have reached the maximum number of prayers ({settings.ALLOWED_PRAYER_COUNT}) allowed in the last 24 hours."
)
Expand Down
20 changes: 8 additions & 12 deletions cl/favorites/templates/top_prayers.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,21 @@
{% load pacer %}
{% load humanize %}

{% block title %}RECAP Requests – CourtListener.com{% endblock %}
{% block og_title %}RECAP Requests – CourtListener.com{% endblock %}

{% block description %}RECAP Requests on CourtListener.{% endblock %}
{% block og_description %}RECAP Requests on CourtListener.{% endblock %}
{% block title %}Most Wanted PACER Documents — CourtListener.com{% endblock %}
{% block og_title %}Most Wanted PACER Documents — CourtListener.com{% endblock %}

{% block description %}CourtListener lets you request the purchase of legal documents. View the community's most wanted documents.{% endblock %}
{% block og_description %}CourtListener lets you request the purchase of legal documents. View the community's most wanted documents.{% endblock %}

{% block content %}
<div class="col-xs-12">
<h1 class="text-center">Community's Most Requested Documents</h1>
<h1 class="text-center v-offset-below-3">Community's Most Wanted PACER Documents</h1>
<h3 class="text-center"><b>{{ granted_stats.prayer_count|intcomma }}</b> prayers granted totaling <b>${{ granted_stats.total_cost }}</b>.</h3>
<h3 class="text-center"><b>{{ waiting_stats.prayer_count|intcomma }}</b> prayers pending totaling at least <b>${{ waiting_stats.total_cost }}</b>.</h3>
</div>


<div class="col-xs-12">
<div class="well well-sm">
<p>There have been <b>{{ granted_stats.prayer_count|intcomma }}</b> requests granted for <b>{{ granted_stats.distinct_count|intcomma }}</b> unique documents that cost <b>${{ granted_stats.total_cost }}</b>.</p>
<br>
<p>There are <b>{{ waiting_stats.prayer_count|intcomma }}</b> requests pending for <b>{{ waiting_stats.distinct_count|intcomma }}</b> unique documents that cost at least <b>${{ waiting_stats.total_cost }}</b>.</p>
<br>
<p>{% if user.is_authenticated %}
<a href="{% url 'user_prayers' user.username %}">View your prayers</a>
{% else %}
Expand Down Expand Up @@ -55,7 +51,7 @@ <h1 class="text-center">Community's Most Requested Documents</h1>
</a>
</td>
<td>
<a href="{% url "view_docket" docket.pk docket.slug %}#entry-{{ prayer.docket_entry.entry_number }}">
<a href="{% url "view_recap_document" docket.pk prayer.docket_entry.entry_number docket.slug %}">
{{ prayer.document_number }}
</a>
</td>
Expand Down
23 changes: 7 additions & 16 deletions cl/favorites/templates/user_prayers.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
{% load tz %}
{% load humanize %}

{% block title %}{% if is_page_owner %}Your RECAP Requests {% else %}RECAP Requests for: {{ requested_user }}{% endif %} – CourtListener.com{% endblock %}
{% block og_title %}{% if is_page_owner %}Your RECAP Requests {% else %}RECAP Requests for: {{ requested_user }}{% endif %} – CourtListener.com{% endblock %}
{% block description %}CourtListener lets you request purchase of legal documents. View the document requests for {{ requested_user }}.{% endblock %}
{% block og_description %}CourtListener lets you request purchase of legal documents. View the document requests for {{ requested_user }}.{% endblock %}
{% block title %}{% if is_page_owner %}Your PACER document Prayers{% else %}PACER Document Requests for: {{ requested_user }}{% endif %} – CourtListener.com{% endblock %}
{% block og_title %}{% if is_page_owner %}Your PACER document Prayers{% else %}PACER Document Requests for: {{ requested_user }}{% endif %} – CourtListener.com{% endblock %}
{% block description %}CourtListener lets you request the purchase of legal documents. View the documents requested by {{ requested_user }}.{% endblock %}
{% block og_description %}CourtListener lets you request the purchase of legal documents. View the documents requested by {{ requested_user }}.{% endblock %}

{% block content %}
<div class="col-xs-12">
<h1 class="text-center">{% if is_page_owner %}Your RECAP Requests {% else %}RECAP Requests for: {{ requested_user }}{% endif %}</h1>
<h1 class="text-center v-offset-below-3">{% if is_page_owner %}Your PACER Document Prayers{% else %}PACER Document Requests for: {{ requested_user }}{% endif %}</h1>
{% if is_page_owner %}<h3 class="text-center"><b>{{ count|intcomma }}</b> prayers granted totaling <b>${{total_cost|floatformat:2 }}</b> (<b>{{ num_remaining }}</b> remaining today).</h3>{% endif %}
</div>

<div class="col-xs-12" id="prayer_summary" hx-swap-oob="true"
Expand All @@ -22,16 +23,6 @@ <h1 class="text-center">{% if is_page_owner %}Your RECAP Requests {% else %}RECA
hx-trigger="prayersListChanged from:body" hx-swap="none"
{%endif %}
>
<div class="well well-sm">
{% if is_page_owner %}
<p>
You have had <b>{{ count|intcomma }}</b> requests fulfilled for documents that cost <b>${{total_cost|floatformat:2 }}</b>.
</p>
<p>
{% if is_eligible %}You are eligible to make document requests.{% else %}You have reached your daily limit; wait 24 hours to make new requests.{% endif %}
</p>
{% endif %}
</div>
</div>

<div class="col-xs-12" id="prayer_list" hx-swap-oob="true">
Expand Down Expand Up @@ -59,7 +50,7 @@ <h1 class="text-center">{% if is_page_owner %}Your RECAP Requests {% else %}RECA
</a>
</td>
<td>
<a href="{% url "view_docket" docket.pk docket.slug %}#entry-{{ rd.docket_entry.entry_number }}">
<a href="{% url "view_recap_document" docket.pk rd.docket_entry.entry_number docket.slug %}">
{{ rd.document_number }}
</a>
</td>
Expand Down
8 changes: 4 additions & 4 deletions cl/favorites/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ async def test_prayer_eligible(self) -> None:
current_time = now()
with time_machine.travel(current_time, tick=False):
# No user prayers in the last 24 hours yet for this user.
user_is_eligible = await prayer_eligible(self.user)
user_is_eligible, _ = await prayer_eligible(self.user)
self.assertTrue(user_is_eligible)

# Add prays for this user.
Expand All @@ -709,7 +709,7 @@ async def test_prayer_eligible(self) -> None:

user_prays = Prayer.objects.filter(user=self.user)
self.assertEqual(await user_prays.acount(), 1)
user_is_eligible = await prayer_eligible(self.user)
user_is_eligible, _ = await prayer_eligible(self.user)
self.assertTrue(user_is_eligible)

await sync_to_async(PrayerFactory)(
Expand All @@ -719,7 +719,7 @@ async def test_prayer_eligible(self) -> None:

# After two prays (ALLOWED_PRAYER_COUNT) in the last 24 hours.
# The user is no longer eligible to create more prays
user_is_eligible = await prayer_eligible(self.user)
user_is_eligible, _ = await prayer_eligible(self.user)
self.assertFalse(user_is_eligible)

with time_machine.travel(
Expand All @@ -730,7 +730,7 @@ async def test_prayer_eligible(self) -> None:
user=self.user, recap_document=self.rd_3
)
self.assertEqual(await user_prays.acount(), 3)
user_is_eligible = await prayer_eligible(self.user)
user_is_eligible, _ = await prayer_eligible(self.user)
self.assertTrue(user_is_eligible)

async def test_create_prayer(self) -> None:
Expand Down
10 changes: 6 additions & 4 deletions cl/favorites/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from cl.search.models import RECAPDocument


async def prayer_eligible(user: User) -> bool:
async def prayer_eligible(user: User) -> tuple[bool, int]:
allowed_prayer_count = settings.ALLOWED_PRAYER_COUNT

now = timezone.now()
Expand All @@ -39,13 +39,15 @@ async def prayer_eligible(user: User) -> bool:
user=user, date_created__gte=last_24_hours
).acount()

return prayer_count < allowed_prayer_count
return prayer_count < allowed_prayer_count, (
allowed_prayer_count - prayer_count
)


async def create_prayer(
user: User, recap_document: RECAPDocument
) -> Prayer | None:
if await prayer_eligible(user) and not recap_document.is_available:
if (await prayer_eligible(user))[0] and not recap_document.is_available:
new_prayer, created = await Prayer.objects.aget_or_create(
user=user, recap_document=recap_document
)
Expand Down Expand Up @@ -200,7 +202,7 @@ async def get_user_prayers(user: User) -> QuerySet[RECAPDocument]:
prayer_status=F("prayers__status"),
prayer_date_created=F("prayers__date_created"),
)
.order_by("prayers__date_created")
.order_by("-prayers__date_created")
)

return documents
Expand Down
5 changes: 3 additions & 2 deletions cl/favorites/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ async def create_prayer_view(
user = request.user
is_htmx_request = request.META.get("HTTP_HX_REQUEST", False)
regular_size = bool(request.POST.get("regular_size"))
if not await prayer_eligible(request.user):
if not (await prayer_eligible(request.user))[0]:
if is_htmx_request:
return TemplateResponse(
request,
Expand Down Expand Up @@ -291,7 +291,7 @@ async def user_prayers_view(

count, total_cost = await get_user_prayer_history(requested_user)

is_eligible = await prayer_eligible(requested_user)
is_eligible, num_remaining = await prayer_eligible(requested_user)

context = {
"rd_with_prayers": rd_with_prayers,
Expand All @@ -300,6 +300,7 @@ async def user_prayers_view(
"count": count,
"total_cost": total_cost,
"is_eligible": is_eligible,
"num_remaining": num_remaining,
"private": False,
}

Expand Down
Loading

0 comments on commit bd3ce86

Please sign in to comment.