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

4507 pray and pay api #4519

Merged
merged 96 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
43d37e3
beginning work on API
v-anne Oct 1, 2024
f9bb77f
Merge branch 'freelawproject:main' into 4507-pray-and-pay-API
v-anne Oct 1, 2024
6677f72
PrayerSerializer
v-anne Oct 1, 2024
611b137
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 1, 2024
18498f6
filters
v-anne Oct 1, 2024
114bbf9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 1, 2024
ea76f6c
views
v-anne Oct 1, 2024
2707ebd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 1, 2024
4586a36
fixing email test (single-digit dates don't have zero padding in the …
v-anne Oct 1, 2024
df4677d
Merge branch 'main' into 4507-pray-and-pay-API
v-anne Oct 1, 2024
c687c40
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 1, 2024
a31bcce
route
v-anne Oct 1, 2024
ad42a89
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 1, 2024
f32cfd5
adding link to open document requests to base.html
v-anne Oct 1, 2024
b2f276b
function to get how many open requests for a given document
v-anne Oct 3, 2024
0fb956e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 3, 2024
8bba545
function to check if user can request a given document
v-anne Oct 3, 2024
d676ede
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 3, 2024
c64db71
Merge branch 'main' into 4507-pray-and-pay-API
v-anne Oct 3, 2024
20f1ec6
showing how many open prayers on docket entry page
v-anne Oct 4, 2024
0268314
Merge branch '4507-pray-and-pay-API' of https://github.com/v-anne/cou…
v-anne Oct 4, 2024
1b1975c
adding prayer count to docket entry
v-anne Oct 4, 2024
027edbf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2024
7920547
url
v-anne Oct 4, 2024
725b3e9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2024
d40f026
rough work on html
v-anne Oct 4, 2024
04ea765
Merge branch '4507-pray-and-pay-API' of https://github.com/v-anne/cou…
v-anne Oct 4, 2024
703d6e7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2024
cac6281
Merge branch 'main' into 4507-pray-and-pay-API
v-anne Oct 4, 2024
3a32ebc
grouping similar functions together
v-anne Oct 6, 2024
c1e7b9f
commenting out problematic function
v-anne Oct 6, 2024
98b0ac2
comment out dead url path
v-anne Oct 6, 2024
2aabc99
fix
v-anne Oct 6, 2024
4291b1b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2024
e96d146
grouping common functions together
v-anne Oct 8, 2024
479aef5
adding checks for whether user can request a particular document
v-anne Oct 8, 2024
8423892
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 8, 2024
2e22f81
Merge branch 'main' into 4507-pray-and-pay-API
v-anne Oct 8, 2024
120ebad
this all seems to work. I'm not 100% happy with how it's written, but…
v-anne Oct 8, 2024
a0c9511
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 8, 2024
8edfc78
Update .env.example
v-anne Oct 8, 2024
2e2840d
adding document cost to wishlist
v-anne Oct 8, 2024
09e33b5
Merge branch 'main' into 4507-pray-and-pay-API
v-anne Oct 8, 2024
a382d10
Merge branch 'main' into 4507-pray-and-pay-API
v-anne Oct 8, 2024
f78d20f
Merge branch 'main' into 4507-pray-and-pay-API
v-anne Oct 9, 2024
385a943
fix(favorites): Improved prayers frontend query performance and added…
albertisfu Oct 9, 2024
e4ebf01
fix(favorites): Linked pray button to modal-logged-out
albertisfu Oct 9, 2024
47ee93f
delete prayer function
v-anne Oct 10, 2024
e005d82
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2024
f806fb3
waffle flag "pray-and-pay"
v-anne Oct 10, 2024
f617d85
work on frontend
v-anne Oct 10, 2024
d7c4235
Merge branch 'main' into 4507-pray-and-pay-API
v-anne Oct 10, 2024
41456c7
view and url to delete prayer
v-anne Oct 10, 2024
3da0aaa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2024
8cca389
fixing delete function
v-anne Oct 10, 2024
683ccca
Merge branch '4507-pray-and-pay-API' of https://github.com/v-anne/cou…
v-anne Oct 10, 2024
8b07b73
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2024
6fd59d1
small changes to comments
v-anne Oct 10, 2024
29c3ad4
fix(favorites): Fixed indentation after the pray-and-pay flag in the …
albertisfu Oct 10, 2024
f0501b9
allowing users to see how many requests have been fulfilled over the …
v-anne Oct 10, 2024
ff3eac0
Merge branch '4507-pray-and-pay-API' of https://github.com/v-anne/cou…
v-anne Oct 10, 2024
f28678b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2024
531166b
Update utils.py
v-anne Oct 10, 2024
28e541c
Merge branch 'main' into 4507-pray-and-pay-API
albertisfu Oct 10, 2024
3407ba9
Merge branch 'main' into 4507-pray-and-pay-API
albertisfu Oct 10, 2024
ef4b21c
adding tests and adjusting logic of delete_prayer() function
v-anne Oct 10, 2024
e959b83
Update tests.py
v-anne Oct 10, 2024
ba2ce3c
Update tests.py
v-anne Oct 10, 2024
fd5fb34
Update tests.py
v-anne Oct 10, 2024
44ff65c
Merge branch 'main' into 4507-pray-and-pay-API
v-anne Oct 10, 2024
d67e306
Merge branch 'main' into 4507-pray-and-pay-API
v-anne Oct 11, 2024
d21ecc0
Update tests.py
v-anne Oct 11, 2024
0132a43
new func
v-anne Oct 11, 2024
841c521
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 11, 2024
19b9306
fixing buggy functions
v-anne Oct 11, 2024
be928aa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 11, 2024
6f41aab
Merge branch 'main' into 4507-pray-and-pay-API
v-anne Oct 12, 2024
9d294ef
Merge branch 'main' into 4507-pray-and-pay-API
ERosendo Oct 14, 2024
c958ce5
removing unused imports
v-anne Oct 14, 2024
3776784
adding waffle flag to base.html
v-anne Oct 14, 2024
267d5db
deleting commented out summary statistics
v-anne Oct 14, 2024
fa181a9
changing private to False
v-anne Oct 14, 2024
6348424
removing import of unused function
v-anne Oct 14, 2024
1edb1a0
Merge branch 'main' into 4507-pray-and-pay-API
v-anne Oct 14, 2024
0d0f2bd
Merge branch 'main' into 4507-pray-and-pay-API
ERosendo Oct 15, 2024
7b217a8
feat(docket): Remove inline styles from pray button
ERosendo Oct 14, 2024
69494da
refactor(docket): Extract pray button HTML into reusable fragment
ERosendo Oct 14, 2024
09a9dd7
feat(docket): Integrate HTMX to the docket page
ERosendo Oct 14, 2024
e99e61b
feat(pray button): Adds HTMX functionality to the pray button
ERosendo Oct 14, 2024
7d479d5
eat(pray_button): Add visual indicator for requested docs
ERosendo Oct 15, 2024
bc05db4
feat(pray button): Enhance user experience with instant feedback
ERosendo Oct 15, 2024
ee9db29
feat(favorite): Tweaks prayer views to support HTMX interactions
ERosendo Oct 15, 2024
79c4d14
refactor(favorites): Remove unused variables from open_prayers view
ERosendo Oct 15, 2024
d6ae2a4
Merge branch 'main' into 4507-pray-and-pay-API
v-anne Oct 15, 2024
ed6ae38
feat(docket): Check prayers flag before computing counts
ERosendo Oct 15, 2024
11971ab
feat(prayers): Implement daily limit tooltip
ERosendo Oct 15, 2024
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
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ IA_ACCESS_KEY=""
IA_SECRET_KEY=""

FTM_KEY=""

# CL API key for cloning data
CL_API_KEY=""
3 changes: 3 additions & 0 deletions cl/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
r"docket-tags", favorite_views.DocketTagViewSet, basename="DocketTag"
)

