Skip to content

Commit

Permalink
Merge pull request #2321 from Sefaria/modularization-merge-master
Browse files Browse the repository at this point in the history
Modularization merge master
  • Loading branch information
yitzhakc authored Feb 11, 2025
2 parents b40b782 + f1fed2a commit 183aa65
Show file tree
Hide file tree
Showing 171 changed files with 2,628 additions and 1,009 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/helm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Helm
uses: azure/setup-helm@v1
with:
version: v3.5.0
uses: azure/[email protected]
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Set up chart-testing
uses: helm/[email protected]
with:
version: v3.5.1
- name: Lint chart
run: ct lint --charts helm-chart/sefaria-project
run: ct lint --charts helm-chart/sefaria

chart:
name: Release Chart
Expand Down Expand Up @@ -87,9 +83,9 @@ jobs:
wget -nv -nc -O yq https://github.com/mikefarah/yq/releases/download/v4.20.2/yq_linux_amd64
chmod +x yq
- name: Update chart version
run: ./yq -i e '.version = "${{ steps.chartVersion.outputs.chartVersion }}"' helm-chart/sefaria-project/Chart.yaml
run: ./yq -i e '.version = "${{ steps.chartVersion.outputs.chartVersion }}"' helm-chart/sefaria/Chart.yaml
- name: Update chart appVersion
run: ./yq -i e '.appVersion = "${{ steps.appVersion.outputs.appVersion }}"' helm-chart/sefaria-project/Chart.yaml
run: ./yq -i e '.appVersion = "${{ steps.appVersion.outputs.appVersion }}"' helm-chart/sefaria/Chart.yaml
- name: Publish Helm charts
uses: stefanprodan/helm-gh-pages@master
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/integration-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ jobs:
sudo apt-get update
sudo apt-get install -y --no-install-recommends curl unzip
- name: Setup kubectl
uses: azure/setup-kubectl@v3
uses: azure/setup-kubectl@v4
- name: setup helm
uses: azure/setup-helm@v3
uses: azure/setup-helm@v4
- name: Set up yq
run: |
curl -L https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O
Expand Down Expand Up @@ -200,7 +200,7 @@ jobs:
PLAYWRIGHT_USER_PASSWORD: "${{ secrets.PLAYWRIGHT_USER_PASSWORD }}"

- name: Upload Playwright report
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
Expand All @@ -215,7 +215,7 @@ jobs:
- run-tests
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: '14'
- run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion build/ci/integration-helm-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ yq e -i '.secrets.localSettings.data.SEFARIA_DB = "sefaria-integration"' $1
yq e -i '.ingress.hosts[0].host = strenv(GIT_COMMIT)+".integration.sefaria.org"' $1
yq e -i '.localSettings.FRONT_END_URL = "https://"+strenv(GIT_COMMIT)+".integration.sefaria.org"' $1

helm upgrade -i $NAME ./helm-chart/sefaria-project --namespace $NAMESPACE -f $1 --debug --timeout=30m0s
helm upgrade -i $NAME ./helm-chart/sefaria --namespace $NAMESPACE -f $1 --debug --timeout=30m0s

2 changes: 1 addition & 1 deletion build/ci/sandbox-helm-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ yq e -i '.monitor.containerImage.tag = strenv(TAG)' $1
yq e -i '.deployEnv = strenv(NAME)' $1
yq e -i '.localSettings.FRONT_END_URL = "https://"+strenv(NAME)+".cauldron.sefaria.org"' $1

helm upgrade -i $NAME ./helm-chart/sefaria-project --namespace $NAMESPACE -f $1 --debug --timeout=30m0s
helm upgrade -i $NAME ./helm-chart/sefaria --namespace $NAMESPACE -f $1 --debug --timeout=30m0s

19 changes: 12 additions & 7 deletions django_topics/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.contrib import admin, messages
from django.utils.html import format_html
from django_topics.models import Topic, TopicPool, TopicOfTheDayEnglish, TopicOfTheDayHebrew, SeasonalTopicEnglish, SeasonalTopicHebrew
from django_topics.models import Topic, TopicPool, FeaturedTopicEnglish, FeaturedTopicHebrew, SeasonalTopicEnglish, SeasonalTopicHebrew
from django_topics.models.pool import PoolType
from django.utils.html import format_html



