Coverage for apps / recipes / migrations / 0002_populate_search_sources.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
1from django.db import migrations
4SEARCH_SOURCES = [
5 {
6 'host': 'allrecipes.com',
7 'name': 'AllRecipes',
8 'search_url_template': 'https://www.allrecipes.com/search?q={query}',
9 'result_selector': '',
10 },
11 {
12 'host': 'bbcgoodfood.com',
13 'name': 'BBC Good Food',
14 'search_url_template': 'https://www.bbcgoodfood.com/search?q={query}',
15 'result_selector': '',
16 },
17 {
18 'host': 'bbc.co.uk',
19 'name': 'BBC Food',
20 'search_url_template': 'https://www.bbc.co.uk/food/search?q={query}',
21 'result_selector': '',
22 },
23 {
24 'host': 'bonappetit.com',
25 'name': 'Bon Appetit',
26 'search_url_template': 'https://www.bonappetit.com/search?q={query}',
27 'result_selector': '',
28 },
29 {
30 'host': 'budgetbytes.com',
31 'name': 'Budget Bytes',
32 'search_url_template': 'https://www.budgetbytes.com/?s={query}',
33 'result_selector': '',
34 },
35 {
36 'host': 'delish.com',
37 'name': 'Delish',
38 'search_url_template': 'https://www.delish.com/search/?q={query}',
39 'result_selector': '',
40 },
41 {
42 'host': 'epicurious.com',
43 'name': 'Epicurious',
44 'search_url_template': 'https://www.epicurious.com/search?q={query}',
45 'result_selector': '',
46 },
47 {
48 'host': 'thepioneerwoman.com',
49 'name': 'The Pioneer Woman',
50 'search_url_template': 'https://www.thepioneerwoman.com/food-cooking/recipes/?query={query}',
51 'result_selector': '',
52 },
53 {
54 'host': 'southernliving.com',
55 'name': 'Southern Living',
56 'search_url_template': 'https://www.southernliving.com/search?q={query}',
57 'result_selector': '',
58 },
59 {
60 'host': 'skinnytaste.com',
61 'name': 'Skinnytaste',
62 'search_url_template': 'https://www.skinnytaste.com/?s={query}',
63 'result_selector': '',
64 },
65 {
66 'host': 'tasty.co',
67 'name': 'Tasty',
68 'search_url_template': 'https://tasty.co/search?q={query}',
69 'result_selector': '',
70 },
71 {
72 'host': 'seriouseats.com',
73 'name': 'Serious Eats',
74 'search_url_template': 'https://www.seriouseats.com/search?q={query}',
75 'result_selector': '',
76 },
77 {
78 'host': 'simplyrecipes.com',
79 'name': 'Simply Recipes',
80 'search_url_template': 'https://www.simplyrecipes.com/search?q={query}',
81 'result_selector': '',
82 },
83 {
84 'host': 'tasteofhome.com',
85 'name': 'Taste of Home',
86 'search_url_template': 'https://www.tasteofhome.com/recipes/?s={query}',
87 'result_selector': '',
88 },
89 {
90 'host': 'thekitchn.com',
91 'name': 'The Kitchn',
92 'search_url_template': 'https://www.thekitchn.com/search?q={query}',
93 'result_selector': '',
94 },
95]
98def populate_search_sources(apps, schema_editor):
99 SearchSource = apps.get_model('recipes', 'SearchSource')
100 for source_data in SEARCH_SOURCES:
101 SearchSource.objects.get_or_create(
102 host=source_data['host'],
103 defaults=source_data,
104 )
107def remove_search_sources(apps, schema_editor):
108 SearchSource = apps.get_model('recipes', 'SearchSource')
109 hosts = [s['host'] for s in SEARCH_SOURCES]
110 SearchSource.objects.filter(host__in=hosts).delete()
113class Migration(migrations.Migration):
115 dependencies = [
116 ('recipes', '0001_initial'),
117 ]
119 operations = [
120 migrations.RunPython(populate_search_sources, remove_search_sources),
121 ]