# Prayers
router.register(r"prayers", favorite_views.PrayerViewSet, basename="prayer")

# Visualizations
router.register(
r"visualizations/json", viz_views.JSONViewSet, basename="jsonversion"
Expand Down
8 changes: 8 additions & 0 deletions cl/assets/static-global/css/override.css
Original file line number Diff line number Diff line change
Expand Up @@ -1723,3 +1723,11 @@ rect.series-segment {
opacity 150ms 150ms ease-in;
transform: translate3d(0, 0, 0);
}

.prayer-button[data-gap-size="small"] {
margin-left: 8px;
}

.prayer-button[data-gap-size="large"]{
margin-left: 44px;
}
13 changes: 9 additions & 4 deletions cl/assets/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,22 @@ <h1>You did not supply the "private" variable to your template.
<li>
<a href="https://free.law/recap/" tabindex="202">Install RECAP</a>
</li>
{% flag "pray-and-pay" %}
<li>
<a href="{% url "top_prayers" %}#recap-alerts" tabindex="203">Pray and Pay Project</a>
</li>
{% endflag %}
<li>
<a href="{% url "alert_help" %}#recap-alerts" tabindex="203">Get Case Alerts</a>
<a href="{% url "alert_help" %}#recap-alerts" tabindex="204">Get Case Alerts</a>
</li>
<li>
<a href="{% url "coverage_recap" %}" tabindex="204">About this Collection</a>
<a href="{% url "coverage_recap" %}" tabindex="205">About this Collection</a>
</li>
<li>
<a href="https://free.law/data-consulting/" tabindex="205">Bulk Data Service</a>
<a href="https://free.law/data-consulting/" tabindex="206">Bulk Data Service</a>
</li>
<li>
<a href="{% url "pacer_api_help" %}" tabindex="206">API</a>
<a href="{% url "pacer_api_help" %}" tabindex="207">API</a>
</li>
</ul>
</li>
Expand Down
37 changes: 36 additions & 1 deletion cl/favorites/api_serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from asgiref.sync import async_to_sync
from django.conf import settings
from drf_dynamic_fields import DynamicFieldsMixin
from rest_framework import serializers
from rest_framework.exceptions import ValidationError
from rest_framework.serializers import ModelSerializer

from cl.favorites.models import DocketTag, UserTag
from cl.favorites.models import DocketTag, Prayer, UserTag
from cl.favorites.utils import prayer_eligible
from cl.search.models import Docket


Expand Down Expand Up @@ -37,3 +41,34 @@ class DocketTagSerializer(DynamicFieldsMixin, ModelSerializer):
class Meta:
model = DocketTag
fields = "__all__"


class PrayerSerializer(DynamicFieldsMixin, serializers.ModelSerializer):
user = serializers.HiddenField(default=serializers.CurrentUserDefault())

class Meta:
model = Prayer
fields = "__all__"
read_only_fields = (
"date_created",
"user",
)

def validate(self, data):
user = self.context["request"].user
recap_document = data.get("recap_document")

# Check if a Prayer for the same user and recap_document already exists
if Prayer.objects.filter(
user=user, recap_document=recap_document
).exists():
raise ValidationError(
"A prayer for this recap document already exists."
)

# Check if the user is eligible to create a new prayer
if not async_to_sync(prayer_eligible)(user):
raise ValidationError(
f"You have reached the maximum number of prayers ({settings.ALLOWED_PRAYER_COUNT}) allowed in the last 24 hours."
)
return data
37 changes: 34 additions & 3 deletions cl/favorites/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
from rest_framework.viewsets import ModelViewSet

from cl.api.pagination import MediumAdjustablePagination
from cl.api.utils import LoggingMixin
from cl.favorites.api_permissions import IsTagOwner
from cl.favorites.api_serializers import DocketTagSerializer, UserTagSerializer
from cl.favorites.filters import DocketTagFilter, UserTagFilter
from cl.favorites.models import DocketTag, UserTag
from cl.favorites.api_serializers import (
DocketTagSerializer,
PrayerSerializer,
UserTagSerializer,
)
from cl.favorites.filters import DocketTagFilter, PrayerFilter, UserTagFilter
from cl.favorites.models import DocketTag, Prayer, UserTag


class UserTagViewSet(ModelViewSet):
Expand Down Expand Up @@ -51,3 +56,29 @@ def get_queryset(self):
return DocketTag.objects.filter(
Q(tag__user=self.request.user) | Q(tag__published=True)
)


class PrayerViewSet(LoggingMixin, ModelViewSet):
"""A ModelViewset to handle CRUD operations for Prayer."""

permission_classes = [IsAuthenticated]
serializer_class = PrayerSerializer
pagination_class = MediumAdjustablePagination
filterset_class = PrayerFilter
ordering_fields = ("date_created",)
# Default cursor ordering key
ordering = "-date_created"
# Additional cursor ordering fields
cursor_ordering_fields = ["date_created"]
# Only allow these methods. Restricting PUT and PATCH.
http_method_names = ["get", "post", "delete", "head", "options"]
v-anne marked this conversation as resolved.
Show resolved Hide resolved

def get_queryset(self):
"""
Return a list of all the open prayers
for the currently authenticated user.
"""
user = self.request.user
return Prayer.objects.filter(
user=user, status=Prayer.WAITING
).order_by("-date_created")
18 changes: 17 additions & 1 deletion cl/favorites/filters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import rest_framework_filters as filters

from cl.api.utils import BASIC_TEXT_LOOKUPS, BOOLEAN_LOOKUPS, NoEmptyFilterSet
from cl.favorites.models import DocketTag, UserTag
from cl.favorites.models import DocketTag, Prayer, UserTag


class UserTagFilter(NoEmptyFilterSet):
Expand All @@ -21,3 +21,19 @@ class DocketTagFilter(NoEmptyFilterSet):
class Meta:
model = DocketTag
fields = {"id": ["exact"], "docket": ["exact"]}


class PrayerFilter(NoEmptyFilterSet):
date_created = filters.DateFromToRangeFilter(
field_name="date_created",
help_text="Filter prayers by a date range (e.g., ?date_created_after=2024-09-01&date_created_before=2024-12-31).",
)

class Meta:
model = Prayer
fields = {
"date_created": ["exact", "range"],
"user": ["exact"],
"recap_document": ["exact"],
"status": ["exact", "in"],
}
24 changes: 21 additions & 3 deletions cl/favorites/templates/top_prayers.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
{% load extras %}
{% load text_filters %}
{% load static %}

{% load pacer %}

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

{% block description %}Lorem Ipsum on CourtListener.{% endblock %}
{% block og_description %}Lorem Ipsum on CourtListener.{% endblock %}
{% block description %}RECAP Requests on CourtListener.{% endblock %}
{% block og_description %}RECAP Requests on CourtListener.{% endblock %}


{% block content %}

<div class="col-xs-12">
<div class="table-responsive">
<table class="settings-table table">
Expand All @@ -21,6 +23,7 @@
<th>Document Number</th>
<th>PACER Doc ID</th>
<th>Document Court</th>
<th>Buy on Pacer</th>
</tr>
</thead>
<tbody>
Expand All @@ -31,6 +34,15 @@
<td>{{ prayer.document_number }}</td>
<td>{{ prayer.pacer_doc_id }}</td>
<td>{{ prayer.docket_entry.docket.court_id }}</td>
<td><a href="{{ prayer.pacer_url }}"
{% if not request.COOKIES.buy_on_pacer_modal and not request.COOKIES.recap_install_plea %}
class="open_buy_pacer_modal btn btn-default btn-xs"
data-toggle="modal" data-target="#modal-buy-pacer"
{% else%}
class="btn btn-default btn-xs"
{% endif %}
target="_blank"
rel="nofollow">Buy on PACER {% if prayer.page_count %}(${{ prayer|price }}){% endif %}</td>
</tr>
{% empty %}
<tr>
Expand All @@ -42,3 +54,9 @@
</div>
</div>
{% endblock %}

{% block footer-scripts %}
<script defer type="text/javascript"
src="{% static "js/buy_pacer_modal.js" %}"></script>
{% include "includes/buy_pacer_modal.html" %}
{% endblock %}
Loading
Loading