def create_add_to_pool_action(pool_name):
Expand Down Expand Up @@ -70,6 +71,10 @@ class TopicAdmin(admin.ModelAdmin):
create_remove_from_pool_action('general_he'),
create_remove_from_pool_action(PoolType.TORAH_TAB.value),
]
def save_related(self, request, form, formsets, change):
super().save_related(request, form, formsets, change)
Topic.objects.build_slug_to_pools_cache(rebuild=True)


def has_add_permission(self, request):
return False
Expand Down Expand Up @@ -102,7 +107,7 @@ def sefaria_link(self, obj):
sefaria_link.short_description = "Sefaria Link"


class TopicOfTheDayAdmin(admin.ModelAdmin):
class FeaturedTopicAdmin(admin.ModelAdmin):
exclude = ("lang",) # not for manual editing
list_display = ('start_date', 'topic')
list_filter = ('start_date',)
Expand All @@ -123,16 +128,16 @@ def formfield_for_foreignkey(self, db_field, request, **kwargs):
return super().formfield_for_foreignkey(db_field, request, **kwargs)


@admin.register(TopicOfTheDayEnglish)
class TopicOfTheDayAdminEnglish(TopicOfTheDayAdmin):
@admin.register(FeaturedTopicEnglish)
class FeaturedTopicAdminEnglish(FeaturedTopicAdmin):

def get_queryset(self, request):
qs = super().get_queryset(request)
return qs.filter(lang="en")


@admin.register(TopicOfTheDayHebrew)
class TopicOfTheDayAdminHebrew(TopicOfTheDayAdmin):
@admin.register(FeaturedTopicHebrew)
class FeaturedTopicAdminHebrew(FeaturedTopicAdmin):

def get_queryset(self, request):
qs = super().get_queryset(request)
Expand Down
49 changes: 49 additions & 0 deletions django_topics/migrations/0008_auto_20241217_0702.py
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'},
),
]
19 changes: 19 additions & 0 deletions django_topics/migrations/0009_auto_20250210_0647.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2025-02-10 10:47
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('django_topics', '0008_auto_20241217_0702'),
]

operations = [
migrations.AlterUniqueTogether(
name='topicoftheday',
unique_together=set([('topic', 'start_date', 'lang')]),
),
]
2 changes: 1 addition & 1 deletion django_topics/models/__init__.py
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
62 changes: 62 additions & 0 deletions django_topics/models/featured_topic.py
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', 'lang')
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)
23 changes: 23 additions & 0 deletions django_topics/models/seasonal_topic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
from django.db import models
from django_topics.models import Topic
from django.core.exceptions import ValidationError
from django.utils.timezone import now
from datetime import datetime

class SeasonalTopicManager(models.Manager):
def get_seasonal_topic(self, lang: str, date: datetime = None) -> 'SeasonalTopic':
"""
Return seasonal 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 SeasonalTopic(models.Model):
topic = models.ForeignKey(
Expand All @@ -25,6 +41,7 @@ class SeasonalTopic(models.Model):
display_date_prefix = models.CharField(max_length=255, blank=True, null=True)
display_date_suffix = models.CharField(max_length=255, blank=True, null=True)
lang = models.CharField(max_length=2, choices=[('en', 'English'), ('he', 'Hebrew')])
objects = SeasonalTopicManager()

class Meta:
unique_together = ('topic', 'start_date')
Expand Down Expand Up @@ -61,6 +78,12 @@ def clean(self):
def __str__(self):
return f"{self.topic.slug} ({self.start_date})"

def get_display_start_date(self, diaspora=True):
return self.display_start_date_diaspora if diaspora else self.display_start_date_israel

def get_display_end_date(self, diaspora=True):
return self.display_end_date_diaspora if diaspora else self.display_end_date_israel


class SeasonalTopicEnglish(SeasonalTopic):
class Meta:
Expand Down
47 changes: 47 additions & 0 deletions django_topics/models/tests/featured_topic_test.py
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
Loading

0 comments on commit 183aa65

Please sign in to comment.