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 9 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
16 changes: 15 additions & 1 deletion cl/favorites/api_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rest_framework import serializers
from rest_framework.serializers import ModelSerializer

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


Expand Down Expand Up @@ -37,3 +37,17 @@ 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",
"recap_document",
"status",
)
35 changes: 32 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,27 @@ 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"]

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"],
}
4 changes: 2 additions & 2 deletions cl/favorites/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ async def test_prayers_integration(self) -> None:
email_text_content,
)
self.assertIn(
f"You requested it on {prayer_1.date_created.strftime("%b %d, %Y")}",
f"You requested it on {prayer_1.date_created.strftime("%b %-d, %Y")}",
v-anne marked this conversation as resolved.
Show resolved Hide resolved
email_text_content,
)
self.assertIn(
Expand All @@ -945,7 +945,7 @@ async def test_prayers_integration(self) -> None:
html_content,
)
self.assertIn(
f"You requested it on {prayer_1.date_created.strftime("%b %d, %Y")}",
f"You requested it on {prayer_1.date_created.strftime("%b %-d, %Y")}",
html_content,
)
self.assertIn(
Expand Down
Loading