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

Modularization main2 #2171

Merged
merged 173 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
173 commits
Select commit Hold shift + click to select a range
de6f472
fix(api): refine v1 texts error
saengel Jul 10, 2024
c9d05f1
fix(api): First pass at removing 500 from v3
saengel Jul 14, 2024
33d8b0d
feat(api): scaffolding out 400 error instead of 500
saengel Jul 15, 2024
fcfbe65
fix(api): update error message to include a link
saengel Jul 15, 2024
f76702d
feat(api): add message check
saengel Jul 17, 2024
f87734d
chore(api): remove todos
saengel Jul 17, 2024
6536f74
chore(api): ensure model level error message is informative, and appr…
saengel Jul 19, 2024
390204e
feat(api): add a v1 view error message including a link
saengel Jul 19, 2024
2509488
fix(api): Move errors to view level
saengel Aug 1, 2024
353e652
chore(api): Correct param type to enable accurate results
saengel Nov 10, 2024
8268d5e
Merge pull request #2107 from Sefaria/topic-backend
nsantacruz Nov 11, 2024
25fc731
chore(api errors): Add exception as an official exception vs string comp
saengel Nov 11, 2024
6bea38e
feat(topics): add topic_pool_link model
nsantacruz Nov 11, 2024
ac1fa70
refactor(topics): modify random topic api to use topic pool link model
nsantacruz Nov 11, 2024
110b051
refactor(topics): change pool to 'promoted'
nsantacruz Nov 11, 2024
cce7daf
refactor(topics): move management of pools to use TopicLinkPool model
nsantacruz Nov 12, 2024
94dee44
chore(topics): add uniqueness constraint on topicpoollink
nsantacruz Nov 12, 2024
129529b
chore(topics): add migrate_good_to_promote_to_topic_pools.py
nsantacruz Nov 12, 2024
599180d
chore(api errors): Raise exception, find the right place in model for…
saengel Nov 13, 2024
1827d9d
refactor(topics): Refactor to use two models, Topic and TopicPool to …
nsantacruz Nov 13, 2024
ad18ba1
feat(topics): admin interface for topics and topic pools
nsantacruz Nov 14, 2024
9725b61
feat(topics): only show library topics in topic admin view
nsantacruz Nov 14, 2024
544df75
chore(topics): update pools migration to fully migrate
nsantacruz Nov 14, 2024
eed87c6
feat(topics): add filters and boolean columns
nsantacruz Nov 14, 2024
e85ecf1
refactor(topics): refactor sefaria functions to use new django models
nsantacruz Nov 14, 2024
b483714
chore(topics): add topic migrations
nsantacruz Nov 14, 2024
fb18fcd
chore(topics): add PoolType to model export
nsantacruz Nov 14, 2024
f67db08
refactor(topics): rename pools
nsantacruz Nov 14, 2024
67dec73
feat(topics): add utility funcs to topic model
nsantacruz Nov 14, 2024
86804eb
fix(topics): remove pools from mongo topics model
nsantacruz Nov 14, 2024
17c6a31
fix(topics): fix query
nsantacruz Nov 14, 2024
b268246
refactor(topics): import and pool name
nsantacruz Nov 14, 2024
30736ee
chore(topics): update django topic model on mongo topic save
nsantacruz Nov 14, 2024
53affe9
chore(topics): update django topic when mongo topic slug changes
nsantacruz Nov 14, 2024
f754481
chore(topics): remove extra newline
nsantacruz Nov 14, 2024
d787bf6
refactor(topics): move delete to Topic delete dependency
nsantacruz Nov 14, 2024
af9f31d
test(topics): add tests to make sure django topic remains in sync wit…
nsantacruz Nov 14, 2024
c9a0c43
fix(topics): cast queryset to list
nsantacruz Nov 14, 2024
c99c0e5
chore(topics): remove unused imports
nsantacruz Nov 14, 2024
fb805a8
chore(topics): improve functionality of adding and removing pools
nsantacruz Nov 14, 2024
bf1a99b
test(topics): add topic pool tests
nsantacruz Nov 14, 2024
2b7d79d
feat(topics): add topic pools api
nsantacruz Nov 14, 2024
d889942
refactor(topics): move topics folder to django_topics
nsantacruz Nov 18, 2024
1c7f3be
feat(topics): add TopicOfTheDay model with admin view
nsantacruz Nov 18, 2024
02858a6
feat(topics): add SeasonalTopic model with admin view
nsantacruz Nov 19, 2024
928d9ae
feat(topics): remove end_date from TopicOfTheDay
nsantacruz Nov 19, 2024
5ee2b61
chore(topics): add migration for all django topics models
nsantacruz Nov 19, 2024
1bbb5bb
Merge pull request #2117 from Sefaria/topic-landing-tod
nsantacruz Nov 19, 2024
ba81240
Merge pull request #2110 from Sefaria/topic-landing-pools-sql
nsantacruz Nov 19, 2024
1a5f13f
chore(topics): add migration for all django topics models
nsantacruz Nov 19, 2024
8a60423
fix(search): remove hard-coded DJANGO_SETTINGS env var
nsantacruz Nov 19, 2024
27df1a8
fix(topics): move library setup to startup script.
nsantacruz Nov 19, 2024
25eec71
chore(topics): move os import first
nsantacruz Nov 19, 2024
3589b5a
chore(topics): remove extra print statements
nsantacruz Nov 19, 2024
3863b72
feat(topics): add helpful text for admins
nsantacruz Nov 19, 2024
add1abb
fix(topics): only run init_library_cache() when runserver is run
nsantacruz Nov 20, 2024
eef1df2
chore(topics): add logs to understand why web pod is failing
nsantacruz Nov 20, 2024
6e0cdee
fix(topics): remove if statements
nsantacruz Nov 20, 2024
5b7eff6
chore(topics): add log when starting reader
nsantacruz Nov 20, 2024
5a9202c
fix(topics): run library initialization to runserver command
nsantacruz Nov 20, 2024
967d1eb
chore(topics): add logs
nsantacruz Nov 20, 2024
02431af
chore(api): improved generalized error catching on v3
saengel Nov 20, 2024
9e703ae
chore(api): improved generalized error catching on v1
saengel Nov 20, 2024
8f417b4
fix(topics): use middleware for startup logic so it runs both locally…
nsantacruz Nov 20, 2024
c8f9575
fix(topics): catch data error in topics migration
nsantacruz Nov 20, 2024
e3a41d1
chore(topics): remove useless topic pool admin
nsantacruz Nov 20, 2024
b2435c8
feat(topics): improve admin fields for topic and secondary_topic
nsantacruz Nov 20, 2024
f682f5c
feat(topics): improve admin fields for topic and secondary_topic
nsantacruz Nov 20, 2024
373679b
fix(topics): dont validate start and end dates if both are None
nsantacruz Nov 20, 2024
5f61449
fix(topics): modify admin labels
nsantacruz Nov 21, 2024
10e7ed8
chore(topics): add migration
nsantacruz Nov 21, 2024
49b13f8
chore(topics): change where date is in list view
nsantacruz Nov 21, 2024
432a464
chore(topics): change default sort of start_date
nsantacruz Nov 21, 2024
17f5bd9
chore(topics): change labels of general and torah tab pool
nsantacruz Nov 21, 2024
e68b121
refactor(topics): use topic slug as django topic primary key
nsantacruz Nov 21, 2024
820927c
chore(topics): temp disable library startup
nsantacruz Nov 21, 2024
633d850
chore(topics): temp disable library startup
nsantacruz Nov 21, 2024
5aaee2b
chore(topics): temp disable library startup
nsantacruz Nov 21, 2024
52f3a72
chore(topics): reenable startup
nsantacruz Nov 21, 2024
5b6a297
chore(modules): Clean up naming for modules
saengel Nov 21, 2024
1a79811
fix(topics): ensure slug is str before passing to django model
nsantacruz Nov 21, 2024
e4332a4
fix(topics): move library init to wsgi level so it runs properly on g…
nsantacruz Nov 22, 2024
7b5362b
fix(topics): remove startup middleware from settings
nsantacruz Nov 24, 2024
fc1130b
static(ways-to-give): Update Sefaria's 990 Form
relyks Nov 25, 2024
6b85aa7
Correct filename for 990 form
relyks Nov 25, 2024
fb332c4
chore(linker): respond with validation errors when linker input is in…
nsantacruz Nov 26, 2024
0276f41
test(linker): fix test that was missing params
nsantacruz Nov 26, 2024
2e49f7b
chore(linker): remove unused code
nsantacruz Nov 26, 2024
51b6eff
chore(linker): remove extra =
nsantacruz Nov 26, 2024
53780cb
test(linker): add test for validation error
nsantacruz Nov 26, 2024
09ca59d
fix(linker): add content-type header to find-refs api call from linke…
nsantacruz Nov 26, 2024
cf20819
fix(search): skip index if there are no versions
nsantacruz Nov 26, 2024
577a347
Merge pull request #2130 from Sefaria/fix-reindex-es-no-versions-error
nsantacruz Nov 26, 2024
edef13b
feat(linkSummary): elevate Rashbam on Talmud in the commentaries on c…
YishaiGlasner Nov 26, 2024
8a38170
chore: change single quotes to double quotes.
YishaiGlasner Nov 26, 2024
7120383
chore(api): Clean up empty lines
saengel Nov 26, 2024
8c203d3
chore(api): Add error code
saengel Nov 26, 2024
3f1dabe
chore(api): Add new line before class
saengel Nov 26, 2024
121db3d
chore(module rename): Fix missing import statement
saengel Nov 26, 2024
f8d4237
Merge pull request #2132 from Sefaria/elevate-rashbam
yitzhakc Nov 26, 2024
69b6bad
Merge pull request #2121 from Sefaria/chore/sc-30212/rename-sidebar-m…
yitzhakc Nov 27, 2024
220fb2b
refactor(api): move exception to new api_errors.py
nsantacruz Nov 28, 2024
bcb8c0d
Merge pull request #1972 from Sefaria/feature/sc-27447/improve-error-…
yitzhakc Nov 28, 2024
66c0cf3
refactor(api): move jsonResponse logic to APIInvalidInputException
nsantacruz Nov 28, 2024
bc8a037
Merge pull request #2129 from Sefaria/catch-errors-find-refs
nsantacruz Nov 28, 2024
c41e21d
fix(onSidebarSearchClick): prevent converting of commentary ref to ba…
YishaiGlasner Nov 28, 2024
091c8d9
Merge pull request #2134 from Sefaria/sources-from-search-within-text…
yitzhakc Nov 28, 2024
60059c5
Merge pull request #2105 from Sefaria/feature/sc-29434/bulk-text-api-bug
yitzhakc Dec 1, 2024
051eb36
fix(linker): allow version preferences to be null for find refs api
nsantacruz Dec 1, 2024
1857fc4
Merge pull request #2136 from Sefaria/make-version-prefs-find-refs-nu…
nsantacruz Dec 2, 2024
86a73a5
chore: merge
nsantacruz Dec 2, 2024
49aa8c7
fix(topics): fix bad find and replace
nsantacruz Dec 2, 2024
affb67e
Merge branch 'master' into topic-landing-pools
nsantacruz Dec 2, 2024
1b09814
fix(topics): force cast to str
nsantacruz Nov 25, 2024
192d00e
fix(topics): remove pools for now
nsantacruz Nov 25, 2024
bc0fa46
fix(topics): add pools back
nsantacruz Nov 25, 2024
0a1dfa1
fix(topics): dont allow adding or deleting topics
nsantacruz Nov 25, 2024
35608bc
fix(topics): refer to field as topic slug
nsantacruz Nov 25, 2024
16d9a4b
feat(topics): split calendar into en and he calendar
nsantacruz Nov 27, 2024
075ec5b
feat(topics): split topic of the day into en and he calendar
nsantacruz Nov 27, 2024
b29d2b4
feat(topics): make two general pools, one for en and one for he
nsantacruz Nov 27, 2024
8c469be
feat(topics): add column with sefaria link
nsantacruz Nov 27, 2024
3630cd0
feat(topics): make display data prefix/suffix editable
nsantacruz Nov 27, 2024
04abbbe
fix(topics): remove incorrect find and replace
nsantacruz Dec 3, 2024
fd170b5
fix(topics): correct update link order logic
nsantacruz Dec 3, 2024
eb1d725
Merge pull request #2139 from Sefaria/pull-out-image-cropper
nsantacruz Dec 3, 2024
6b23c91
refactor(topics): move pools attribute out of derived attributes
nsantacruz Dec 3, 2024
6814354
fix(topics): regenerate sheet links
nsantacruz Dec 3, 2024
623b655
fix(topics): revert int conversion on bulktext_api
saengel Dec 3, 2024
7822673
Merge pull request #2144 from Sefaria/fix-topics
nsantacruz Dec 3, 2024
82057e8
fix(profile): pass image to onSave callback so it is uploaded
nsantacruz Dec 3, 2024
43da550
Merge pull request #2145 from Sefaria/fix-profile-image-upload-callback
nsantacruz Dec 4, 2024
837df54
add workflow_dispatch
akiva10b Dec 4, 2024
a40df15
Merge pull request #2146 from Sefaria/akiva10b-patch-1
akiva10b Dec 4, 2024
00d6640
chore(caned db): fix = typo
akiva10b Dec 4, 2024
2cc6fd2
fix: use correct name for gar tag
BrendanGalloway Dec 4, 2024
6d266ff
Merge pull request #2147 from Sefaria/mic-gcr-image
akiva10b Dec 4, 2024
64001fd
fix: remove caching instructions from mic build
BrendanGalloway Dec 4, 2024
e10dc78
Merge pull request #2148 from Sefaria/mic-gcr-image
akiva10b Dec 4, 2024
10a94c8
ci(db): update registry to sefaria-public
akiva10b Dec 5, 2024
7e30a52
Merge pull request #2153 from Sefaria/akiva10b-patch-2
edamboritz Dec 5, 2024
e536339
Merge pull request #2128 from Sefaria/update-990-form-2023
edamboritz Dec 5, 2024
79ed249
chore(topics): add log when initialization is complete
nsantacruz Dec 7, 2024
7d40f2c
chore(topics): fix typing
nsantacruz Dec 7, 2024
5341518
Merge pull request #2140 from Sefaria/topic-landing-pools
nsantacruz Dec 8, 2024
18cb217
fix(topics): remove subscript from QuerySet
nsantacruz Dec 8, 2024
8162a41
Merge branch 'master' into topic-landing-pools
nsantacruz Dec 8, 2024
510565a
Merge pull request #2156 from Sefaria/topic-landing-pools
nsantacruz Dec 8, 2024
249e6b4
fix(helm): increase gunicorn timeout
nsantacruz Dec 8, 2024
9de2979
Merge pull request #2157 from Sefaria/up-gunicorn-timeout
nsantacruz Dec 8, 2024
64ccbbd
fix(helm): Fix syntax error in rollout file
edamboritz Dec 8, 2024
7d3ceeb
Merge pull request #2158 from Sefaria/hotfix-task-helm-rollout
edamboritz Dec 8, 2024
f73421b
fix(helm): move library init code to gunicorn start hook.
nsantacruz Dec 9, 2024
1f8d2db
fix(helm): use when_ready
nsantacruz Dec 9, 2024
781a1ed
fix(helm): fix indentation
nsantacruz Dec 9, 2024
895a538
fix(startup): explicitly run django setup
nsantacruz Dec 9, 2024
00c4d84
fix(startup): set preload_app to True
nsantacruz Dec 9, 2024
b5b96fc
fix: switch healthz and healthz-rollout
nsantacruz Dec 9, 2024
04ced9f
fix: run library init on runserver so that it also runs locally
nsantacruz Dec 9, 2024
71a2f15
Merge pull request #2160 from Sefaria/gunicorn-startup-script
nsantacruz Dec 9, 2024
dd6f490
fix(strapi banners): Temporary fix for fixing the spacing on Strapi b…
relyks Dec 9, 2024
29a3dd3
fix(static): Update link that was missing change for the most recent …
relyks Dec 10, 2024
7e237ef
Merge pull request #2162 from Sefaria/fix-link-for-2023-990-form
edamboritz Dec 10, 2024
587c797
Merge pull request #2161 from Sefaria/bug/sc-30956/fix-display-of-str…
edamboritz Dec 10, 2024
c7401e6
fix: build mongo for arm too
BrendanGalloway Dec 10, 2024
f6b8f18
Merge pull request #2166 from Sefaria/mic-arm
akiva10b Dec 10, 2024
ed9d542
feat: add action to free space on the runner
BrendanGalloway Dec 11, 2024
43c4a00
Merge pull request #2167 from Sefaria/mic-arm
akiva10b Dec 11, 2024
fa782b6
fix: reduce parallelism to avoid port collision
BrendanGalloway Dec 11, 2024
f613b7d
Merge pull request #2168 from Sefaria/mic-arm
akiva10b Dec 11, 2024
8d70c58
fix: correct buildkit config flag
BrendanGalloway Dec 11, 2024
4130934
Merge pull request #2169 from Sefaria/mic-arm
akiva10b Dec 11, 2024
698d99e
Merge branch 'master' into modularization-main2
stevekaplan123 Dec 11, 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
24 changes: 17 additions & 7 deletions .github/workflows/weekly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Weekly Tasks
on:
schedule:
- cron: '0 0 * 6 *'
workflow_dispatch:

jobs:
build-mongo:
Expand All @@ -11,11 +12,21 @@ jobs:
contents: 'read'
id-token: 'write'
steps:
- name: Maximize build space
uses: AdityaGarg8/[email protected]
with:
remove-android: 'true'
remove-dotnet: 'true'
remove-haskell: 'true'
remove-codeql: 'true'
remove-docker-images: 'true'
- uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
with:
buildkitd-config: ./build/standalone-db/buildkit.toml
- id: auth
name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
Expand All @@ -37,27 +48,26 @@ jobs:
password: '${{ steps.auth.outputs.access_token }}'
- name: Get current date
id: date
run: echo "date$(date +'%Y%m%d%H%M')" >> $GITHUB_OUTPUT
run: echo "date=$(date +'%Y%m%d%H%M')" >> $GITHUB_OUTPUT
- name: Generate image metadata
id: meta
uses: docker/metadata-action@v3
with:
images: |
gcr.io/${{ secrets.DEV_PROJECT }}/sefaria-mongo
us-east1-docker.pkg.dev/${{ secrets.DEV_PROJECT }}/containers/sefaria-${{ matrix.app }}-${{ steps.branch-name.outputs.current_branch }}
us-east1-docker.pkg.dev/${{ secrets.DEV_PROJECT }}/sefaria-public/sefaria-mongo
# generate Docker tags based on the following events/attributes
tags: |
type=sha,enable=true,priority=100,prefix=sha-,suffix=-${{ steps.date.outputs.date }},format=short
type=sha
flavor: |
latest=true
- name: build and push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v6
with:
cache-from: type=registry, ref=sefaria-mongo/cache
cache-to: type=registry, ref=sefaria-mongo/cache, mode=max
context: .
push: true
platforms: linux/amd64,linux/arm64
file: ./build/standalone-db/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
16 changes: 16 additions & 0 deletions api/api_errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Classes for API errors
"""
from sefaria.client.util import jsonResponse


class APIInvalidInputException(Exception):
"""
When data in an invalid format is passed to an API
"""
def __init__(self, message):
super().__init__(message)
self.message = message

def to_json_response(self):
return jsonResponse({"invalid_input_error": self.message}, status=400)
11 changes: 9 additions & 2 deletions api/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from sefaria.model import *
from sefaria.model.text_reuqest_adapter import TextRequestAdapter
from sefaria.client.util import jsonResponse
from sefaria.system.exceptions import InputError, ComplexBookLevelRefError
from django.views import View
from .api_warnings import *

Expand Down Expand Up @@ -53,6 +54,12 @@ def get(self, request, *args, **kwargs):
if return_format not in self.RETURN_FORMATS:
return jsonResponse({'error': f'return_format should be one of those formats: {self.RETURN_FORMATS}.'}, status=400)
text_manager = TextRequestAdapter(self.oref, versions_params, fill_in_missing_segments, return_format)
data = text_manager.get_versions_for_query()
data = self._handle_warnings(data)

try:
data = text_manager.get_versions_for_query()
data = self._handle_warnings(data)

except Exception as e:
return jsonResponse({'error': str(e)}, status=400)

return jsonResponse(data)
2 changes: 2 additions & 0 deletions build/standalone-db/buildkit.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[worker.oci]
max-parallelism = 1
8 changes: 8 additions & 0 deletions django_topics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Django Topics app

Django app that defines models and admin interfaces for editing certain aspects of topics that are unique to Sefaria's product and not needed for general usage of Sefaria's data.

Currently contains methods to:
- Edit which topics are in which pools
- Define topic of the day schedule
- Define seasonal topic schedule
Empty file added django_topics/__init__.py
Empty file.
229 changes: 229 additions & 0 deletions django_topics/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
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.pool import PoolType


def create_add_to_pool_action(pool_name):
def add_to_pool(modeladmin, request, queryset):
try:
pool = TopicPool.objects.get(name=pool_name)
for topic in queryset:
topic.pools.add(pool)
modeladmin.message_user(request, f"Added {queryset.count()} topics to {pool.name}", messages.SUCCESS)

except TopicPool.DoesNotExist:
modeladmin.message_user(request, "The specified pool does not exist.", messages.ERROR)

add_to_pool.short_description = f"Add selected topics to '{pool_name}' pool"
add_to_pool.__name__ = f"add_to_specific_pool_{pool_name}"
return add_to_pool


def create_remove_from_pool_action(pool_name):
def remove_from_pool(modeladmin, request, queryset):
try:
pool = TopicPool.objects.get(name=pool_name)
for topic in queryset:
topic.pools.remove(pool)
modeladmin.message_user(request, f"Removed {queryset.count()} topics from {pool.name}", messages.SUCCESS)

except TopicPool.DoesNotExist:
modeladmin.message_user(request, "The specified pool does not exist.", messages.ERROR)

remove_from_pool.short_description = f"Remove selected topics from '{pool_name}' pool"
remove_from_pool.__name__ = f"remove_from_pool_{pool_name}"
return remove_from_pool


class PoolFilter(admin.SimpleListFilter):
title = 'Pool Filter'
parameter_name = 'pool'

def lookups(self, request, model_admin):
return [
('general_en', 'General Pool EN'),
('general_he', 'General Pool HE'),
(PoolType.TORAH_TAB.value, 'TorahTab Pool'),
]

def queryset(self, request, queryset):
pool_name = self.value()
if pool_name:
pool = TopicPool.objects.get(name=pool_name)
return queryset.filter(pools=pool)
return queryset


@admin.register(Topic)
class TopicAdmin(admin.ModelAdmin):
list_display = ('slug', 'en_title', 'he_title', 'is_in_pool_general_en', 'is_in_pool_general_he', 'is_in_pool_torah_tab', 'sefaria_link')
list_filter = (PoolFilter,)
filter_horizontal = ('pools',)
search_fields = ('slug', 'en_title', 'he_title')
readonly_fields = ('slug', 'en_title', 'he_title')
actions = [
create_add_to_pool_action('general_en'),
create_add_to_pool_action('general_he'),
create_add_to_pool_action(PoolType.TORAH_TAB.value),
create_remove_from_pool_action('general_en'),
create_remove_from_pool_action('general_he'),
create_remove_from_pool_action(PoolType.TORAH_TAB.value),
]

def has_add_permission(self, request):
return False

def has_delete_permission(self, request, obj=None):
return False

def get_queryset(self, request):
queryset = super().get_queryset(request)
return queryset.filter(pools__name=PoolType.LIBRARY.value)

def is_in_pool_general_en(self, obj):
return obj.pools.filter(name='general_en').exists()
is_in_pool_general_en.boolean = True
is_in_pool_general_en.short_description = "General Pool EN"

def is_in_pool_general_he(self, obj):
return obj.pools.filter(name='general_he').exists()
is_in_pool_general_he.boolean = True
is_in_pool_general_he.short_description = "General Pool HE"

def is_in_pool_torah_tab(self, obj):
return obj.pools.filter(name=PoolType.TORAH_TAB.value).exists()
is_in_pool_torah_tab.boolean = True
is_in_pool_torah_tab.short_description = "TorahTab Pool"

def sefaria_link(self, obj):
url = f"https://www.sefaria.org/topics/{obj.slug}"
return format_html('<a href="{}" target="_blank">{}</a>', url, obj.slug)
sefaria_link.short_description = "Sefaria Link"


class TopicOfTheDayAdmin(admin.ModelAdmin):
exclude = ("lang",) # not for manual editing
list_display = ('start_date', 'topic')
list_filter = ('start_date',)
raw_id_fields = ('topic',)
search_fields = ('topic__slug', 'topic__en_title', 'topic__he_title')
date_hierarchy = 'start_date'
ordering = ['-start_date']
fieldsets = (
(None, {
'fields': ('topic', 'start_date'),
}),
)

def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "topic":
kwargs["label"] = "Topic slug"
kwargs["help_text"] = "Use the magnifying glass button to select a topic."
return super().formfield_for_foreignkey(db_field, request, **kwargs)


@admin.register(TopicOfTheDayEnglish)
class TopicOfTheDayAdminEnglish(TopicOfTheDayAdmin):

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


@admin.register(TopicOfTheDayHebrew)
class TopicOfTheDayAdminHebrew(TopicOfTheDayAdmin):

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


class SeasonalTopicAdmin(admin.ModelAdmin):
exclude = ("lang",) # not for manual editing
list_display = (
'start_date',
'topic',
'display_date_prefix',
'display_date_suffix',
'secondary_topic',
'display_start_date_israel',
'display_end_date_israel',
'display_start_date_diaspora',
'display_end_date_diaspora'
)
raw_id_fields = ('topic', 'secondary_topic')
list_filter = (
'start_date',
'display_start_date_israel',
'display_start_date_diaspora'
)
ordering = ['-start_date']
search_fields = ('topic__slug', 'topic__en_title', 'topic__he_title', 'secondary_topic__slug')
autocomplete_fields = ('topic', 'secondary_topic')
date_hierarchy = 'start_date'
fieldsets = (
(None, {
'fields': (
'topic',
'secondary_topic',
'start_date'
)
}),
('Display Date Prefix/Suffix', {
'fields': (
'display_date_prefix',
'display_date_suffix',
),
'description': 'Prefix/Suffix that will be displayed around the secondary topic.',
}),
('Israel Display Dates', {
'fields': (
'display_start_date_israel',
'display_end_date_israel'
),
'description': 'Dates to be displayed to the user of when this topic is "happening". '
'E.g. for a holiday, when the holiday occurs. '
'When the dates are the same for both Israel and Diaspora, only fill out Israeli dates. '
'Similarly, when the start and end dates are the same, only fill out start date.'
}),
('Diaspora Display Dates', {
'fields': (
'display_start_date_diaspora',
'display_end_date_diaspora'
),
'description': 'When the dates are the same for both Israel and Diaspora, only fill out Israeli dates. '
'Similarly, when the start and end dates are the same, only fill out start date.'

}),
)

def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "topic":
kwargs["label"] = "Topic slug"
kwargs["help_text"] = "Use the magnifying glass button to select a topic."
if db_field.name == "secondary_topic":
kwargs["label"] = "Secondary topic slug"
return super().formfield_for_foreignkey(db_field, request, **kwargs)

def save_model(self, request, obj, form, change):
"""
Overriding the save_model to ensure the model's clean method is executed.
"""
obj.clean()
super().save_model(request, obj, form, change)


@admin.register(SeasonalTopicEnglish)
class SeasonalTopicAdminEnglish(SeasonalTopicAdmin):

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


@admin.register(SeasonalTopicHebrew)
class SeasonalTopicAdminHebrew(SeasonalTopicAdmin):
def get_queryset(self, request):
qs = super().get_queryset(request)
return qs.filter(lang="he")
6 changes: 6 additions & 0 deletions django_topics/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class DjangoTopicsAppConfig(AppConfig):
name = "django_topics"
verbose_name = "Topics Management"
Loading
Loading