-
-
Notifications
You must be signed in to change notification settings - Fork 280
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
Topic landing tod #2137
Merged
Merged
Topic landing tod #2137
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
97f3466
test(topics): add test for topic of the day
nsantacruz c22abe4
feat(topics): add topic of the day api
nsantacruz f6e6959
chore(topics): remove unnecessary django setup now that we have pytes…
nsantacruz b7bea0c
chore(topics): add pytest django as a dependency
nsantacruz 2b39b16
chore(topics): add topic of the day function in Sefaria to call corre…
nsantacruz 9219d5c
feat(topics): basic topic of the day rendering
nsantacruz 347167a
feat(topics): add ImageWithAltText
nsantacruz d7f8846
feat(topics): topic of the day frontend WIP
nsantacruz 633c801
fix(topics): change text transform
nsantacruz c786ba1
Merge branch 'topic-landing' into topic-landing-tod
nsantacruz c4474f3
chore(topics): merge
nsantacruz 12f0223
feat(topics): polish topic of the day (to be known henceforth as feat…
nsantacruz 914c9bf
refactor(topics): only fetch topic of the day on first render
nsantacruz 513d286
chore(topics): merge
nsantacruz e77010b
refactor(topics): rename all mentions of TopicOfTheDay to FeaturedTopic
nsantacruz 611716c
chore(topics): merge master
nsantacruz dd60de1
fix(topics): fix forked migration
nsantacruz 9478479
chore(topics): leave TopicOfTheDay model name as is to avoid issues w…
nsantacruz dfc2486
chore(topics): merge
nsantacruz bf793a7
chore(topics): merge
nsantacruz f18e75b
chore(topics): upgrade pytest to match pytest-django
nsantacruz 74357c2
fix(topics): use secondary image
nsantacruz 2b574ee
fix(topics): use secondary image
nsantacruz d2538a4
fix(topics): fix styling
nsantacruz 1904663
fix(topic): make featured topic image correct aspect ratio on chrome
nsantacruz b49ecc3
fix(topic): handle case where there is no image
nsantacruz 5a04fc8
chore(topic): merge
nsantacruz ab054c8
chore(topic): remove unused callback parameter
nsantacruz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.29 on 2024-12-17 11:02 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('django_topics', '0007_auto_20241127_0034'), | ||
] | ||
|
||
operations = [ | ||
migrations.DeleteModel( | ||
name='TopicOfTheDayEnglish', | ||
), | ||
migrations.DeleteModel( | ||
name='TopicOfTheDayHebrew', | ||
), | ||
migrations.CreateModel( | ||
name='FeaturedTopicEnglish', | ||
fields=[ | ||
], | ||
options={ | ||
'verbose_name': 'Landing Page - Featured Topic (EN)', | ||
'verbose_name_plural': 'Landing Page - Featured Topic (EN)', | ||
'proxy': True, | ||
'indexes': [], | ||
}, | ||
bases=('django_topics.topicoftheday',), | ||
), | ||
migrations.CreateModel( | ||
name='FeaturedTopicHebrew', | ||
fields=[ | ||
], | ||
options={ | ||
'verbose_name': 'Landing Page - Featured Topic (HE)', | ||
'verbose_name_plural': 'Landing Page - Featured Topic (HE)', | ||
'proxy': True, | ||
'indexes': [], | ||
}, | ||
bases=('django_topics.topicoftheday',), | ||
), | ||
migrations.AlterModelOptions( | ||
name='topicoftheday', | ||
options={'verbose_name': 'Landing Page - Featured Topic', 'verbose_name_plural': 'Landing Page - Featured Topic'}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .topic import Topic | ||
from .pool import TopicPool, PoolType | ||
from .topic_of_the_day import TopicOfTheDay, TopicOfTheDayEnglish, TopicOfTheDayHebrew | ||
from .featured_topic import TopicOfTheDay, FeaturedTopicEnglish, FeaturedTopicHebrew | ||
from .seasonal_topic import SeasonalTopic, SeasonalTopicEnglish, SeasonalTopicHebrew |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from django.db import models | ||
from datetime import datetime | ||
from django.utils.timezone import now | ||
from django_topics.models import Topic | ||
|
||
|
||
class FeaturedTopicManager(models.Manager): | ||
|
||
def get_featured_topic(self, lang: str, date: datetime = None) -> 'TopicOfTheDay': | ||
""" | ||
Return featured topic for given date or closest date that is less than or equal to given date | ||
@param lang: language code, "en" or "he" | ||
@param date: datetime object | ||
@return: | ||
""" | ||
date = date or now().date() | ||
return ( | ||
self.filter(start_date__lte=date, lang=lang) | ||
.order_by('-start_date') | ||
.first() | ||
) | ||
|
||
|
||
class TopicOfTheDay(models.Model): | ||
topic = models.ForeignKey( | ||
Topic, | ||
on_delete=models.CASCADE, | ||
related_name='topic_of_the_day' | ||
) | ||
start_date = models.DateField() | ||
lang = models.CharField(max_length=2, choices=[('en', 'English'), ('he', 'Hebrew')]) | ||
objects = FeaturedTopicManager() | ||
|
||
class Meta: | ||
unique_together = ('topic', 'start_date') | ||
verbose_name = "Landing Page - Featured Topic" | ||
verbose_name_plural = "Landing Page - Featured Topic" | ||
|
||
def __str__(self): | ||
return f"{self.topic.slug} ({self.start_date})" | ||
|
||
|
||
class FeaturedTopicEnglish(TopicOfTheDay): | ||
class Meta: | ||
proxy = True | ||
verbose_name = "Landing Page - Featured Topic (EN)" | ||
verbose_name_plural = "Landing Page - Featured Topic (EN)" | ||
|
||
def save(self, *args, **kwargs): | ||
self.lang = "en" | ||
super().save(*args, **kwargs) | ||
|
||
|
||
class FeaturedTopicHebrew(TopicOfTheDay): | ||
class Meta: | ||
proxy = True | ||
verbose_name = "Landing Page - Featured Topic (HE)" | ||
verbose_name_plural = "Landing Page - Featured Topic (HE)" | ||
|
||
def save(self, *args, **kwargs): | ||
self.lang = "he" | ||
super().save(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import pytest | ||
from datetime import date | ||
from django_topics.models import TopicOfTheDay, Topic | ||
|
||
|
||
@pytest.fixture | ||
def topic(db): | ||
"""Fixture to create a Topic instance.""" | ||
return Topic.objects.create(slug="test-topic") | ||
|
||
|
||
@pytest.fixture | ||
def featured_topics(db, topic): | ||
"""Fixture to create TopicOfTheDay instances.""" | ||
topics = [ | ||
TopicOfTheDay.objects.create(topic=topic, start_date=date(2024, 11, 26), lang="en"), | ||
TopicOfTheDay.objects.create(topic=topic, start_date=date(2024, 11, 25), lang="en"), | ||
TopicOfTheDay.objects.create(topic=topic, start_date=date(2024, 11, 24), lang="en"), | ||
] | ||
return topics | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_get_featured_topic_with_exact_date_db(featured_topics): | ||
"""Test for exact match.""" | ||
result = TopicOfTheDay.objects.get_featured_topic(lang="en", date=date(2024, 11, 26)) | ||
|
||
assert result.start_date == date(2024, 11, 26) | ||
assert result.lang == "en" | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_get_featured_topic_with_closest_date_db(featured_topics): | ||
"""Test for the closest date less than or equal to the given date.""" | ||
result = TopicOfTheDay.objects.get_featured_topic(lang="en", date=date(2024, 11, 27)) | ||
|
||
assert result.start_date == date(2024, 11, 26) | ||
assert result.lang == "en" | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_get_featured_topic_with_no_matching_date_db(db, topic): | ||
"""Test when there is no matching date.""" | ||
TopicOfTheDay.objects.create(topic=topic, start_date=date(2024, 11, 20), lang="en") | ||
result = TopicOfTheDay.objects.get_featured_topic(lang="en", date=date(2024, 11, 19)) | ||
|
||
assert result is None |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is child called
FeaturedTopicEnglish
instead of simplyTopicOfTheDayEnglish
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed every variable and class name to be based on the new name of the feature "Featured Topic" EXCEPT for the main django model which I kept as "TopicOfTheDay". This is unfortunate but this is why: