Coverage for apps / recipes / migrations / 0009_add_default_selectors.py: 77%
13 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-11 00:40 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-11 00:40 +0000
1"""
2Add default CSS selectors for search sources.
3These selectors target the main recipe result container on each site.
4"""
6from django.db import migrations
9SELECTOR_UPDATES = {
10 'allrecipes.com': 'a.mntl-card-list-items',
11 'bbcgoodfood.com': 'article.card',
12 'bbc.co.uk': '.gel-layout__item a[href*="/recipes/"]',
13 'bonappetit.com': 'a.summary-item__hed-link',
14 'budgetbytes.com': 'article.post-summary',
15 'delish.com': 'a.full-item-card',
16 'epicurious.com': 'article.recipe-card',
17 'thepioneerwoman.com': 'a[href*="/recipes/a"]',
18 'southernliving.com': 'a[href*="/recipes/"]',
19 'skinnytaste.com': 'h2 a',
20 'tasty.co': 'a.feed-item',
21 'seriouseats.com': 'a.card__title',
22 'simplyrecipes.com': 'a.card__titleLink',
23 'tasteofhome.com': 'h3.entry-title a',
24 'thekitchn.com': 'a.PostCard__link',
25}
28def add_selectors(apps, schema_editor):
29 SearchSource = apps.get_model('recipes', 'SearchSource')
30 for host, selector in SELECTOR_UPDATES.items():
31 SearchSource.objects.filter(host=host).update(result_selector=selector)
34def remove_selectors(apps, schema_editor):
35 SearchSource = apps.get_model('recipes', 'SearchSource')
36 for host in SELECTOR_UPDATES.keys():
37 SearchSource.objects.filter(host=host).update(result_selector='')
40class Migration(migrations.Migration):
42 dependencies = [
43 ('recipes', '0008_rename_recipes_rec_profile_idx_recipes_rec_profile_7945b8_idx'),
44 ]
46 operations = [
47 migrations.RunPython(add_selectors, remove_selectors),
48 ]