Skip to content

Commit

Permalink
✨ Add feed (#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsthejoker committed May 18, 2023
1 parent f5c5681 commit 4aa10c2
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
18 changes: 18 additions & 0 deletions blossom/api/migrations/0028_submission_feed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.19 on 2023-05-18 02:48

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("api", "0027_auto_20221004_2042"),
]

operations = [
migrations.AddField(
model_name="submission",
name="feed",
field=models.CharField(blank=True, max_length=50, null=True),
),
]
10 changes: 9 additions & 1 deletion blossom/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ class Meta:
# be run through OCR, this flag should be set.
cannot_ocr = models.BooleanField(default=False)

# For reddit posts, keep the source as "reddit" but put the subreddit here so
# we can search by subreddit.
feed = models.CharField(max_length=50, null=True, blank=True)

def __str__(self) -> str: # pragma: no cover
return f"{self.original_id}"

Expand Down Expand Up @@ -255,8 +259,12 @@ def save(self, *args: Any, skip_extras: bool = False, **kwargs: Any) -> None:
simply "save the object to the db".
"""
super(Submission, self).save(*args, **kwargs)

if not self.feed:
self.feed = self.get_subreddit_name()

if not skip_extras:
if self.is_image and not self.has_ocr_transcription:
if self.is_image and not self.has_ocr_transcription and not self.cannot_ocr:
# TODO: This is a great candidate for a basic queue system
self.generate_ocr_transcription()

Expand Down
1 change: 1 addition & 0 deletions blossom/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Meta:
"cannot_ocr",
"redis_id",
"removed_from_queue",
"feed",
)
# TODO: Omitting the below line while adding `transcription_set` makes
# a call to a single submission created with the test data set take
Expand Down
14 changes: 13 additions & 1 deletion blossom/api/tests/submissions/test_submission_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_list_with_filters(self, client: Client) -> None:
create_submission(source=aaa)
create_submission(source=aaa)
create_submission(source=bbb)
create_submission(source=bbb)
create_submission(source=bbb, feed="ccc")

result = client.get(reverse("submission-list"), content_type="application/json", **headers)

Expand Down Expand Up @@ -96,6 +96,18 @@ def test_list_with_filters(self, client: Client) -> None:
assert "AAA" in result.json()["results"][0]["source"] # it will be a full link
assert result.json()["results"][0]["id"] == 1

result = client.get(
reverse("submission-list") + "?feed=ccc",
content_type="application/json",
**headers,
)

assert result.status_code == status.HTTP_200_OK
assert len(result.json()["results"]) == 1
assert "BBB" in result.json()["results"][0]["source"] # it will be a full link
assert result.json()["results"][0]["feed"] == "ccc"
assert result.json()["results"][0]["id"] == 4

@pytest.mark.parametrize(
"time_query,result_count",
[
Expand Down
2 changes: 1 addition & 1 deletion blossom/api/tests/submissions/test_submission_yeet.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_yeet_with_no_count(self, client: Client) -> None:
assert Submission.objects.count() == 3

def test_yeet_with_no_user(self, client: Client) -> None:
"""Verify that yeeting without a count only deletes one."""
"""Verify that yeeting without a user returns an error."""
client, headers, user = setup_user_client(client)

response = client.post(
Expand Down
1 change: 1 addition & 0 deletions blossom/api/views/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class SubmissionViewSet(viewsets.ModelViewSet):
"content_url": ["exact", "isnull"],
"redis_id": ["exact", "isnull"],
"removed_from_queue": ["exact"],
"feed": ["exact"],
}
ordering_fields = [
"id",
Expand Down

0 comments on commit 4aa10c2

Please sign in to comment.