mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2025-12-26 03:43:34 -05:00
Compare commits
975 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed313cbf9a | ||
|
|
b1db591e9f | ||
|
|
94c51f90cd | ||
|
|
3074d916dc | ||
|
|
bf467b1ec0 | ||
|
|
348c1c78f1 | ||
|
|
913e896906 | ||
|
|
a0a673a0c9 | ||
|
|
3d60379ed0 | ||
|
|
fd7e20a46b | ||
|
|
a970f0c00e | ||
|
|
297dd6244a | ||
|
|
c83eb1a42b | ||
|
|
8181a6d416 | ||
|
|
4a8b50aeba | ||
|
|
388ef32475 | ||
|
|
bfe72210df | ||
|
|
02c5aed0a3 | ||
|
|
6fc0c02674 | ||
|
|
040af330cc | ||
|
|
05caad5cfe | ||
|
|
7aa1c7b53b | ||
|
|
ad24a44588 | ||
|
|
9f4eb91287 | ||
|
|
9982cae7c3 | ||
|
|
6d065cb939 | ||
|
|
b10163e309 | ||
|
|
28b8973259 | ||
|
|
4f09970130 | ||
|
|
e05019d2b1 | ||
|
|
3c778927e2 | ||
|
|
505b60cb14 | ||
|
|
14ca61b11f | ||
|
|
22900dc460 | ||
|
|
28806e6857 | ||
|
|
dbf1334ec0 | ||
|
|
7e0d9bfe49 | ||
|
|
56f80acede | ||
|
|
46a8a9f60d | ||
|
|
71fdfe6acb | ||
|
|
50572e9a36 | ||
|
|
c8054349b2 | ||
|
|
0ec5d669dd | ||
|
|
6dd778112a | ||
|
|
a14e33973c | ||
|
|
a8d01f4d5a | ||
|
|
58f841a770 | ||
|
|
c851b54a22 | ||
|
|
df53fdeb03 | ||
|
|
18333563f2 | ||
|
|
286118093c | ||
|
|
066ca27712 | ||
|
|
03c78f539d | ||
|
|
be225d2b8c | ||
|
|
3340ef9ca4 | ||
|
|
fe3e611dd1 | ||
|
|
61d1528911 | ||
|
|
88524b0411 | ||
|
|
e774845ade | ||
|
|
9a8049f71b | ||
|
|
d67bb9de25 | ||
|
|
4b7896f7d1 | ||
|
|
66ce1a88f6 | ||
|
|
9ad42ae869 | ||
|
|
1e72893c84 | ||
|
|
a21755cf81 | ||
|
|
f0ba8eb788 | ||
|
|
149020f930 | ||
|
|
200adb2fcf | ||
|
|
bbd4d20210 | ||
|
|
8aa11836a3 | ||
|
|
35338e2765 | ||
|
|
ddc91d910f | ||
|
|
34085fc949 | ||
|
|
4ab56ef9f7 | ||
|
|
47b873a2af | ||
|
|
34128ba3a3 | ||
|
|
fae25b83fa | ||
|
|
a2322c18eb | ||
|
|
f99793fc1a | ||
|
|
b10b811550 | ||
|
|
792ee43377 | ||
|
|
157beb3376 | ||
|
|
1313c962fa | ||
|
|
17c18c6d08 | ||
|
|
7650edfdc8 | ||
|
|
46e48cd3a5 | ||
|
|
223f899e88 | ||
|
|
d56c8c283c | ||
|
|
67cd74860f | ||
|
|
4df87bc7c7 | ||
|
|
16237866a1 | ||
|
|
79cc8cc905 | ||
|
|
3e2f3effeb | ||
|
|
5623879919 | ||
|
|
b1b1373d65 | ||
|
|
3270f56744 | ||
|
|
36df86c26c | ||
|
|
532d6e2867 | ||
|
|
7c6d32456a | ||
|
|
6b8aa99b24 | ||
|
|
65a6c08015 | ||
|
|
22f4612d12 | ||
|
|
f65a5a9ad7 | ||
|
|
02b2d953ce | ||
|
|
19cdf3a919 | ||
|
|
6dfe737ec5 | ||
|
|
6110c75f59 | ||
|
|
984d5aae11 | ||
|
|
e345d2eb39 | ||
|
|
90e1e69dac | ||
|
|
c4880bf5b0 | ||
|
|
3baa03396c | ||
|
|
373df5d99f | ||
|
|
d36274066a | ||
|
|
59c33798b8 | ||
|
|
d7afbc5745 | ||
|
|
c62a88d032 | ||
|
|
ed76f020c5 | ||
|
|
8b61d8c504 | ||
|
|
82abdd0144 | ||
|
|
04d131f534 | ||
|
|
8cc74f3dcd | ||
|
|
bd46962b71 | ||
|
|
059987fd9f | ||
|
|
2ecc0ab680 | ||
|
|
a69fb4922d | ||
|
|
358ba5120d | ||
|
|
254267c2a7 | ||
|
|
a701437548 | ||
|
|
25f6adba1f | ||
|
|
018fa0a62f | ||
|
|
faf458e8ef | ||
|
|
2c5348fcb4 | ||
|
|
2b16f966a2 | ||
|
|
c2931137bb | ||
|
|
461d53671c | ||
|
|
3e4e55e9c5 | ||
|
|
11fa23f3da | ||
|
|
6de128757f | ||
|
|
7c682ebab3 | ||
|
|
ee165ef0f1 | ||
|
|
4bc4ce0d7c | ||
|
|
c50bd039ef | ||
|
|
5fff5b97da | ||
|
|
2c27e06bfb | ||
|
|
e4044016c3 | ||
|
|
52df886372 | ||
|
|
c7949edb18 | ||
|
|
342a261017 | ||
|
|
e5984abd97 | ||
|
|
2ea3e4f8f3 | ||
|
|
98b3b002f9 | ||
|
|
d2a1a0ac32 | ||
|
|
2ceefdd9b0 | ||
|
|
b22392726f | ||
|
|
b89fedd07f | ||
|
|
a263771383 | ||
|
|
7cc757ac33 | ||
|
|
6acbd6d308 | ||
|
|
30a357e27f | ||
|
|
7bc3292301 | ||
|
|
7fb440a855 | ||
|
|
0e27ddab74 | ||
|
|
0a38049ce4 | ||
|
|
4aaecb4ada | ||
|
|
3f5e64fc4a | ||
|
|
154527ef1b | ||
|
|
788e253749 | ||
|
|
7c8b489857 | ||
|
|
cdc25b480d | ||
|
|
1568d86143 | ||
|
|
adeb360837 | ||
|
|
9cc6a1dc79 | ||
|
|
6a13619bbd | ||
|
|
58e33ef31a | ||
|
|
36841d74af | ||
|
|
8094c7d53a | ||
|
|
71e02c0916 | ||
|
|
25fb41baed | ||
|
|
34ff484830 | ||
|
|
91e36eb222 | ||
|
|
55ba568f3c | ||
|
|
8f3f1c230c | ||
|
|
1690abaf47 | ||
|
|
7414033495 | ||
|
|
d1b9d15816 | ||
|
|
ff43492265 | ||
|
|
3daebc4170 | ||
|
|
67485c0ea3 | ||
|
|
aafbc497cc | ||
|
|
0a99791021 | ||
|
|
7bc4ae9870 | ||
|
|
84bd33f93e | ||
|
|
7cd6a7c2a6 | ||
|
|
c661646f46 | ||
|
|
7a017899ee | ||
|
|
5ef5530392 | ||
|
|
689c447b6c | ||
|
|
239ba5f861 | ||
|
|
43c71af2af | ||
|
|
b9040cb3a4 | ||
|
|
c710d42ccb | ||
|
|
1bc5af1cab | ||
|
|
23415f8a61 | ||
|
|
cc34496c00 | ||
|
|
be84e44e43 | ||
|
|
ae3eb6cfe5 | ||
|
|
d06e6c0ab3 | ||
|
|
5ee718b578 | ||
|
|
dc27f39393 | ||
|
|
ec95f8032c | ||
|
|
94b56ff742 | ||
|
|
fd1258f851 | ||
|
|
6f104d8aa4 | ||
|
|
d35f8a0ccd | ||
|
|
f2d761f7d9 | ||
|
|
d9a92fac95 | ||
|
|
a1572a4809 | ||
|
|
2b5dceee7c | ||
|
|
62e9a7f29c | ||
|
|
66bb5b4328 | ||
|
|
0f4cd4b17c | ||
|
|
ae3835b541 | ||
|
|
28fedfda1f | ||
|
|
92c65ec1e8 | ||
|
|
a376c3a5b6 | ||
|
|
058d705170 | ||
|
|
4ad5d6ef2f | ||
|
|
e676b4bac3 | ||
|
|
04488741c4 | ||
|
|
99004ad34b | ||
|
|
f78f7dfc14 | ||
|
|
49fb1e7183 | ||
|
|
7930c2417c | ||
|
|
880db58d38 | ||
|
|
2f27413c0a | ||
|
|
5869a8ad1b | ||
|
|
0640a265fc | ||
|
|
d449fc8fd8 | ||
|
|
b9ee77709b | ||
|
|
f594ba4c69 | ||
|
|
d1d65d878c | ||
|
|
3194a7580d | ||
|
|
ba061df1b6 | ||
|
|
7cc515bcdf | ||
|
|
724748d38a | ||
|
|
b2c1c6e301 | ||
|
|
987be4b04d | ||
|
|
ca84da68c4 | ||
|
|
d75e39fbcd | ||
|
|
eb2593aacd | ||
|
|
496e04cfc8 | ||
|
|
d814d13d54 | ||
|
|
d0cedaf7a1 | ||
|
|
01f504f7b1 | ||
|
|
c716346f1f | ||
|
|
fef5236931 | ||
|
|
b115c37eb8 | ||
|
|
1e17f3703a | ||
|
|
468b986314 | ||
|
|
a531d135b5 | ||
|
|
7524609cd0 | ||
|
|
a28f8e65d5 | ||
|
|
d193637091 | ||
|
|
0953af05fc | ||
|
|
19e8e5cb5b | ||
|
|
43c808380d | ||
|
|
7ab8b84044 | ||
|
|
d739fe6752 | ||
|
|
a84c41e29f | ||
|
|
393aba1f31 | ||
|
|
436a070730 | ||
|
|
2fe6788ce5 | ||
|
|
747d146389 | ||
|
|
efe4c4043d | ||
|
|
c6739ba8e0 | ||
|
|
50140db668 | ||
|
|
028b2dfb22 | ||
|
|
ec6a10ca0a | ||
|
|
3cf949bf8d | ||
|
|
0a62225797 | ||
|
|
a54f4e1367 | ||
|
|
bf3c30a8fb | ||
|
|
f811f5996e | ||
|
|
a3490240f4 | ||
|
|
b26aea96f4 | ||
|
|
4d4af5fdf2 | ||
|
|
3da74505d6 | ||
|
|
c8a4861df8 | ||
|
|
5e27cd606e | ||
|
|
a341fd8ebe | ||
|
|
9a62b6e4e7 | ||
|
|
f80c44bca3 | ||
|
|
09d2e9f831 | ||
|
|
4d5a9e446f | ||
|
|
6a2c27749f | ||
|
|
de60e12073 | ||
|
|
1188ed9227 | ||
|
|
cb708e7e47 | ||
|
|
215eadb4a0 | ||
|
|
4ffc54f720 | ||
|
|
21f6c7a21f | ||
|
|
ce7c6939d2 | ||
|
|
40a2f7ff90 | ||
|
|
4015517c0a | ||
|
|
7c8d41753c | ||
|
|
90670613c5 | ||
|
|
647c1678f1 | ||
|
|
44dee16e0a | ||
|
|
f8fedcac82 | ||
|
|
3a48d0e580 | ||
|
|
9930789aa8 | ||
|
|
83fce6461a | ||
|
|
f0d37244b6 | ||
|
|
386834f409 | ||
|
|
17c5084bc0 | ||
|
|
e38f50c352 | ||
|
|
c1abff8da0 | ||
|
|
625c04257e | ||
|
|
5521c29d43 | ||
|
|
dc3a530928 | ||
|
|
48f63b4d9f | ||
|
|
1604ae51de | ||
|
|
a1502bffd1 | ||
|
|
756e5ec668 | ||
|
|
b9cf0a7136 | ||
|
|
6bf72c4043 | ||
|
|
f2f8342b49 | ||
|
|
7d82393789 | ||
|
|
2254d6f072 | ||
|
|
8d02cad7d9 | ||
|
|
5c12d00f49 | ||
|
|
b37fc4e24f | ||
|
|
35a7f62837 | ||
|
|
ffc1c5a99c | ||
|
|
fc2a60a4ba | ||
|
|
fb0f424d82 | ||
|
|
ffb5291f4b | ||
|
|
77ba482b79 | ||
|
|
abb0be69d8 | ||
|
|
7bb23e8362 | ||
|
|
cbb659da41 | ||
|
|
52b0382243 | ||
|
|
3371dc949a | ||
|
|
49f026f2bd | ||
|
|
cce373a522 | ||
|
|
b4b3e659de | ||
|
|
f81500ec99 | ||
|
|
ecba13e97f | ||
|
|
191a6c0d9b | ||
|
|
52ba2be586 | ||
|
|
36129b29b4 | ||
|
|
99e3690a42 | ||
|
|
c780f81dd8 | ||
|
|
27f5e85e11 | ||
|
|
e6d9ffbb9c | ||
|
|
3b188c3c55 | ||
|
|
161e70dc9c | ||
|
|
1f80df262b | ||
|
|
9928675f48 | ||
|
|
3d925b29c2 | ||
|
|
4825317a58 | ||
|
|
9a5408e996 | ||
|
|
f13c1a2605 | ||
|
|
bc8aadbe4e | ||
|
|
e60843b54c | ||
|
|
46dce472db | ||
|
|
556ca1bcb1 | ||
|
|
d9b2fcaa87 | ||
|
|
3e950602a7 | ||
|
|
1fe0757f6c | ||
|
|
b6cf1cf5e6 | ||
|
|
ca7d487789 | ||
|
|
cb44136b2e | ||
|
|
c92331a79c | ||
|
|
82e7118757 | ||
|
|
6d9817183e | ||
|
|
0e05d5b18d | ||
|
|
da1d88314b | ||
|
|
c46f22d71e | ||
|
|
f21de5eddc | ||
|
|
e88fb88d8a | ||
|
|
6eb14daf4d | ||
|
|
fad40dab6c | ||
|
|
015e01afb9 | ||
|
|
2acdd16d9e | ||
|
|
d15162337f | ||
|
|
0862c0f0bc | ||
|
|
a811d4a55c | ||
|
|
01a53ad8ec | ||
|
|
c7e20716f5 | ||
|
|
7adc4ad50a | ||
|
|
61ded5094f | ||
|
|
7aff5dc44a | ||
|
|
b5e5ff9bf8 | ||
|
|
a8434ce745 | ||
|
|
cf926295cf | ||
|
|
dbd7ae4adc | ||
|
|
ba20fa1ff5 | ||
|
|
a5b92f5672 | ||
|
|
ed412d11b7 | ||
|
|
b36d0620e0 | ||
|
|
d16d77f640 | ||
|
|
d72f90b90e | ||
|
|
9c78bcd662 | ||
|
|
b8c8fc3b58 | ||
|
|
e1110000ab | ||
|
|
00194f68bf | ||
|
|
4f4c324c30 | ||
|
|
106129e779 | ||
|
|
c5d509bf9e | ||
|
|
8b0f9bc2e7 | ||
|
|
4db17874c4 | ||
|
|
f6c491a8e6 | ||
|
|
e4a9f56352 | ||
|
|
c1287407a3 | ||
|
|
ba1e18410a | ||
|
|
7f8e29f1bc | ||
|
|
6334bee608 | ||
|
|
681c57201a | ||
|
|
738f0781b2 | ||
|
|
6143e31e1a | ||
|
|
d6e6ab24c2 | ||
|
|
0492182803 | ||
|
|
22713d884e | ||
|
|
bd14b77f62 | ||
|
|
6a89ed1bb6 | ||
|
|
25717f6a79 | ||
|
|
d3ecd52fd2 | ||
|
|
1830eb4edc | ||
|
|
81a8734fac | ||
|
|
abcef54e72 | ||
|
|
e15c92cda5 | ||
|
|
45dba6fad2 | ||
|
|
f67bb3cb98 | ||
|
|
53b584da56 | ||
|
|
58fc26904b | ||
|
|
7527646319 | ||
|
|
d3b1139a22 | ||
|
|
f04a51c1ad | ||
|
|
7fbff9f3b5 | ||
|
|
bb0f3e1778 | ||
|
|
6ab8d6bd0d | ||
|
|
69a51e0640 | ||
|
|
1425e795ff | ||
|
|
afadc61d5d | ||
|
|
ce8524b247 | ||
|
|
fd09ae1510 | ||
|
|
9137fbfb97 | ||
|
|
f0ac55c20e | ||
|
|
249663bd91 | ||
|
|
55920501b8 | ||
|
|
cc3e00e75f | ||
|
|
661f7ae789 | ||
|
|
8bfbd96398 | ||
|
|
8a051b531d | ||
|
|
de9456e3d7 | ||
|
|
950315936e | ||
|
|
af1bc19fd8 | ||
|
|
906da25301 | ||
|
|
fe1ddf1237 | ||
|
|
48c90c483a | ||
|
|
3c1b6a5f3a | ||
|
|
780c929162 | ||
|
|
e00b6b9293 | ||
|
|
8c9ee37c46 | ||
|
|
45a0bda758 | ||
|
|
e71417e77f | ||
|
|
29e6eda9cd | ||
|
|
32c984c7f0 | ||
|
|
b68d2ba384 | ||
|
|
daf0be37fd | ||
|
|
2e625715cc | ||
|
|
6a25428b3c | ||
|
|
cb78f75f19 | ||
|
|
77cfcb4602 | ||
|
|
d2a4a9d953 | ||
|
|
9280540927 | ||
|
|
2f77532111 | ||
|
|
2149f4034b | ||
|
|
76eeed1a77 | ||
|
|
ad0d802e41 | ||
|
|
e41464cb31 | ||
|
|
ab3f7bf671 | ||
|
|
e968a57c06 | ||
|
|
641feede74 | ||
|
|
b48708652f | ||
|
|
c2addc1121 | ||
|
|
a25109e16c | ||
|
|
ae81b10dbd | ||
|
|
4d6d84bf5b | ||
|
|
a8a132e2a1 | ||
|
|
3b0413c30e | ||
|
|
d767743b64 | ||
|
|
e8f7caebd1 | ||
|
|
a7b7272bec | ||
|
|
d7402f60c5 | ||
|
|
d049cf6d3d | ||
|
|
fdcdf6a026 | ||
|
|
7e38e946a5 | ||
|
|
b552badff7 | ||
|
|
d10c84b66e | ||
|
|
e7f8d58a7d | ||
|
|
528f329ebb | ||
|
|
b9b7a125f0 | ||
|
|
4742056223 | ||
|
|
ba4c3b95e5 | ||
|
|
4c03520371 | ||
|
|
1f5ddd9af7 | ||
|
|
d3e6b34a63 | ||
|
|
323f424630 | ||
|
|
eed6e9d3a5 | ||
|
|
f4af7ffb0b | ||
|
|
3b072d5dd9 | ||
|
|
11240dcf48 | ||
|
|
0b5fc1a9f4 | ||
|
|
049449bda3 | ||
|
|
e5a19302f0 | ||
|
|
e1fa939757 | ||
|
|
3da33e364e | ||
|
|
bfaed434cc | ||
|
|
b6acc17e5a | ||
|
|
5fd03e7cdc | ||
|
|
54e71f2910 | ||
|
|
c99c944130 | ||
|
|
94c9185bcf | ||
|
|
74e731e334 | ||
|
|
d01f7409bf | ||
|
|
29ab6cfb2d | ||
|
|
59b2da933d | ||
|
|
99b5f9a3ec | ||
|
|
9057eac42c | ||
|
|
24b5cdff85 | ||
|
|
f2630c3ba0 | ||
|
|
21740522bc | ||
|
|
47090ce863 | ||
|
|
3ac22c08ff | ||
|
|
cc62b088fd | ||
|
|
2c34425135 | ||
|
|
205f76d128 | ||
|
|
4147bc61c7 | ||
|
|
dfae453925 | ||
|
|
7507cae44c | ||
|
|
28312774bd | ||
|
|
058723d583 | ||
|
|
db4abdd31d | ||
|
|
727b0e9e61 | ||
|
|
aa41146735 | ||
|
|
670fc9bf35 | ||
|
|
d9a5649adc | ||
|
|
5ed300a3ea | ||
|
|
59cc22a877 | ||
|
|
8dffc07072 | ||
|
|
76c7ad1ff5 | ||
|
|
7f391c25a4 | ||
|
|
bccc41d177 | ||
|
|
cc882082d2 | ||
|
|
689918c1ac | ||
|
|
1c43be3899 | ||
|
|
40387428e7 | ||
|
|
46fb02376e | ||
|
|
24e43e3e2e | ||
|
|
846c660811 | ||
|
|
beb4aa634f | ||
|
|
58c6077925 | ||
|
|
d7675d4b80 | ||
|
|
e2b1115b3b | ||
|
|
96c963795e | ||
|
|
804adde964 | ||
|
|
5aa918f478 | ||
|
|
a44f72a030 | ||
|
|
ad163509b4 | ||
|
|
fb58d35029 | ||
|
|
79f823cd62 | ||
|
|
c42266b82c | ||
|
|
331d85a993 | ||
|
|
c60c3f1876 | ||
|
|
fc5455a0f2 | ||
|
|
28d8f62af7 | ||
|
|
b6b505c361 | ||
|
|
97cef449c9 | ||
|
|
fef6f695ce | ||
|
|
73a24a8ef0 | ||
|
|
e727cae020 | ||
|
|
c6dd55df4e | ||
|
|
6962b0e218 | ||
|
|
894d2d2e6b | ||
|
|
8bf4a32dfd | ||
|
|
505650518e | ||
|
|
35f3ecc7eb | ||
|
|
543e52d596 | ||
|
|
f39433142d | ||
|
|
f2765c75c6 | ||
|
|
47049808b7 | ||
|
|
150d4c7309 | ||
|
|
d116d08adf | ||
|
|
82d2e479b2 | ||
|
|
df81aec02e | ||
|
|
74779fc488 | ||
|
|
ac9922ff61 | ||
|
|
ff0cd6fa93 | ||
|
|
777f4518be | ||
|
|
84591fd17a | ||
|
|
7536425e39 | ||
|
|
9d28ce48fe | ||
|
|
d6b438b5f4 | ||
|
|
87d6ca0200 | ||
|
|
bcda57a4fa | ||
|
|
3e55207a8d | ||
|
|
80eee945a0 | ||
|
|
3436ef4877 | ||
|
|
20e9d4a990 | ||
|
|
3a1c9aa462 | ||
|
|
de9f0ad8f8 | ||
|
|
61f43f78ec | ||
|
|
a3f2c1bed2 | ||
|
|
e0a0eeeecc | ||
|
|
4a4dafd69c | ||
|
|
6781128c1b | ||
|
|
73b7f60222 | ||
|
|
46a9d19374 | ||
|
|
6ba1ff4505 | ||
|
|
58c5b2c301 | ||
|
|
5d1d6d4248 | ||
|
|
0f251bee9b | ||
|
|
149c5b5f5e | ||
|
|
7d051336d3 | ||
|
|
79da8db889 | ||
|
|
ec842aa657 | ||
|
|
61c2d5eb61 | ||
|
|
41e3ec41e9 | ||
|
|
086570ce90 | ||
|
|
d2783429a1 | ||
|
|
de19a10cba | ||
|
|
f312631676 | ||
|
|
6c52b7bbd9 | ||
|
|
900f1a6f7a | ||
|
|
ff0a7c5262 | ||
|
|
e0acd1de83 | ||
|
|
585c31490a | ||
|
|
3e7f96c0b8 | ||
|
|
d45adc1688 | ||
|
|
c857d092b1 | ||
|
|
b0fe98c091 | ||
|
|
103878e107 | ||
|
|
175fca2b39 | ||
|
|
4600aab13a | ||
|
|
966a107414 | ||
|
|
69674e2648 | ||
|
|
bcd2e44493 | ||
|
|
e745e4be0c | ||
|
|
3afd18ccdc | ||
|
|
24f1fb228e | ||
|
|
431e213514 | ||
|
|
1e00fa16db | ||
|
|
ac1c283efb | ||
|
|
0a6a8b760f | ||
|
|
4cdd784259 | ||
|
|
461cb20a4f | ||
|
|
7ebf4d5e2a | ||
|
|
e50d3233fd | ||
|
|
cc980b2e8a | ||
|
|
93e965697a | ||
|
|
8d65d20d1f | ||
|
|
a112824578 | ||
|
|
6192277778 | ||
|
|
148324b37f | ||
|
|
c30ce471c2 | ||
|
|
63cfa14a21 | ||
|
|
53c715b6f6 | ||
|
|
96146a388a | ||
|
|
d2a0bb1ec1 | ||
|
|
d826b9f38a | ||
|
|
e8d9cc6ad9 | ||
|
|
e9689d347c | ||
|
|
b275fdcf62 | ||
|
|
a0ebc47ade | ||
|
|
b698fad83a | ||
|
|
5e53c66eaa | ||
|
|
37008ef290 | ||
|
|
35ee5847ca | ||
|
|
935dee853e | ||
|
|
7b75e279b0 | ||
|
|
15c758b24a | ||
|
|
26ec1724a5 | ||
|
|
96c4823664 | ||
|
|
5ab19b7958 | ||
|
|
09716f2b00 | ||
|
|
138a29770a | ||
|
|
36584346cb | ||
|
|
c7dd5dd8bb | ||
|
|
a16ad2c887 | ||
|
|
ca728b45ca | ||
|
|
9fd87dbf23 | ||
|
|
384a49b1c6 | ||
|
|
477236009c | ||
|
|
93cff8873e | ||
|
|
d9feb61e85 | ||
|
|
00875c0d8e | ||
|
|
f1b7ed7d7a | ||
|
|
fce293e722 | ||
|
|
09062cb12c | ||
|
|
098f88e0b8 | ||
|
|
6992bf83aa | ||
|
|
32044907bf | ||
|
|
3fcd613ca8 | ||
|
|
5b8a22762b | ||
|
|
c41c319d25 | ||
|
|
6690c3b206 | ||
|
|
56bcd4f887 | ||
|
|
47c690526e | ||
|
|
ec14338159 | ||
|
|
bf3fe1c716 | ||
|
|
fede79fc04 | ||
|
|
9251613cd6 | ||
|
|
0bd6df9d57 | ||
|
|
24e660156c | ||
|
|
345ffe4d6d | ||
|
|
e5b7cf5f30 | ||
|
|
b563447674 | ||
|
|
523a2b41d1 | ||
|
|
a0741f6ad3 | ||
|
|
b52c3d6bd4 | ||
|
|
803369a7a6 | ||
|
|
2e3e629406 | ||
|
|
d7894e07e9 | ||
|
|
63dbdfa4a6 | ||
|
|
961b3f07b5 | ||
|
|
7a1ee9a9b2 | ||
|
|
f18980a9e2 | ||
|
|
08733751aa | ||
|
|
b271f81af2 | ||
|
|
0900e4c57d | ||
|
|
d99e523608 | ||
|
|
50829dce47 | ||
|
|
910dc29f06 | ||
|
|
486c871cb5 | ||
|
|
2b94500ffe | ||
|
|
d25ea34512 | ||
|
|
fbc3dcdfef | ||
|
|
642015b368 | ||
|
|
99f06955dc | ||
|
|
9e5a7b2cc0 | ||
|
|
948eb9be3e | ||
|
|
ec778edb93 | ||
|
|
a431031c04 | ||
|
|
082a656210 | ||
|
|
9f51b9fd16 | ||
|
|
98aadf2869 | ||
|
|
54107000af | ||
|
|
999fe2bc61 | ||
|
|
23bd0a7d90 | ||
|
|
f9059f636c | ||
|
|
95aff5c998 | ||
|
|
bf9b8a0230 | ||
|
|
c79432567c | ||
|
|
ddc484562b | ||
|
|
97b5f64718 | ||
|
|
b042ab72cd | ||
|
|
a59ac44f3b | ||
|
|
acafcbc077 | ||
|
|
6ff0e3b7b3 | ||
|
|
bb43ed203a | ||
|
|
1bb412e007 | ||
|
|
e69d1c3408 | ||
|
|
cd51d12618 | ||
|
|
ee130f9077 | ||
|
|
0eebd438ca | ||
|
|
983d40f2c1 | ||
|
|
bbd01fdb04 | ||
|
|
ea2f493e01 | ||
|
|
9b364d57c7 | ||
|
|
068a09e28e | ||
|
|
83c7e318ea | ||
|
|
24ed6a1cd2 | ||
|
|
816ced83b5 | ||
|
|
b93fb99e1b | ||
|
|
9203b8e985 | ||
|
|
7b936ec4fd | ||
|
|
99f0ab830b | ||
|
|
34028587fc | ||
|
|
df0cfc3677 | ||
|
|
16e2af8c5d | ||
|
|
02aec7d6d6 | ||
|
|
cb913f6cea | ||
|
|
5bb20bd479 | ||
|
|
c561ddc08c | ||
|
|
fd3743377b | ||
|
|
381c3bf3fa | ||
|
|
5d37a1dc0b | ||
|
|
cf07040ece | ||
|
|
f2028ee928 | ||
|
|
0c39ddcf66 | ||
|
|
8ddbc34017 | ||
|
|
6ef06b2650 | ||
|
|
67581c7fa4 | ||
|
|
bc1f28eda6 | ||
|
|
61daf9d5c9 | ||
|
|
a37c77bb84 | ||
|
|
6d2c48a1c8 | ||
|
|
bed5b72864 | ||
|
|
325d6e4326 | ||
|
|
f7ff700c7a | ||
|
|
41c8e53569 | ||
|
|
ff8e431630 | ||
|
|
eb9b2ac6fe | ||
|
|
1ad468e652 | ||
|
|
986bda0c81 | ||
|
|
bb361001b9 | ||
|
|
26aa0207aa | ||
|
|
8b1bd3c555 | ||
|
|
b59c7288b1 | ||
|
|
f5b456018d | ||
|
|
4dad26102a | ||
|
|
afc7718c95 | ||
|
|
e5ef19ffe4 | ||
|
|
ecf065db2b | ||
|
|
4c03d1eb87 | ||
|
|
b71e9fe57d | ||
|
|
7ab6276397 | ||
|
|
c7da37e7e7 | ||
|
|
00f9bc087c | ||
|
|
f2c658cb2d | ||
|
|
c35f71370e | ||
|
|
edb9c883f7 | ||
|
|
0405c123f4 | ||
|
|
b84a330883 | ||
|
|
2d8c6ef44a | ||
|
|
6af5f59c80 | ||
|
|
3c4384e2f6 | ||
|
|
e50239f067 | ||
|
|
4fa6919ca0 | ||
|
|
db6fe4256f | ||
|
|
8a73f018f0 | ||
|
|
b93b16d6eb | ||
|
|
6acf4bb831 | ||
|
|
86134eecb4 | ||
|
|
3716e2bb0f | ||
|
|
b5e08a4828 | ||
|
|
976cedd536 | ||
|
|
4af5a4e96e | ||
|
|
9044f9e1ff | ||
|
|
4b719af4e1 | ||
|
|
78fa5338d3 | ||
|
|
e9f2b875b9 | ||
|
|
fe3f817bc5 | ||
|
|
32f5cf64e5 | ||
|
|
5aadb66013 | ||
|
|
6225648e3a | ||
|
|
29903af085 | ||
|
|
8ed2562454 | ||
|
|
fd255fd6ad | ||
|
|
8931fa8557 | ||
|
|
251bd88f70 | ||
|
|
2ac076afa5 | ||
|
|
2d82fc1ddd | ||
|
|
ba9d85dfc9 | ||
|
|
c752b2e81b | ||
|
|
19df1cf65d | ||
|
|
ebdd8fc053 | ||
|
|
924576c8ba | ||
|
|
f4fa28bfbc | ||
|
|
0c2cb599ba | ||
|
|
54f85196e7 | ||
|
|
a1093ed918 | ||
|
|
caa33810c4 | ||
|
|
fd8229684c | ||
|
|
320d94a223 | ||
|
|
43ccc351c7 | ||
|
|
d36e4c6e0a | ||
|
|
fdeede5717 | ||
|
|
738b601462 | ||
|
|
2c93a2f177 | ||
|
|
6b2d164585 | ||
|
|
ee707eba5c | ||
|
|
f26b09cc0a | ||
|
|
4e88f846af | ||
|
|
6a1d892e8b | ||
|
|
b90c70b2a3 | ||
|
|
bcf50f30bc | ||
|
|
065ed6c437 | ||
|
|
285e09f40a | ||
|
|
0398f36949 | ||
|
|
ea30eb96cd | ||
|
|
b787ae49bb | ||
|
|
f8e2283a69 | ||
|
|
13d51a7b46 | ||
|
|
e74ae06b64 | ||
|
|
aa495250c9 | ||
|
|
f8ee48c23b | ||
|
|
320246b18b | ||
|
|
00992da998 | ||
|
|
2b9ad2feed | ||
|
|
257127bd4e | ||
|
|
b1df118140 | ||
|
|
da6b437b20 | ||
|
|
6fe4c79b0d | ||
|
|
1793753cb4 | ||
|
|
9ed1aff0d2 | ||
|
|
51c3ec5762 | ||
|
|
5feeabb498 | ||
|
|
c4aa3eb019 | ||
|
|
e8b9f473a6 | ||
|
|
279b4dc025 | ||
|
|
6a1226ca26 | ||
|
|
b9ee7d53fa | ||
|
|
ace7ee4274 | ||
|
|
16968db1cf | ||
|
|
2b24155dd2 | ||
|
|
5a7c914fe7 | ||
|
|
f822e03be0 | ||
|
|
1bdf14dbf9 | ||
|
|
6ef173d82d | ||
|
|
1e471ad40d | ||
|
|
4ff1a6bc93 | ||
|
|
7d1f47edc5 | ||
|
|
f69d7898d5 | ||
|
|
9692e2386b | ||
|
|
93b2e2d7e4 | ||
|
|
8b2833f353 | ||
|
|
643dbbc294 | ||
|
|
c4273a4c3f | ||
|
|
95461316a5 | ||
|
|
1775b64ba4 | ||
|
|
5a9270373f | ||
|
|
37f98ce9fe | ||
|
|
fa556c9a7f | ||
|
|
29e1d1286c | ||
|
|
f489043077 | ||
|
|
bdd004518c | ||
|
|
840f5ec60d | ||
|
|
566eea1d75 | ||
|
|
bb48655acb | ||
|
|
d723165b1c | ||
|
|
592bd4f11e | ||
|
|
0aec23fcdd | ||
|
|
a23dc717aa | ||
|
|
d364994ed7 | ||
|
|
a38ed28512 | ||
|
|
1f5c02bcc3 | ||
|
|
f4afdfbc07 | ||
|
|
f753b63b13 | ||
|
|
6f3068a28c | ||
|
|
aa57b47d18 | ||
|
|
113e9ef1e3 | ||
|
|
5899527621 | ||
|
|
0a40de0f14 | ||
|
|
bc31f013c0 | ||
|
|
e7fc15dc72 | ||
|
|
79396cec9e | ||
|
|
5e07c6130f | ||
|
|
94e1fdfbff | ||
|
|
a0d414c83f | ||
|
|
1441368465 | ||
|
|
6f301c4771 | ||
|
|
ec31d251ea | ||
|
|
289625923f | ||
|
|
a42a76a2cf | ||
|
|
fd1216cd22 | ||
|
|
3f6a342026 | ||
|
|
f72fc699f8 | ||
|
|
cdcca80196 | ||
|
|
400cd2f6a0 | ||
|
|
37a4821d01 | ||
|
|
d165075a96 | ||
|
|
a062173ebd | ||
|
|
806963c396 | ||
|
|
dc46502667 | ||
|
|
ac58f1959d | ||
|
|
f4543f8d65 | ||
|
|
d0ef5e27df | ||
|
|
6fd9cf0d8c | ||
|
|
1e800889e4 | ||
|
|
652b4bf2af |
@@ -14,5 +14,4 @@ LICENSE
|
||||
.idea
|
||||
LICENSE.md
|
||||
docs
|
||||
nginx
|
||||
update.sh
|
||||
@@ -5,26 +5,31 @@ DEBUG=0
|
||||
# hosts the application can run under e.g. recipes.mydomain.com,cooking.mydomain.com,...
|
||||
ALLOWED_HOSTS=*
|
||||
|
||||
# random secret key, use for example base64 /dev/urandom | head -c50 to generate one
|
||||
# random secret key, use for example `base64 /dev/urandom | head -c50` to generate one
|
||||
SECRET_KEY=
|
||||
|
||||
# your default timezone
|
||||
# your default timezone See https://timezonedb.com/time-zones for a list of timezones
|
||||
TIMEZONE=Europe/Berlin
|
||||
|
||||
# add only a database password if you want to run with the default postgres, otherwise change settings accordingly
|
||||
DB_ENGINE=django.db.backends.postgresql
|
||||
# DB_OPTIONS= {} # e.g. {"sslmode":"require"} to enable ssl
|
||||
POSTGRES_HOST=db_recipes
|
||||
POSTGRES_PORT=5432
|
||||
POSTGRES_USER=djangodb
|
||||
POSTGRES_USER=djangouser
|
||||
POSTGRES_PASSWORD=
|
||||
POSTGRES_DB=djangodb
|
||||
|
||||
# database connection string, when used overrides other database settings.
|
||||
# format might vary depending on backend
|
||||
# DATABASE_URL = engine://username:password@host:port/dbname
|
||||
|
||||
# the default value for the user preference 'fractions' (enable/disable fraction support)
|
||||
# when unset: 0 (disabled)
|
||||
# default: disabled=0
|
||||
FRACTION_PREF_DEFAULT=0
|
||||
|
||||
# the default value for the user preference 'comments' (enable/disable commenting system)
|
||||
# when unset: 1 (true)
|
||||
# default comments enabled=1
|
||||
COMMENT_PREF_DEFAULT=1
|
||||
|
||||
# Users can set a amount of time after which the shopping list is refreshed when they are in viewing mode
|
||||
@@ -32,6 +37,9 @@ COMMENT_PREF_DEFAULT=1
|
||||
# might cause high load on the server. (Technically they can obviously refresh as often as they want with their own scripts)
|
||||
SHOPPING_MIN_AUTOSYNC_INTERVAL=5
|
||||
|
||||
# Default for user setting sticky navbar
|
||||
# STICKY_NAV_PREF_DEFAULT=1
|
||||
|
||||
# If staticfiles are stored at a different location uncomment and change accordingly
|
||||
# STATIC_URL=/static/
|
||||
|
||||
@@ -44,9 +52,63 @@ SHOPPING_MIN_AUTOSYNC_INTERVAL=5
|
||||
# when unset: 1 (true) - this is temporary until an appropriate amount of time has passed for everyone to migrate
|
||||
GUNICORN_MEDIA=0
|
||||
|
||||
# allow authentication via reverse proxy (e.g. authelia), leave of if you dont know what you are doing
|
||||
# docs: https://github.com/vabene1111/recipes/tree/develop/docs/docker/nginx-proxy%20with%20proxy%20authentication
|
||||
# S3 Media settings: store mediafiles in s3 or any compatible storage backend (e.g. minio)
|
||||
# as long as S3_ACCESS_KEY is not set S3 features are disabled
|
||||
# S3_ACCESS_KEY=
|
||||
# S3_SECRET_ACCESS_KEY=
|
||||
# S3_BUCKET_NAME=
|
||||
# S3_REGION_NAME= # default none, set your region might be required
|
||||
# S3_QUERYSTRING_AUTH=1 # default true, set to 0 to serve media from a public bucket without signed urls
|
||||
# S3_QUERYSTRING_EXPIRE=3600 # number of seconds querystring are valid for
|
||||
# S3_ENDPOINT_URL= # when using a custom endpoint like minio
|
||||
|
||||
# Email Settings, see https://docs.djangoproject.com/en/3.2/ref/settings/#email-host
|
||||
# Required for email confirmation and password reset (automatically activates if host is set)
|
||||
# EMAIL_HOST=
|
||||
# EMAIL_PORT=
|
||||
# EMAIL_HOST_USER=
|
||||
# EMAIL_HOST_PASSWORD=
|
||||
# EMAIL_USE_TLS=0
|
||||
# EMAIL_USE_SSL=0
|
||||
# DEFAULT_FROM_EMAIL= # email sender address (default 'webmaster@localhost')
|
||||
# ACCOUNT_EMAIL_SUBJECT_PREFIX= # prefix used for account related emails (default "[Tandoor Recipes] ")
|
||||
|
||||
# allow authentication via reverse proxy (e.g. authelia), leave off if you dont know what you are doing
|
||||
# see docs for more information https://vabene1111.github.io/recipes/features/authentication/
|
||||
# when unset: 0 (false)
|
||||
REVERSE_PROXY_AUTH=0
|
||||
|
||||
# Default settings for spaces, apply per space and can be changed in the admin view
|
||||
# SPACE_DEFAULT_MAX_RECIPES=0 # 0=unlimited recipes
|
||||
# SPACE_DEFAULT_MAX_USERS=0 # 0=unlimited users per space
|
||||
# SPACE_DEFAULT_FILES=1 # 1=can upload files (images, etc.) NOT IMPLEMENTED YET
|
||||
|
||||
# allow people to create accounts on your application instance (without an invite link)
|
||||
# when unset: 0 (false)
|
||||
# ENABLE_SIGNUP=0
|
||||
|
||||
# If signup is enabled you might want to add a captcha to it to prevent spam
|
||||
# HCAPTCHA_SITEKEY=
|
||||
# HCAPTCHA_SECRET=
|
||||
|
||||
# if signup is enabled you might want to provide urls to data protection policies or terms and conditions
|
||||
# TERMS_URL=
|
||||
# PRIVACY_URL=
|
||||
# IMPRINT_URL=
|
||||
|
||||
# enable serving of prometheus metrics under the /metrics path
|
||||
# ATTENTION: view is not secured (as per the prometheus default way) so make sure to secure it
|
||||
# trough your web server (or leave it open of you dont care if the stats are exposed)
|
||||
# ENABLE_METRICS=0
|
||||
|
||||
# allows you to setup OAuth providers
|
||||
# see docs for more information https://vabene1111.github.io/recipes/features/authentication/
|
||||
# SOCIAL_PROVIDERS = allauth.socialaccount.providers.github, allauth.socialaccount.providers.nextcloud,
|
||||
|
||||
# Should a newly created user from a social provider get assigned to the default space and given permission by default ?
|
||||
# ATTENTION: This feature might be deprecated in favor of a space join and public viewing system in the future
|
||||
# default 0 (false), when 1 (true) users will be assigned space and group
|
||||
# SOCIAL_DEFAULT_ACCESS = 1
|
||||
|
||||
# if SOCIAL_DEFAULT_ACCESS is used, which group should be added
|
||||
# SOCIAL_DEFAULT_GROUP=guest
|
||||
18
.github/ISSUE_TEMPLATE/help-request.md
vendored
18
.github/ISSUE_TEMPLATE/help-request.md
vendored
@@ -6,14 +6,16 @@ labels: setup issue
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
### Version
|
||||
Please provide your current version (can be found on the system page since v0.8.4)
|
||||
Version:
|
||||
|
||||
### Issue
|
||||
## Issue
|
||||
Please describe your problem here
|
||||
|
||||
|
||||
## Setup Info
|
||||
Version: (can be found on the system page since v0.8.4)
|
||||
OS: e.g. Ubuntu 20.02
|
||||
|
||||
Other relevant information regarding your problem (proxies, firewalls, etc.)
|
||||
|
||||
### `.env`
|
||||
Please include your `.env` config file (**make sure to remove/replace all secrets**)
|
||||
```
|
||||
@@ -25,3 +27,7 @@ When running with docker compose please provide your `docker-compose.yml`
|
||||
```
|
||||
docker-compose.yml content
|
||||
```
|
||||
|
||||
### Logs
|
||||
If you feel like there is anything interesting please post the output of `docker-compose logs` at
|
||||
container startup and when the issue happens.
|
||||
22
.github/ISSUE_TEMPLATE/url_import.md
vendored
Normal file
22
.github/ISSUE_TEMPLATE/url_import.md
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
name: Website Import
|
||||
about: Anything related to website imports
|
||||
title: ''
|
||||
labels: enhancement, url_import
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
### Version
|
||||
Please provide your current version (can be found on the system page since v0.8.4)
|
||||
Version:
|
||||
|
||||
### Information
|
||||
Exact URL you are trying to import from:
|
||||
|
||||
When did the issue happen: When pressing the search button with the url / when importing after the page has loaded
|
||||
|
||||
Response/Message shown
|
||||
```
|
||||
Message
|
||||
```
|
||||
9
.github/workflows/ci.yml
vendored
9
.github/workflows/ci.yml
vendored
@@ -9,19 +9,20 @@ jobs:
|
||||
strategy:
|
||||
max-parallel: 4
|
||||
matrix:
|
||||
python-version: [3.8]
|
||||
python-version: [3.9]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Set up Python 3.8
|
||||
- name: Set up Python 3.9
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: 3.8
|
||||
python-version: 3.9
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
python3 manage.py collectstatic --noinput
|
||||
python3 manage.py collectstatic_js_reverse
|
||||
- name: Django Testing project
|
||||
run: |
|
||||
python3 manage.py test
|
||||
pytest
|
||||
|
||||
64
.github/workflows/codeql-analysis.yml
vendored
64
.github/workflows/codeql-analysis.yml
vendored
@@ -12,40 +12,42 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
# We must fetch at least the immediate parents so that if this is
|
||||
# a pull request then we can checkout the head.
|
||||
fetch-depth: 2
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
# We must fetch at least the immediate parents so that if this is
|
||||
# a pull request then we can checkout the head.
|
||||
fetch-depth: 2
|
||||
|
||||
# If this run was triggered by a pull request event, then checkout
|
||||
# the head of the pull request instead of the merge commit.
|
||||
- run: git checkout HEAD^2
|
||||
if: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
# Override language selection by uncommenting this and choosing your languages
|
||||
# with:
|
||||
# languages: go, javascript, csharp, python, cpp, java
|
||||
# If this run was triggered by a pull request event, then checkout
|
||||
# the head of the pull request instead of the merge commit.
|
||||
- run: git checkout HEAD^2
|
||||
if: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
# - name: Autobuild
|
||||
# uses: github/codeql-action/autobuild@v1
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
# Override language selection by uncommenting this and choosing your languages
|
||||
with:
|
||||
languages: python, javascript
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
# - name: Autobuild
|
||||
# uses: github/codeql-action/autobuild@v1
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
with:
|
||||
languages: javascript, python
|
||||
|
||||
26
.github/workflows/docker-publish-beta.yml
vendored
Normal file
26
.github/workflows/docker-publish-beta.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
name: publish beta image docker
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'beta'
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- name: Update version file
|
||||
uses: DamianReeves/write-file-action@v1.0
|
||||
with:
|
||||
path: recipes/version.py
|
||||
contents: |
|
||||
VERSION_NUMBER = 'beta'
|
||||
BUILD_REF = '${{ github.sha }}'
|
||||
write-mode: overwrite
|
||||
- name: Build and publish image
|
||||
uses: ilteoood/docker_buildx@master
|
||||
with:
|
||||
publish: true
|
||||
imageName: vabene1111/recipes
|
||||
tag: beta
|
||||
dockerHubUser: ${{ secrets.DOCKER_USERNAME }}
|
||||
dockerHubPassword: ${{ secrets.DOCKER_PASSWORD }}
|
||||
17
.github/workflows/docs.yml
vendored
Normal file
17
.github/workflows/docs.yml
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
name: Make Docs
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- develop
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.x
|
||||
- run: pip install mkdocs-material
|
||||
- run: mkdocs gh-deploy --force
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -77,3 +77,5 @@ postgresql/
|
||||
|
||||
|
||||
/docker-compose.override.yml
|
||||
vue/node_modules
|
||||
.vscode/
|
||||
|
||||
4
.idea/dictionaries/vabene1111_PC.xml
generated
4
.idea/dictionaries/vabene1111_PC.xml
generated
@@ -2,9 +2,13 @@
|
||||
<dictionary name="vabene1111-PC">
|
||||
<words>
|
||||
<w>autosync</w>
|
||||
<w>chowdown</w>
|
||||
<w>csrftoken</w>
|
||||
<w>gunicorn</w>
|
||||
<w>ical</w>
|
||||
<w>mealie</w>
|
||||
<w>pepperplate</w>
|
||||
<w>safron</w>
|
||||
<w>traefik</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
|
||||
9
.idea/recipes.iml
generated
9
.idea/recipes.iml
generated
@@ -18,12 +18,8 @@
|
||||
<excludeFolder url="file://$MODULE_DIR$/staticfiles" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.8 (recipes)" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.9 (recipes)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="jquery-3.4.1" level="application" />
|
||||
<orderEntry type="library" name="pretty-checkbox" level="application" />
|
||||
<orderEntry type="library" name="pdf" level="application" />
|
||||
<orderEntry type="library" name="pdf_viewer" level="application" />
|
||||
</component>
|
||||
<component name="TemplatesService">
|
||||
<option name="TEMPLATE_CONFIGURATION" value="Django" />
|
||||
@@ -33,4 +29,7 @@
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="TestRunnerService">
|
||||
<option name="PROJECT_TEST_RUNNER" value="pytest" />
|
||||
</component>
|
||||
</module>
|
||||
31
.pre-commit-config.yaml
Normal file
31
.pre-commit-config.yaml
Normal file
@@ -0,0 +1,31 @@
|
||||
# See https://pre-commit.com for more information
|
||||
# See https://pre-commit.com/hooks.html for more hooks
|
||||
repos:
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: pre-commit-yarn-build
|
||||
name: Build javascript files
|
||||
entry: yarn --cwd ./vue build
|
||||
always_run: true
|
||||
language: system
|
||||
types: [ python ]
|
||||
pass_filenames: false
|
||||
|
||||
#- id: pre-commit-django-migrations
|
||||
# name: Check django migrations
|
||||
# entry: bash -c './venv/bin/activate && ./manage.py makemigrations --check'
|
||||
# language: system
|
||||
# types: [ python ]
|
||||
# pass_filenames: false
|
||||
# - id: pre-commit-django-make-messages
|
||||
# name: Make messages if necessary
|
||||
# entry: ./manage.py makemessages -i venv -a
|
||||
# language: system
|
||||
# types: [ python ]
|
||||
# pass_filenames: false
|
||||
# - id: pre-commit-django-compile-messages
|
||||
# name: Compile messages if necessary
|
||||
# entry: ./manage.py compilemessages -i venv
|
||||
# language: system
|
||||
# types: [ python ]
|
||||
# pass_filenames: false
|
||||
@@ -1,11 +1,63 @@
|
||||
Many thanks to everyone who contributed to this project!
|
||||
Many thanks to everyone who contributed to this project! If you add something or help out feel free to add yourself
|
||||
to this list.
|
||||
|
||||
## Code/Features
|
||||
Please have a look at the [list of pull requests](https://github.com/vabene1111/recipes/pulls) for
|
||||
a complete list of contributions.
|
||||
Below are some of the larger contributions made yet.
|
||||
|
||||
|
||||
- @tourn provided the serving feature and **several** other improvements!
|
||||
- @l0c4lh057 provided a much improved ingredient text parser in [#277](https://github.com/vabene1111/recipes/pull/277)
|
||||
- @sebimarkgraf added nutritional information [#199](https://github.com/vabene1111/recipes/pull/199)
|
||||
- @cazier added reverse proxy authentication [#88](https://github.com/vabene1111/recipes/pull/88)
|
||||
|
||||
## Translations
|
||||
|
||||
### Catalan
|
||||
[Rubenix](https://www.transifex.com/user/profile/rubenix/)
|
||||
|
||||
### Dutch
|
||||
[D0T1X](https://www.transifex.com/user/profile/D0T1X/)
|
||||
[D0T1X](https://www.transifex.com/user/profile/D0T1X/)
|
||||
[ikbenfrank](https://www.transifex.com/user/profile/ikbenfrank/)
|
||||
[kampsj](https://www.transifex.com/user/profile/kampsj/)
|
||||
|
||||
### French
|
||||
[jt117](https://www.transifex.com/user/profile/jt117/)
|
||||
[nerdinator](https://www.transifex.com/user/profile/nerdinator/)
|
||||
[nerdinator](https://www.transifex.com/user/profile/nerdinator/)
|
||||
[agaume](https://www.transifex.com/user/profile/agaume/)
|
||||
|
||||
### German
|
||||
[eTaurus](https://www.transifex.com/user/profile/eTaurus/)
|
||||
[l0c4lh057](https://www.transifex.com/user/profile/l0c4lh057/)
|
||||
|
||||
### Hungarian
|
||||
[igazka](https://www.transifex.com/user/profile/igazka/)
|
||||
|
||||
### Italian
|
||||
[SK3LA](https://www.transifex.com/user/profile/SK3LA/)
|
||||
[auanasgheps](https://www.transifex.com/user/profile/auanasgheps/)
|
||||
|
||||
### Latvian
|
||||
[melkypie](https://github.com/melkypie)
|
||||
|
||||
### Portuguese
|
||||
|
||||
[hds](https://www.transifex.com/user/profile/hds/)
|
||||
[mlopezifu](https://www.transifex.com/user/profile/mlopezifu/)
|
||||
[stormsz](https://www.transifex.com/user/profile/stormsz/)
|
||||
|
||||
### Spanish
|
||||
|
||||
[albertocp](https://www.transifex.com/user/profile/albertocp/)
|
||||
[alfa5](https://www.transifex.com/user/profile/alfa5/)
|
||||
[mlopezifu](https://www.transifex.com/user/profile/mlopezifu/)
|
||||
[sergio.laya](https://www.transifex.com/user/profile/sergio.laya/)
|
||||
|
||||
### Turkish
|
||||
|
||||
[batmanisnaked](https://www.transifex.com/user/profile/batmanisnaked/)
|
||||
|
||||
### Vietnamese
|
||||
|
||||
[vuongtrunghieu](https://www.transifex.com/user/profile/vuongtrunghieu/)
|
||||
22
Dockerfile
22
Dockerfile
@@ -1,18 +1,28 @@
|
||||
FROM python:3.8-alpine
|
||||
FROM python:3.9-alpine3.12
|
||||
|
||||
RUN apk add --no-cache postgresql-libs gettext zlib libjpeg libxml2-dev libxslt-dev
|
||||
#Install all dependencies.
|
||||
RUN apk add --no-cache postgresql-libs gettext zlib libjpeg libxml2-dev libxslt-dev py-cryptography
|
||||
|
||||
#Print all logs without buffering it.
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
|
||||
#This port will be used by gunicorn.
|
||||
EXPOSE 8080
|
||||
|
||||
#Create app dir and install requirements.
|
||||
RUN mkdir /opt/recipes
|
||||
WORKDIR /opt/recipes
|
||||
COPY . ./
|
||||
RUN chmod +x boot.sh setup.sh
|
||||
RUN ln -s /opt/recipes/setup.sh /usr/local/bin/createsuperuser
|
||||
|
||||
RUN apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev zlib-dev jpeg-dev && \
|
||||
COPY requirements.txt ./
|
||||
|
||||
RUN apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev zlib-dev jpeg-dev libressl-dev libffi-dev cargo && \
|
||||
python -m venv venv && \
|
||||
/opt/recipes/venv/bin/python -m pip install --upgrade pip && \
|
||||
venv/bin/pip install wheel==0.36.2 && \
|
||||
venv/bin/pip install -r requirements.txt --no-cache-dir &&\
|
||||
apk --purge del .build-deps
|
||||
|
||||
#Copy project and execute it.
|
||||
COPY . ./
|
||||
RUN chmod +x boot.sh
|
||||
ENTRYPOINT ["/opt/recipes/boot.sh"]
|
||||
111
README.md
111
README.md
@@ -1,78 +1,69 @@
|
||||
# Recipes 
|
||||
<h1 align="center">
|
||||
<br>
|
||||
<a href="https://app.tandoor.dev"><img src="https://github.com/vabene1111/recipes/raw/develop/docs/logo_color.svg" height="256px" width="256px"></a>
|
||||
<br>
|
||||
Tandoor Recipes
|
||||
<br>
|
||||
</h1>
|
||||
|
||||
Recipes is a Django application to manage, tag and search recipes using either built in models or external storage providers hosting PDF's, Images or other files.
|
||||
<h4 align="center">The recipe manager that allows you to manage your ever growing collection of digital recipes.</h4>
|
||||
|
||||
<p align="center">
|
||||
|
||||
<img src="https://github.com/vabene1111/recipes/workflows/Continous%20Integration/badge.svg?branch=develop" >
|
||||
<img src="https://img.shields.io/github/stars/vabene1111/recipes" >
|
||||
<img src="https://img.shields.io/github/forks/vabene1111/recipes" >
|
||||
<img src="https://img.shields.io/docker/pulls/vabene1111/recipes" >
|
||||
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://docs.tandoor.dev/install/docker/" target="_blank" rel="noopener noreferrer">Installation</a> •
|
||||
<a href="https://docs.tandoor.dev/" target="_blank" rel="noopener noreferrer">Documentation</a> •
|
||||
<a href="https://app.tandoor.dev/" target="_blank" rel="noopener noreferrer">Demo</a>
|
||||
</p>
|
||||
|
||||

|
||||
|
||||
[More Screenshots](https://imgur.com/a/V01151p)
|
||||
# Your Feedback
|
||||
|
||||
Share some information on how you use Tandoor to help me improve the application [Google Survey](https://forms.gle/qNfLK2tWTeWHe9Qd7)
|
||||
|
||||
## Features
|
||||
|
||||
- :package: **Sync** files with Dropbox and Nextcloud (more can easily be added)
|
||||
- :mag: Powerful **search** with Djangos [TrigramSimilarity](https://docs.djangoproject.com/en/3.0/ref/contrib/postgres/search/#trigram-similarity)
|
||||
- :label: Create and search for **tags**, assign them in batch to all files matching certain filters
|
||||
- :page_facing_up: **Create recipes** locally within a nice, standardized web interface
|
||||
- :arrow_down: **Import recipes** from thousands of websites supporting [ld+json or microdata](https://schema.org/Recipe)
|
||||
- :iphone: Optimized for use on **mobile** devices like phones and tablets
|
||||
- :shopping_cart: Generate **shopping** lists from recipes
|
||||
- :calendar: Create a **Plan** on what to eat when
|
||||
- :family: **Share** recipes with friends and comment on them to suggest or remember changes you made
|
||||
- :whale: Easy setup with **Docker**
|
||||
- :art: Customize your interface with **themes**
|
||||
- :envelope: Export and import recipes from other users
|
||||
- :heavy_plus_sign: Many more like recipe scaling, image compression, cookbooks, printing views, ...
|
||||
- 📦 **Sync** files with Dropbox and Nextcloud (more can easily be added)
|
||||
- 🔍 Powerful **search** with Djangos [TrigramSimilarity](https://docs.djangoproject.com/en/3.0/ref/contrib/postgres/search/#trigram-similarity)
|
||||
- 🏷️ Create and search for **tags**, assign them in batch to all files matching certain filters
|
||||
- 📄 **Create recipes** locally within a nice, standardized web interface
|
||||
- ⬇️ **Import recipes** from thousands of websites supporting [ld+json or microdata](https://schema.org/Recipe)
|
||||
- 📱 Optimized for use on **mobile** devices like phones and tablets
|
||||
- 🛒 Generate **shopping** lists from recipes
|
||||
- 📆 Create a **Plan** on what to eat when
|
||||
- 👪 **Share** recipes with friends and comment on them to suggest or remember changes you made
|
||||
- ➗ automatically convert decimal units to **fractions** for those who like this
|
||||
- 🐳 Easy setup with **Docker** and included examples for Kubernetes, Unraid and Synology
|
||||
- 🎨 Customize your interface with **themes**
|
||||
- ✉️ Export and import recipes from other users
|
||||
- 🌍 localized in many languages thanks to the awesome community
|
||||
- ➕ Many more like recipe scaling, image compression, cookbooks, printing views, ...
|
||||
|
||||
This application is meant for people with a collection of recipes they want to share with family and friends or simply
|
||||
store them in a nicely organized way. A basic permission system exists but this application is not meant to be run as a public page.
|
||||
Some Documentation can be found [here](https://github.com/vabene1111/recipes/wiki)
|
||||
|
||||
## Installation
|
||||
|
||||
The docker image (`vabene1111/recipes`) simply exposes the application on port `8080`. You may choose any preferred installation method, the following are just examples to make it easier.
|
||||
|
||||
### Docker-Compose
|
||||
|
||||
1. Choose one of the included configurations [here](docs/docker).
|
||||
2. Download the environment (config) file template and fill it out `wget https://raw.githubusercontent.com/vabene1111/recipes/develop/.env.template -O .env`
|
||||
3. Start the container `docker-compose up -d`
|
||||
4. Open the page to create the first user. Alternatively use `docker-compose exec web_recipes createsuperuser`
|
||||
|
||||
### Manual
|
||||
|
||||
**Python >= 3.8** is required to run this!
|
||||
|
||||
Refer to [manual install](docs/manual_install) for detailled instructions.
|
||||
|
||||
## Updating
|
||||
|
||||
While intermediate updates can be skipped when updating please make sure to **read the release notes** in case some special action is required to update.
|
||||
|
||||
0. Before updating it is recommended to **create a backup!**
|
||||
1. Stop the container using `docker-compose down`
|
||||
2. Pull the latest image using `docker-compose pull`
|
||||
3. Start the container again using `docker-compose up -d`
|
||||
|
||||
## Kubernetes
|
||||
|
||||
You can find a basic kubernetes setup [here](docs/k8s/). Please see the README in the folder for more detail.
|
||||
|
||||
## Contributing
|
||||
|
||||
Pull Requests and ideas are welcome, feel free to contribute in any way.
|
||||
For any questions on how to work with django please refer to their excellent [documentation](https://www.djangoproject.com/start/).
|
||||
|
||||
### Translating
|
||||
|
||||
There is a [transifex project](https://www.transifex.com/django-recipes/django-cookbook/) project to enable community driven translations. If you want to contribute a new language or help maintain an already existing one feel free to create a transifex account (using the link above) and request to join the project.
|
||||
|
||||
It is also possible to provide the translations directly by creating a new language using `manage.py makemessages -l <language_code> -i venv`. Once finished simply open a PR with the changed files.
|
||||
store them in a nicely organized way. A basic permission system exists but this application is not meant to be run as
|
||||
a public page.
|
||||
Documentation can be found [here](https://docs.tandoor.dev/).
|
||||
|
||||
While this application has been around for a while and is actively used by many (including myself), it is still considered
|
||||
**beta** software that has a lot of rough edges and unpolished parts.
|
||||
## License
|
||||
|
||||
Beginning with version 0.10.0 the code in this repository is licensed under the [GNU AGPL v3](https://www.gnu.org/licenses/agpl-3.0.de.html) license with an
|
||||
[common clause](https://commonsclause.com/) selling exception. See [LICENSE.md](https://github.com/vabene1111/recipes/blob/develop/LICENSE.md) for details.
|
||||
|
||||
**Reasoning**
|
||||
> NOTE: There appears to be a whole range of legal issues with licensing anything else then the standard completely open licenses.
|
||||
> I am in the process of getting some professional legal advice to sort out these issues.
|
||||
> Please also see [Issue 238](https://github.com/vabene1111/recipes/issues/238) for some discussion and **reasoning** regarding the topic.
|
||||
|
||||
**Reasoning**
|
||||
**This software and *all* its features are and will always be free for everyone to use and enjoy.**
|
||||
|
||||
The reason for the selling exception is that a significant amount of time was spend over multiple years to develop this software.
|
||||
|
||||
10
SECURITY.md
Normal file
10
SECURITY.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
Since this software is still considered beta/WIP support is always only given for the latest version. There are no backports of security or any other fixes.
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Please open a normal public issue if you have any security related concerns. If you feel like the issue should not be discussed in
|
||||
public just open a generic issue and we will discuss further communitcation there (since GitHub does not allow everyone to create a security advisory :/).
|
||||
1
boot.sh
1
boot.sh
@@ -3,6 +3,7 @@ source venv/bin/activate
|
||||
|
||||
echo "Updating database"
|
||||
python manage.py migrate
|
||||
python manage.py collectstatic_js_reverse
|
||||
python manage.py collectstatic --noinput
|
||||
echo "Done"
|
||||
|
||||
|
||||
@@ -1,16 +1,36 @@
|
||||
from django.contrib import admin
|
||||
from .models import *
|
||||
from django.contrib.auth.admin import UserAdmin
|
||||
from django.contrib.auth.models import User, Group
|
||||
|
||||
from .models import (Comment, CookLog, Food, Ingredient, InviteLink, Keyword,
|
||||
MealPlan, MealType, NutritionInformation, Recipe,
|
||||
RecipeBook, RecipeBookEntry, RecipeImport, ShareLink,
|
||||
ShoppingList, ShoppingListEntry, ShoppingListRecipe,
|
||||
Space, Step, Storage, Sync, SyncLog, Unit, UserPreference,
|
||||
ViewLog, Supermarket, SupermarketCategory, SupermarketCategoryRelation,
|
||||
ImportLog, TelegramBot, BookmarkletImport)
|
||||
|
||||
|
||||
class CustomUserAdmin(UserAdmin):
|
||||
def has_add_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
|
||||
admin.site.unregister(User)
|
||||
admin.site.register(User, CustomUserAdmin)
|
||||
|
||||
admin.site.unregister(Group)
|
||||
|
||||
|
||||
class SpaceAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'message')
|
||||
list_display = ('name', 'created_by', 'message')
|
||||
|
||||
|
||||
admin.site.register(Space, SpaceAdmin)
|
||||
|
||||
|
||||
class UserPreferenceAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'theme', 'nav_color', 'default_page', 'search_style', 'comments')
|
||||
list_display = ('name', 'space', 'theme', 'nav_color', 'default_page', 'search_style',)
|
||||
|
||||
@staticmethod
|
||||
def name(obj):
|
||||
@@ -34,6 +54,18 @@ class SyncAdmin(admin.ModelAdmin):
|
||||
admin.site.register(Sync, SyncAdmin)
|
||||
|
||||
|
||||
class SupermarketCategoryInline(admin.TabularInline):
|
||||
model = SupermarketCategoryRelation
|
||||
|
||||
|
||||
class SupermarketAdmin(admin.ModelAdmin):
|
||||
inlines = (SupermarketCategoryInline,)
|
||||
|
||||
|
||||
admin.site.register(Supermarket, SupermarketAdmin)
|
||||
admin.site.register(SupermarketCategory)
|
||||
|
||||
|
||||
class SyncLogAdmin(admin.ModelAdmin):
|
||||
list_display = ('sync', 'status', 'msg', 'created_at')
|
||||
|
||||
@@ -133,7 +165,10 @@ admin.site.register(ViewLog, ViewLogAdmin)
|
||||
|
||||
|
||||
class InviteLinkAdmin(admin.ModelAdmin):
|
||||
list_display = ('username', 'group', 'valid_until', 'created_by', 'created_at', 'used_by')
|
||||
list_display = (
|
||||
'group', 'valid_until',
|
||||
'created_by', 'created_at', 'used_by'
|
||||
)
|
||||
|
||||
|
||||
admin.site.register(InviteLink, InviteLinkAdmin)
|
||||
@@ -147,7 +182,7 @@ admin.site.register(CookLog, CookLogAdmin)
|
||||
|
||||
|
||||
class ShoppingListRecipeAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'recipe', 'multiplier')
|
||||
list_display = ('id', 'recipe', 'servings')
|
||||
|
||||
|
||||
admin.site.register(ShoppingListRecipe, ShoppingListRecipeAdmin)
|
||||
@@ -179,3 +214,24 @@ class NutritionInformationAdmin(admin.ModelAdmin):
|
||||
|
||||
|
||||
admin.site.register(NutritionInformation, NutritionInformationAdmin)
|
||||
|
||||
|
||||
class ImportLogAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'type', 'running', 'created_by', 'created_at',)
|
||||
|
||||
|
||||
admin.site.register(ImportLog, ImportLogAdmin)
|
||||
|
||||
|
||||
class TelegramBotAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'name', 'created_by',)
|
||||
|
||||
|
||||
admin.site.register(TelegramBot, TelegramBotAdmin)
|
||||
|
||||
|
||||
class BookmarkletImportAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'url', 'created_by', 'created_at',)
|
||||
|
||||
|
||||
admin.site.register(BookmarkletImport, BookmarkletImportAdmin)
|
||||
|
||||
@@ -1,67 +1,83 @@
|
||||
import django_filters
|
||||
from django.conf import settings
|
||||
from django.contrib.postgres.search import TrigramSimilarity
|
||||
from django.db.models import Q
|
||||
from cookbook.forms import MultiSelectWidget
|
||||
from cookbook.models import Recipe, Keyword, Food, ShoppingList
|
||||
from django.conf import settings
|
||||
from django.utils.translation import gettext as _
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.forms import MultiSelectWidget
|
||||
from cookbook.models import Food, Keyword, Recipe, ShoppingList
|
||||
|
||||
class RecipeFilter(django_filters.FilterSet):
|
||||
name = django_filters.CharFilter(method='filter_name')
|
||||
keywords = django_filters.ModelMultipleChoiceFilter(queryset=Keyword.objects.all(), widget=MultiSelectWidget,
|
||||
method='filter_keywords')
|
||||
foods = django_filters.ModelMultipleChoiceFilter(queryset=Food.objects.all(), widget=MultiSelectWidget,
|
||||
method='filter_foods', label=_('Ingredients'))
|
||||
with scopes_disabled():
|
||||
class RecipeFilter(django_filters.FilterSet):
|
||||
name = django_filters.CharFilter(method='filter_name')
|
||||
keywords = django_filters.ModelMultipleChoiceFilter(
|
||||
queryset=Keyword.objects.none(),
|
||||
widget=MultiSelectWidget,
|
||||
method='filter_keywords'
|
||||
)
|
||||
foods = django_filters.ModelMultipleChoiceFilter(
|
||||
queryset=Food.objects.none(),
|
||||
widget=MultiSelectWidget,
|
||||
method='filter_foods',
|
||||
label=_('Ingredients')
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def filter_keywords(queryset, name, value):
|
||||
if not name == 'keywords':
|
||||
def __init__(self, data=None, *args, **kwargs):
|
||||
space = kwargs.pop('space')
|
||||
super().__init__(data, *args, **kwargs)
|
||||
self.filters['foods'].queryset = Food.objects.filter(space=space).all()
|
||||
self.filters['keywords'].queryset = Keyword.objects.filter(space=space).all()
|
||||
|
||||
@staticmethod
|
||||
def filter_keywords(queryset, name, value):
|
||||
if not name == 'keywords':
|
||||
return queryset
|
||||
for x in value:
|
||||
queryset = queryset.filter(keywords=x)
|
||||
return queryset
|
||||
for x in value:
|
||||
queryset = queryset.filter(keywords=x)
|
||||
return queryset
|
||||
|
||||
@staticmethod
|
||||
def filter_foods(queryset, name, value):
|
||||
if not name == 'foods':
|
||||
@staticmethod
|
||||
def filter_foods(queryset, name, value):
|
||||
if not name == 'foods':
|
||||
return queryset
|
||||
for x in value:
|
||||
queryset = queryset.filter(steps__ingredients__food__name=x).distinct()
|
||||
return queryset
|
||||
for x in value:
|
||||
queryset = queryset.filter(steps__ingredients__food__name=x).distinct()
|
||||
return queryset
|
||||
|
||||
@staticmethod
|
||||
def filter_name(queryset, name, value):
|
||||
if not name == 'name':
|
||||
@staticmethod
|
||||
def filter_name(queryset, name, value):
|
||||
if not name == 'name':
|
||||
return queryset
|
||||
if settings.DATABASES['default']['ENGINE'] in ['django.db.backends.postgresql_psycopg2',
|
||||
'django.db.backends.postgresql']:
|
||||
queryset = queryset.annotate(similarity=TrigramSimilarity('name', value), ).filter(
|
||||
Q(similarity__gt=0.1) | Q(name__unaccent__icontains=value)).order_by('-similarity')
|
||||
else:
|
||||
queryset = queryset.filter(name__icontains=value)
|
||||
return queryset
|
||||
if settings.DATABASES['default']['ENGINE'] == 'django.db.backends.postgresql_psycopg2':
|
||||
queryset = queryset.annotate(similarity=TrigramSimilarity('name', value), ).filter(
|
||||
Q(similarity__gt=0.1) | Q(name__icontains=value)).order_by('-similarity')
|
||||
else:
|
||||
queryset = queryset.filter(name__icontains=value)
|
||||
return queryset
|
||||
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ['name', 'keywords', 'foods', 'internal']
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ['name', 'keywords', 'foods', 'internal']
|
||||
|
||||
|
||||
class IngredientFilter(django_filters.FilterSet):
|
||||
name = django_filters.CharFilter(lookup_expr='icontains')
|
||||
class FoodFilter(django_filters.FilterSet):
|
||||
name = django_filters.CharFilter(lookup_expr='icontains')
|
||||
|
||||
class Meta:
|
||||
model = Food
|
||||
fields = ['name']
|
||||
class Meta:
|
||||
model = Food
|
||||
fields = ['name']
|
||||
|
||||
|
||||
class ShoppingListFilter(django_filters.FilterSet):
|
||||
class ShoppingListFilter(django_filters.FilterSet):
|
||||
|
||||
def __init__(self, data=None, *args, **kwargs):
|
||||
if data is not None:
|
||||
data = data.copy()
|
||||
data.setdefault("finished", False)
|
||||
super(ShoppingListFilter, self).__init__(data, *args, **kwargs)
|
||||
def __init__(self, data=None, *args, **kwargs):
|
||||
if data is not None:
|
||||
data = data.copy()
|
||||
data.setdefault("finished", False)
|
||||
super().__init__(data, *args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
model = ShoppingList
|
||||
fields = ['finished']
|
||||
class Meta:
|
||||
model = ShoppingList
|
||||
fields = ['finished']
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.forms import widgets
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django_scopes import scopes_disabled
|
||||
from django_scopes.forms import SafeModelChoiceField, SafeModelMultipleChoiceField
|
||||
from emoji_picker.widgets import EmojiPickerTextInput
|
||||
from hcaptcha.fields import hCaptchaField
|
||||
|
||||
from .models import *
|
||||
from .models import (Comment, Food, InviteLink, Keyword, MealPlan, Recipe,
|
||||
RecipeBook, RecipeBookEntry, Storage, Sync, Unit, User,
|
||||
UserPreference, SupermarketCategory, MealType, Space)
|
||||
|
||||
|
||||
class SelectWidget(widgets.Select):
|
||||
@@ -17,7 +23,8 @@ class MultiSelectWidget(widgets.SelectMultiple):
|
||||
js = ('custom/js/form_multiselect.js',)
|
||||
|
||||
|
||||
# yes there are some stupid browsers that still dont support this but i dont support people using these browsers
|
||||
# Yes there are some stupid browsers that still dont support this but
|
||||
# I dont support people using these browsers.
|
||||
class DateWidget(forms.DateInput):
|
||||
input_type = 'date'
|
||||
|
||||
@@ -31,19 +38,31 @@ class UserPreferenceForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = UserPreference
|
||||
fields = ('default_unit', 'use_fractions', 'theme', 'nav_color', 'default_page', 'show_recent', 'search_style', 'plan_share', 'ingredient_decimals', 'shopping_auto_sync', 'comments')
|
||||
fields = (
|
||||
'default_unit', 'use_fractions', 'theme', 'nav_color',
|
||||
'sticky_navbar', 'default_page', 'show_recent', 'search_style',
|
||||
'plan_share', 'ingredient_decimals', 'shopping_auto_sync',
|
||||
'comments'
|
||||
)
|
||||
|
||||
help_texts = {
|
||||
'nav_color': _('Color of the top navigation bar. Not all colors work with all themes, just try them out!'),
|
||||
'default_unit': _('Default Unit to be used when inserting a new ingredient into a recipe.'),
|
||||
'use_fractions': _('Enables support for fractions in ingredient amounts (e.g. convert decimals to fractions automatically)'),
|
||||
'plan_share': _('Default user to share newly created meal plan entries with.'),
|
||||
'show_recent': _('Show recently viewed recipes on search page.'),
|
||||
'ingredient_decimals': _('Number of decimals to round ingredients.'),
|
||||
'comments': _('If you want to be able to create and see comments underneath recipes.'),
|
||||
# noqa: E501
|
||||
'default_unit': _('Default Unit to be used when inserting a new ingredient into a recipe.'), # noqa: E501
|
||||
'use_fractions': _(
|
||||
'Enables support for fractions in ingredient amounts (e.g. convert decimals to fractions automatically)'),
|
||||
# noqa: E501
|
||||
'plan_share': _(
|
||||
'Users with whom newly created meal plan/shopping list entries should be shared by default.'),
|
||||
# noqa: E501
|
||||
'show_recent': _('Show recently viewed recipes on search page.'), # noqa: E501
|
||||
'ingredient_decimals': _('Number of decimals to round ingredients.'), # noqa: E501
|
||||
'comments': _('If you want to be able to create and see comments underneath recipes.'), # noqa: E501
|
||||
'shopping_auto_sync': _(
|
||||
'Setting to 0 will disable auto sync. When viewing a shopping list the list is updated every set seconds to sync changes someone else might have made. Useful when shopping with multiple people but might use a little bit '
|
||||
'of mobile data. If lower than instance limit it is reset when saving.')
|
||||
'Setting to 0 will disable auto sync. When viewing a shopping list the list is updated every set seconds to sync changes someone else might have made. Useful when shopping with multiple people but might use a little bit ' # noqa: E501
|
||||
'of mobile data. If lower than instance limit it is reset when saving.' # noqa: E501
|
||||
),
|
||||
'sticky_navbar': _('Makes the navbar stick to the top of the page.') # noqa: E501
|
||||
}
|
||||
|
||||
widgets = {
|
||||
@@ -65,12 +84,19 @@ class UserNameForm(forms.ModelForm):
|
||||
|
||||
class ExternalRecipeForm(forms.ModelForm):
|
||||
file_path = forms.CharField(disabled=True, required=False)
|
||||
storage = forms.ModelChoiceField(queryset=Storage.objects.all(), disabled=True, required=False)
|
||||
file_uid = forms.CharField(disabled=True, required=False)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
space = kwargs.pop('space')
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['keywords'].queryset = Keyword.objects.filter(space=space).all()
|
||||
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ('name', 'keywords', 'working_time', 'waiting_time', 'file_path', 'storage', 'file_uid')
|
||||
fields = (
|
||||
'name', 'description', 'servings', 'working_time', 'waiting_time',
|
||||
'file_path', 'file_uid', 'keywords'
|
||||
)
|
||||
|
||||
labels = {
|
||||
'name': _('Name'),
|
||||
@@ -81,88 +107,96 @@ class ExternalRecipeForm(forms.ModelForm):
|
||||
'file_uid': _('Storage UID'),
|
||||
}
|
||||
widgets = {'keywords': MultiSelectWidget}
|
||||
|
||||
|
||||
class InternalRecipeForm(forms.ModelForm):
|
||||
ingredients = forms.CharField(widget=forms.HiddenInput(), required=False)
|
||||
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ('name', 'image', 'working_time', 'waiting_time', 'keywords')
|
||||
|
||||
labels = {
|
||||
'name': _('Name'),
|
||||
'keywords': _('Keywords'),
|
||||
'working_time': _('Preparation time in minutes'),
|
||||
'waiting_time': _('Waiting time (cooking/baking) in minutes'),
|
||||
field_classes = {
|
||||
'keywords': SafeModelMultipleChoiceField,
|
||||
}
|
||||
widgets = {'keywords': MultiSelectWidget}
|
||||
|
||||
|
||||
class ShoppingForm(forms.Form):
|
||||
recipe = forms.ModelMultipleChoiceField(
|
||||
queryset=Recipe.objects.filter(internal=True).all(),
|
||||
widget=MultiSelectWidget
|
||||
)
|
||||
markdown_format = forms.BooleanField(
|
||||
help_text=_('Include <code>- [ ]</code> in list for easier usage in markdown based documents.'),
|
||||
required=False,
|
||||
initial=False
|
||||
)
|
||||
class ImportExportBase(forms.Form):
|
||||
DEFAULT = 'DEFAULT'
|
||||
PAPRIKA = 'PAPRIKA'
|
||||
NEXTCLOUD = 'NEXTCLOUD'
|
||||
MEALIE = 'MEALIE'
|
||||
CHOWDOWN = 'CHOWDOWN'
|
||||
SAFRON = 'SAFRON'
|
||||
CHEFTAP = 'CHEFTAP'
|
||||
PEPPERPLATE = 'PEPPERPLATE'
|
||||
RECETTETEK = 'RECETTETEK'
|
||||
RECIPESAGE = 'RECIPESAGE'
|
||||
DOMESTICA = 'DOMESTICA'
|
||||
MEALMASTER = 'MEALMASTER'
|
||||
REZKONV = 'REZKONV'
|
||||
|
||||
type = forms.ChoiceField(choices=(
|
||||
(DEFAULT, _('Default')), (PAPRIKA, 'Paprika'), (NEXTCLOUD, 'Nextcloud Cookbook'),
|
||||
(MEALIE, 'Mealie'), (CHOWDOWN, 'Chowdown'), (SAFRON, 'Safron'), (CHEFTAP, 'ChefTap'),
|
||||
(PEPPERPLATE, 'Pepperplate'), (RECETTETEK, 'RecetteTek'), (RECIPESAGE, 'Recipe Sage'), (DOMESTICA, 'Domestica'),
|
||||
(MEALMASTER, 'MealMaster'), (REZKONV, 'RezKonv'),
|
||||
))
|
||||
|
||||
|
||||
class ExportForm(forms.Form):
|
||||
recipe = forms.ModelChoiceField(
|
||||
queryset=Recipe.objects.filter(internal=True).all(),
|
||||
widget=SelectWidget
|
||||
)
|
||||
image = forms.BooleanField(
|
||||
help_text=_('Export Base64 encoded image?'),
|
||||
required=False
|
||||
)
|
||||
download = forms.BooleanField(
|
||||
help_text=_('Download export directly or show on page?'),
|
||||
required=False
|
||||
)
|
||||
class ImportForm(ImportExportBase):
|
||||
files = forms.FileField(required=True, widget=forms.ClearableFileInput(attrs={'multiple': True}))
|
||||
duplicates = forms.BooleanField(help_text=_(
|
||||
'To prevent duplicates recipes with the same name as existing ones are ignored. Check this box to import everything.'),
|
||||
required=False)
|
||||
|
||||
|
||||
class ImportForm(forms.Form):
|
||||
recipe = forms.CharField(widget=forms.Textarea, help_text=_('Simply paste a JSON export into this textarea and click import.'))
|
||||
class ExportForm(ImportExportBase):
|
||||
recipes = forms.ModelMultipleChoiceField(widget=MultiSelectWidget, queryset=Recipe.objects.none())
|
||||
all = forms.BooleanField(required=False)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
space = kwargs.pop('space')
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['recipes'].queryset = Recipe.objects.filter(space=space).all()
|
||||
|
||||
|
||||
class UnitMergeForm(forms.Form):
|
||||
prefix = 'unit'
|
||||
|
||||
new_unit = forms.ModelChoiceField(
|
||||
queryset=Unit.objects.all(),
|
||||
new_unit = SafeModelChoiceField(
|
||||
queryset=Unit.objects.none(),
|
||||
widget=SelectWidget,
|
||||
label=_('New Unit'),
|
||||
help_text=_('New unit that other gets replaced by.'),
|
||||
)
|
||||
old_unit = forms.ModelChoiceField(
|
||||
queryset=Unit.objects.all(),
|
||||
old_unit = SafeModelChoiceField(
|
||||
queryset=Unit.objects.none(),
|
||||
widget=SelectWidget,
|
||||
label=_('Old Unit'),
|
||||
help_text=_('Unit that should be replaced.'),
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
space = kwargs.pop('space')
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['new_unit'].queryset = Unit.objects.filter(space=space).all()
|
||||
self.fields['old_unit'].queryset = Unit.objects.filter(space=space).all()
|
||||
|
||||
|
||||
class FoodMergeForm(forms.Form):
|
||||
prefix = 'food'
|
||||
|
||||
new_food = forms.ModelChoiceField(
|
||||
queryset=Food.objects.all(),
|
||||
new_food = SafeModelChoiceField(
|
||||
queryset=Food.objects.none(),
|
||||
widget=SelectWidget,
|
||||
label=_('New Food'),
|
||||
help_text=_('New food that other gets replaced by.'),
|
||||
)
|
||||
old_food = forms.ModelChoiceField(
|
||||
queryset=Food.objects.all(),
|
||||
old_food = SafeModelChoiceField(
|
||||
queryset=Food.objects.none(),
|
||||
widget=SelectWidget,
|
||||
label=_('Old Food'),
|
||||
help_text=_('Food that should be replaced.'),
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
space = kwargs.pop('space')
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['new_food'].queryset = Food.objects.filter(space=space).all()
|
||||
self.fields['old_food'].queryset = Food.objects.filter(space=space).all()
|
||||
|
||||
|
||||
class CommentForm(forms.ModelForm):
|
||||
prefix = 'comment'
|
||||
@@ -187,24 +221,45 @@ class KeywordForm(forms.ModelForm):
|
||||
|
||||
|
||||
class FoodForm(forms.ModelForm):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
space = kwargs.pop('space')
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['recipe'].queryset = Recipe.objects.filter(space=space).all()
|
||||
self.fields['supermarket_category'].queryset = SupermarketCategory.objects.filter(space=space).all()
|
||||
|
||||
class Meta:
|
||||
model = Food
|
||||
fields = ('name', 'recipe')
|
||||
fields = ('name', 'description', 'ignore_shopping', 'recipe', 'supermarket_category')
|
||||
widgets = {'recipe': SelectWidget}
|
||||
|
||||
field_classes = {
|
||||
'recipe': SafeModelChoiceField,
|
||||
'supermarket_category': SafeModelChoiceField,
|
||||
}
|
||||
|
||||
|
||||
class StorageForm(forms.ModelForm):
|
||||
username = forms.CharField(widget=forms.TextInput(attrs={'autocomplete': 'new-password'}), required=False)
|
||||
password = forms.CharField(widget=forms.TextInput(attrs={'autocomplete': 'new-password', 'type': 'password'}),
|
||||
required=False,
|
||||
help_text=_('Leave empty for dropbox and enter app password for nextcloud.'))
|
||||
token = forms.CharField(widget=forms.TextInput(attrs={'autocomplete': 'new-password', 'type': 'password'}),
|
||||
required=False,
|
||||
help_text=_('Leave empty for nextcloud and enter api token for dropbox.'))
|
||||
username = forms.CharField(
|
||||
widget=forms.TextInput(attrs={'autocomplete': 'new-password'}),
|
||||
required=False
|
||||
)
|
||||
password = forms.CharField(
|
||||
widget=forms.TextInput(attrs={'autocomplete': 'new-password', 'type': 'password'}),
|
||||
required=False,
|
||||
help_text=_('Leave empty for dropbox and enter app password for nextcloud.')
|
||||
)
|
||||
token = forms.CharField(
|
||||
widget=forms.TextInput(
|
||||
attrs={'autocomplete': 'new-password', 'type': 'password'}
|
||||
),
|
||||
required=False,
|
||||
help_text=_('Leave empty for nextcloud and enter api token for dropbox.')
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Storage
|
||||
fields = ('name', 'method', 'username', 'password', 'token', 'url')
|
||||
fields = ('name', 'method', 'username', 'password', 'token', 'url', 'path')
|
||||
|
||||
help_texts = {
|
||||
'url': _(
|
||||
@@ -215,24 +270,56 @@ class StorageForm(forms.ModelForm):
|
||||
class RecipeBookEntryForm(forms.ModelForm):
|
||||
prefix = 'bookmark'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
space = kwargs.pop('space')
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['book'].queryset = RecipeBook.objects.filter(space=space).all()
|
||||
|
||||
class Meta:
|
||||
model = RecipeBookEntry
|
||||
fields = ('book',)
|
||||
|
||||
field_classes = {
|
||||
'book': SafeModelChoiceField,
|
||||
}
|
||||
|
||||
|
||||
class SyncForm(forms.ModelForm):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
space = kwargs.pop('space')
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['storage'].queryset = Storage.objects.filter(space=space).all()
|
||||
|
||||
class Meta:
|
||||
model = Sync
|
||||
fields = ('storage', 'path', 'active')
|
||||
|
||||
field_classes = {
|
||||
'storage': SafeModelChoiceField,
|
||||
}
|
||||
|
||||
|
||||
class BatchEditForm(forms.Form):
|
||||
search = forms.CharField(label=_('Search String'))
|
||||
keywords = forms.ModelMultipleChoiceField(queryset=Keyword.objects.all().order_by('id'), required=False,
|
||||
widget=MultiSelectWidget)
|
||||
keywords = forms.ModelMultipleChoiceField(
|
||||
queryset=Keyword.objects.none(),
|
||||
required=False,
|
||||
widget=MultiSelectWidget
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
space = kwargs.pop('space')
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['keywords'].queryset = Keyword.objects.filter(space=space).all().order_by('id')
|
||||
|
||||
|
||||
class ImportRecipeForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
space = kwargs.pop('space')
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['keywords'].queryset = Keyword.objects.filter(space=space).all()
|
||||
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ('name', 'keywords', 'file_path', 'file_uid')
|
||||
@@ -244,48 +331,140 @@ class ImportRecipeForm(forms.ModelForm):
|
||||
'file_uid': _('File ID'),
|
||||
}
|
||||
widgets = {'keywords': MultiSelectWidget}
|
||||
field_classes = {
|
||||
'keywords': SafeModelChoiceField,
|
||||
}
|
||||
|
||||
|
||||
class RecipeBookForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
space = kwargs.pop('space')
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['shared'].queryset = User.objects.filter(userpreference__space=space).all()
|
||||
|
||||
class Meta:
|
||||
model = RecipeBook
|
||||
fields = ('name', 'icon', 'description', 'shared')
|
||||
widgets = {'icon': EmojiPickerTextInput, 'shared': MultiSelectWidget}
|
||||
field_classes = {
|
||||
'shared': SafeModelMultipleChoiceField,
|
||||
}
|
||||
|
||||
|
||||
class MealPlanForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
space = kwargs.pop('space')
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['recipe'].queryset = Recipe.objects.filter(space=space).all()
|
||||
self.fields['meal_type'].queryset = MealType.objects.filter(space=space).all()
|
||||
self.fields['shared'].queryset = User.objects.filter(userpreference__space=space).all()
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super(MealPlanForm, self).clean()
|
||||
|
||||
if cleaned_data['title'] == '' and cleaned_data['recipe'] is None:
|
||||
raise forms.ValidationError(_('You must provide at least a recipe or a title.'))
|
||||
raise forms.ValidationError(
|
||||
_('You must provide at least a recipe or a title.')
|
||||
)
|
||||
|
||||
return cleaned_data
|
||||
|
||||
class Meta:
|
||||
model = MealPlan
|
||||
fields = ('recipe', 'title', 'meal_type', 'note', 'recipe_multiplier', 'date', 'shared')
|
||||
fields = (
|
||||
'recipe', 'title', 'meal_type', 'note',
|
||||
'servings', 'date', 'shared'
|
||||
)
|
||||
|
||||
help_texts = {
|
||||
'shared': _('You can list default users to share recipes with in the settings.'),
|
||||
'note': _('You can use markdown to format this field. See the <a href="/docs/markdown/">docs here</a>'),
|
||||
'recipe_multiplier': _('Scaling factor for recipe.')
|
||||
'shared': _('You can list default users to share recipes with in the settings.'), # noqa: E501
|
||||
'note': _('You can use markdown to format this field. See the <a href="/docs/markdown/">docs here</a>')
|
||||
# noqa: E501
|
||||
}
|
||||
|
||||
widgets = {'recipe': SelectWidget, 'date': DateWidget, 'shared': MultiSelectWidget}
|
||||
widgets = {
|
||||
'recipe': SelectWidget,
|
||||
'date': DateWidget,
|
||||
'shared': MultiSelectWidget
|
||||
}
|
||||
field_classes = {
|
||||
'recipe': SafeModelChoiceField,
|
||||
'meal_type': SafeModelChoiceField,
|
||||
'shared': SafeModelMultipleChoiceField,
|
||||
}
|
||||
|
||||
|
||||
class InviteLinkForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
user = kwargs.pop('user')
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['space'].queryset = Space.objects.filter(created_by=user).all()
|
||||
|
||||
def clean(self):
|
||||
space = self.cleaned_data['space']
|
||||
if space.max_users != 0 and (UserPreference.objects.filter(space=space).count() + InviteLink.objects.filter(space=space).count()) >= space.max_users:
|
||||
raise ValidationError(_('Maximum number of users for this space reached.'))
|
||||
|
||||
def clean_email(self):
|
||||
email = self.cleaned_data['email']
|
||||
with scopes_disabled():
|
||||
if email != '' and User.objects.filter(email=email).exists():
|
||||
raise ValidationError(_('Email address already taken!'))
|
||||
|
||||
return email
|
||||
|
||||
class Meta:
|
||||
model = InviteLink
|
||||
fields = ('username', 'group', 'valid_until')
|
||||
fields = ('email', 'group', 'valid_until', 'space')
|
||||
help_texts = {
|
||||
'username': _('A username is not required, if left blank the new user can choose one.')
|
||||
'email': _('An email address is not required but if present the invite link will be send to the user.'),
|
||||
}
|
||||
field_classes = {
|
||||
'space': SafeModelChoiceField,
|
||||
}
|
||||
|
||||
|
||||
class SpaceCreateForm(forms.Form):
|
||||
prefix = 'create'
|
||||
name = forms.CharField()
|
||||
|
||||
def clean_name(self):
|
||||
name = self.cleaned_data['name']
|
||||
with scopes_disabled():
|
||||
if Space.objects.filter(name=name).exists():
|
||||
raise ValidationError(_('Name already taken.'))
|
||||
return name
|
||||
|
||||
|
||||
class SpaceJoinForm(forms.Form):
|
||||
prefix = 'join'
|
||||
token = forms.CharField()
|
||||
|
||||
|
||||
class AllAuthSignupForm(forms.Form):
|
||||
captcha = hCaptchaField()
|
||||
terms = forms.BooleanField(label=_('Accept Terms and Privacy'))
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(AllAuthSignupForm, self).__init__(**kwargs)
|
||||
if settings.PRIVACY_URL == '' and settings.TERMS_URL == '':
|
||||
self.fields.pop('terms')
|
||||
if settings.HCAPTCHA_SECRET == '':
|
||||
self.fields.pop('captcha')
|
||||
|
||||
def signup(self, request, user):
|
||||
pass
|
||||
|
||||
|
||||
class UserCreateForm(forms.Form):
|
||||
name = forms.CharField(label='Username')
|
||||
password = forms.CharField(widget=forms.TextInput(attrs={'autocomplete': 'new-password', 'type': 'password'}))
|
||||
password_confirm = forms.CharField(widget=forms.TextInput(attrs={'autocomplete': 'new-password', 'type': 'password'}))
|
||||
password = forms.CharField(
|
||||
widget=forms.TextInput(
|
||||
attrs={'autocomplete': 'new-password', 'type': 'password'}
|
||||
)
|
||||
)
|
||||
password_confirm = forms.CharField(
|
||||
widget=forms.TextInput(
|
||||
attrs={'autocomplete': 'new-password', 'type': 'password'}
|
||||
)
|
||||
)
|
||||
|
||||
32
cookbook/helper/AllAuthCustomAdapter.py
Normal file
32
cookbook/helper/AllAuthCustomAdapter.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import datetime
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from allauth.account.adapter import DefaultAccountAdapter
|
||||
from django.contrib import messages
|
||||
from django.core.cache import caches
|
||||
from gettext import gettext as _
|
||||
|
||||
|
||||
class AllAuthCustomAdapter(DefaultAccountAdapter):
|
||||
|
||||
def is_open_for_signup(self, request):
|
||||
"""
|
||||
Whether to allow sign ups.
|
||||
"""
|
||||
if request.resolver_match.view_name == 'account_signup' and not settings.ENABLE_SIGNUP:
|
||||
return False
|
||||
else:
|
||||
return super(AllAuthCustomAdapter, self).is_open_for_signup(request)
|
||||
|
||||
# disable password reset for now
|
||||
def send_mail(self, template_prefix, email, context):
|
||||
if settings.EMAIL_HOST != '':
|
||||
default = datetime.datetime.now()
|
||||
c = caches['default'].get_or_set(email, default, timeout=360)
|
||||
if c == default:
|
||||
super(AllAuthCustomAdapter, self).send_mail(template_prefix, email, context)
|
||||
else:
|
||||
messages.add_message(self.request, messages.ERROR, _('In order to prevent spam, the requested email was not send. Please wait a few minutes and try again.'))
|
||||
else:
|
||||
pass
|
||||
19
cookbook/helper/CustomStorageClass.py
Normal file
19
cookbook/helper/CustomStorageClass.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import hashlib
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from storages.backends.s3boto3 import S3Boto3Storage
|
||||
|
||||
|
||||
class CachedS3Boto3Storage(S3Boto3Storage):
|
||||
def url(self, name, **kwargs):
|
||||
key = hashlib.md5(f'recipes_media_urls_{name}'.encode('utf-8')).hexdigest()
|
||||
if result := cache.get(key):
|
||||
return result
|
||||
|
||||
result = super(CachedS3Boto3Storage, self).url(name, **kwargs)
|
||||
|
||||
timeout = int(settings.AWS_QUERYSTRING_EXPIRE * .95)
|
||||
cache.set(key, result, timeout)
|
||||
|
||||
return result
|
||||
8
cookbook/helper/CustomTestRunner.py
Normal file
8
cookbook/helper/CustomTestRunner.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from django.test.runner import DiscoverRunner
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
|
||||
class CustomTestRunner(DiscoverRunner):
|
||||
def run_tests(self, *args, **kwargs):
|
||||
with scopes_disabled():
|
||||
return super().run_tests(*args, **kwargs)
|
||||
@@ -1 +1,6 @@
|
||||
from cookbook.helper.dal import *
|
||||
import cookbook.helper.dal
|
||||
from cookbook.helper.AllAuthCustomAdapter import AllAuthCustomAdapter
|
||||
|
||||
__all__ = [
|
||||
'dal',
|
||||
]
|
||||
|
||||
13
cookbook/helper/context_processors.py
Normal file
13
cookbook/helper/context_processors.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
def context_settings(request):
|
||||
return {
|
||||
'EMAIL_ENABLED': settings.EMAIL_HOST != '',
|
||||
'SIGNUP_ENABLED': settings.ENABLE_SIGNUP,
|
||||
'CAPTCHA_ENABLED': settings.HCAPTCHA_SITEKEY != '',
|
||||
'HOSTED': settings.HOSTED,
|
||||
'TERMS_URL': settings.TERMS_URL,
|
||||
'PRIVACY_URL': settings.PRIVACY_URL,
|
||||
'IMPRINT_URL': settings.IMPRINT_URL,
|
||||
}
|
||||
@@ -1,27 +1,16 @@
|
||||
from cookbook.models import Food, Keyword, Recipe, Unit
|
||||
|
||||
from dal import autocomplete
|
||||
|
||||
from cookbook.models import Keyword, Recipe, Unit, Food
|
||||
|
||||
class BaseAutocomplete(autocomplete.Select2QuerySetView):
|
||||
model = None
|
||||
|
||||
class KeywordAutocomplete(autocomplete.Select2QuerySetView):
|
||||
def get_queryset(self):
|
||||
if not self.request.user.is_authenticated:
|
||||
return Keyword.objects.none()
|
||||
return self.model.objects.none()
|
||||
|
||||
qs = Keyword.objects.all()
|
||||
|
||||
if self.q:
|
||||
qs = qs.filter(name__istartswith=self.q)
|
||||
|
||||
return qs
|
||||
|
||||
|
||||
class IngredientsAutocomplete(autocomplete.Select2QuerySetView):
|
||||
def get_queryset(self):
|
||||
if not self.request.user.is_authenticated:
|
||||
return Food.objects.none()
|
||||
|
||||
qs = Food.objects.all()
|
||||
qs = self.model.objects.filter(space=self.request.space).all()
|
||||
|
||||
if self.q:
|
||||
qs = qs.filter(name__icontains=self.q)
|
||||
@@ -29,27 +18,17 @@ class IngredientsAutocomplete(autocomplete.Select2QuerySetView):
|
||||
return qs
|
||||
|
||||
|
||||
class RecipeAutocomplete(autocomplete.Select2QuerySetView):
|
||||
def get_queryset(self):
|
||||
if not self.request.user.is_authenticated:
|
||||
return Recipe.objects.none()
|
||||
|
||||
qs = Recipe.objects.all()
|
||||
|
||||
if self.q:
|
||||
qs = qs.filter(name__icontains=self.q)
|
||||
|
||||
return qs
|
||||
class KeywordAutocomplete(BaseAutocomplete):
|
||||
model = Keyword
|
||||
|
||||
|
||||
class UnitAutocomplete(autocomplete.Select2QuerySetView):
|
||||
def get_queryset(self):
|
||||
if not self.request.user.is_authenticated:
|
||||
return Unit.objects.none()
|
||||
class IngredientsAutocomplete(BaseAutocomplete):
|
||||
model = Food
|
||||
|
||||
qs = Unit.objects.all()
|
||||
|
||||
if self.q:
|
||||
qs = qs.filter(name__icontains=self.q)
|
||||
class RecipeAutocomplete(BaseAutocomplete):
|
||||
model = Recipe
|
||||
|
||||
return qs
|
||||
|
||||
class UnitAutocomplete(BaseAutocomplete):
|
||||
model = Unit
|
||||
|
||||
176
cookbook/helper/ingredient_parser.py
Normal file
176
cookbook/helper/ingredient_parser.py
Normal file
@@ -0,0 +1,176 @@
|
||||
import string
|
||||
import unicodedata
|
||||
|
||||
from cookbook.models import Unit, Food
|
||||
|
||||
|
||||
def parse_fraction(x):
|
||||
if len(x) == 1 and 'fraction' in unicodedata.decomposition(x):
|
||||
frac_split = unicodedata.decomposition(x[-1:]).split()
|
||||
return (float((frac_split[1]).replace('003', ''))
|
||||
/ float((frac_split[3]).replace('003', '')))
|
||||
else:
|
||||
frac_split = x.split('/')
|
||||
if not len(frac_split) == 2:
|
||||
raise ValueError
|
||||
try:
|
||||
return int(frac_split[0]) / int(frac_split[1])
|
||||
except ZeroDivisionError:
|
||||
raise ValueError
|
||||
|
||||
|
||||
def parse_amount(x):
|
||||
amount = 0
|
||||
unit = ''
|
||||
|
||||
did_check_frac = False
|
||||
end = 0
|
||||
while (
|
||||
end < len(x)
|
||||
and (
|
||||
x[end] in string.digits
|
||||
or (
|
||||
(x[end] == '.' or x[end] == ',' or x[end] == '/')
|
||||
and end + 1 < len(x)
|
||||
and x[end + 1] in string.digits
|
||||
)
|
||||
)
|
||||
):
|
||||
end += 1
|
||||
if end > 0:
|
||||
if "/" in x[:end]:
|
||||
amount = parse_fraction(x[:end])
|
||||
else:
|
||||
amount = float(x[:end].replace(',', '.'))
|
||||
else:
|
||||
amount = parse_fraction(x[0])
|
||||
end += 1
|
||||
did_check_frac = True
|
||||
if end < len(x):
|
||||
if did_check_frac:
|
||||
unit = x[end:]
|
||||
else:
|
||||
try:
|
||||
amount += parse_fraction(x[end])
|
||||
unit = x[end + 1:]
|
||||
except ValueError:
|
||||
unit = x[end:]
|
||||
return amount, unit
|
||||
|
||||
|
||||
def parse_ingredient_with_comma(tokens):
|
||||
ingredient = ''
|
||||
note = ''
|
||||
start = 0
|
||||
# search for first occurrence of an argument ending in a comma
|
||||
while start < len(tokens) and not tokens[start].endswith(','):
|
||||
start += 1
|
||||
if start == len(tokens):
|
||||
# no token ending in a comma found -> use everything as ingredient
|
||||
ingredient = ' '.join(tokens)
|
||||
else:
|
||||
ingredient = ' '.join(tokens[:start + 1])[:-1]
|
||||
note = ' '.join(tokens[start + 1:])
|
||||
return ingredient, note
|
||||
|
||||
|
||||
def parse_ingredient(tokens):
|
||||
ingredient = ''
|
||||
note = ''
|
||||
if tokens[-1].endswith(')'):
|
||||
# Check if the matching opening bracket is in the same token
|
||||
if (not tokens[-1].startswith('(')) and ('(' in tokens[-1]):
|
||||
return parse_ingredient_with_comma(tokens)
|
||||
# last argument ends with closing bracket -> look for opening bracket
|
||||
start = len(tokens) - 1
|
||||
while not tokens[start].startswith('(') and not start == 0:
|
||||
start -= 1
|
||||
if start == 0:
|
||||
# the whole list is wrapped in brackets -> assume it is an error (e.g. assumed first argument was the unit) # noqa: E501
|
||||
raise ValueError
|
||||
elif start < 0:
|
||||
# no opening bracket anywhere -> just ignore the last bracket
|
||||
ingredient, note = parse_ingredient_with_comma(tokens)
|
||||
else:
|
||||
# opening bracket found -> split in ingredient and note, remove brackets from note # noqa: E501
|
||||
note = ' '.join(tokens[start:])[1:-1]
|
||||
ingredient = ' '.join(tokens[:start])
|
||||
else:
|
||||
ingredient, note = parse_ingredient_with_comma(tokens)
|
||||
return ingredient, note
|
||||
|
||||
|
||||
def parse(x):
|
||||
# initialize default values
|
||||
amount = 0
|
||||
unit = ''
|
||||
ingredient = ''
|
||||
note = ''
|
||||
|
||||
tokens = x.split()
|
||||
if len(tokens) == 1:
|
||||
# there only is one argument, that must be the ingredient
|
||||
ingredient = tokens[0]
|
||||
else:
|
||||
try:
|
||||
# try to parse first argument as amount
|
||||
amount, unit = parse_amount(tokens[0])
|
||||
# only try to parse second argument as amount if there are at least
|
||||
# three arguments if it already has a unit there can't be
|
||||
# a fraction for the amount
|
||||
if len(tokens) > 2:
|
||||
try:
|
||||
if not unit == '':
|
||||
# a unit is already found, no need to try the second argument for a fraction # noqa: E501
|
||||
# probably not the best method to do it, but I didn't want to make an if check and paste the exact same thing in the else as already is in the except # noqa: E501
|
||||
raise ValueError
|
||||
# try to parse second argument as amount and add that, in case of '2 1/2' or '2 ½' # noqa: E501
|
||||
amount += parse_fraction(tokens[1])
|
||||
# assume that units can't end with a comma
|
||||
if len(tokens) > 3 and not tokens[2].endswith(','):
|
||||
# try to use third argument as unit and everything else as ingredient, use everything as ingredient if it fails # noqa: E501
|
||||
try:
|
||||
ingredient, note = parse_ingredient(tokens[3:])
|
||||
unit = tokens[2]
|
||||
except ValueError:
|
||||
ingredient, note = parse_ingredient(tokens[2:])
|
||||
else:
|
||||
ingredient, note = parse_ingredient(tokens[2:])
|
||||
except ValueError:
|
||||
# assume that units can't end with a comma
|
||||
if not tokens[1].endswith(','):
|
||||
# try to use second argument as unit and everything else as ingredient, use everything as ingredient if it fails # noqa: E501
|
||||
try:
|
||||
ingredient, note = parse_ingredient(tokens[2:])
|
||||
unit = tokens[1]
|
||||
except ValueError:
|
||||
ingredient, note = parse_ingredient(tokens[1:])
|
||||
else:
|
||||
ingredient, note = parse_ingredient(tokens[1:])
|
||||
else:
|
||||
# only two arguments, first one is the amount
|
||||
# which means this is the ingredient
|
||||
ingredient = tokens[1]
|
||||
except ValueError:
|
||||
try:
|
||||
# can't parse first argument as amount
|
||||
# -> no unit -> parse everything as ingredient
|
||||
ingredient, note = parse_ingredient(tokens)
|
||||
except ValueError:
|
||||
ingredient = ' '.join(tokens[1:])
|
||||
return amount, unit.strip(), ingredient.strip(), note.strip()
|
||||
|
||||
|
||||
# small utility functions to prevent emtpy unit/food creation
|
||||
def get_unit(unit, space):
|
||||
if len(unit) > 0:
|
||||
u, created = Unit.objects.get_or_create(name=unit, space=space)
|
||||
return u
|
||||
return None
|
||||
|
||||
|
||||
def get_food(food, space):
|
||||
if len(food) > 0:
|
||||
f, created = Food.objects.get_or_create(name=food, space=space)
|
||||
return f
|
||||
return None
|
||||
@@ -1,5 +1,4 @@
|
||||
import markdown
|
||||
|
||||
from markdown.treeprocessors import Treeprocessor
|
||||
|
||||
|
||||
@@ -20,5 +19,10 @@ class StyleTreeprocessor(Treeprocessor):
|
||||
|
||||
|
||||
class MarkdownFormatExtension(markdown.Extension):
|
||||
def extendMarkdown(self, md, md_globals):
|
||||
md.treeprocessors.register(StyleTreeprocessor(), 'StyleTreeprocessor', 10)
|
||||
# md_ globals deprecated - see here:
|
||||
def extendMarkdown(self, md):
|
||||
md.treeprocessors.register(
|
||||
StyleTreeprocessor(),
|
||||
'StyleTreeprocessor',
|
||||
10
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"""A more liberal autolinker
|
||||
"""
|
||||
A more liberal autolinker
|
||||
|
||||
Inspired by Django's urlize function.
|
||||
|
||||
@@ -45,27 +46,30 @@ URLIZE_RE = '(%s)' % '|'.join([
|
||||
r'[^(<\s]+\.(?:com|net|org)\b',
|
||||
])
|
||||
|
||||
|
||||
class UrlizePattern(markdown.inlinepatterns.Pattern):
|
||||
""" Return a link Element given an autolink (`http://example/com`). """
|
||||
|
||||
def handleMatch(self, m):
|
||||
url = m.group(2)
|
||||
|
||||
|
||||
if url.startswith('<'):
|
||||
url = url[1:-1]
|
||||
|
||||
|
||||
text = url
|
||||
|
||||
if not url.split('://')[0] in ('http','https','ftp'):
|
||||
if '@' in url and not '/' in url:
|
||||
|
||||
if not url.split('://')[0] in ('http', 'https', 'ftp'):
|
||||
if '@' in url and '/' not in url:
|
||||
url = 'mailto:' + url
|
||||
else:
|
||||
url = 'http://' + url
|
||||
|
||||
|
||||
el = markdown.util.etree.Element("a")
|
||||
el.set('href', url)
|
||||
el.text = markdown.util.AtomicString(text)
|
||||
return el
|
||||
|
||||
|
||||
class UrlizeExtension(markdown.Extension):
|
||||
""" Urlize Extension for Python-Markdown. """
|
||||
|
||||
@@ -73,9 +77,12 @@ class UrlizeExtension(markdown.Extension):
|
||||
""" Replace autolink with UrlizePattern """
|
||||
md.inlinePatterns['autolink'] = UrlizePattern(URLIZE_RE, md)
|
||||
|
||||
|
||||
def makeExtension(*args, **kwargs):
|
||||
return UrlizeExtension(*args, **kwargs)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# Permission Config
|
||||
from cookbook.helper.permission_helper import CustomIsUser, CustomIsOwner, CustomIsAdmin, CustomIsGuest
|
||||
from cookbook.helper.permission_helper import CustomIsUser
|
||||
|
||||
|
||||
class PermissionConfig:
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
"""
|
||||
Source: https://djangosnippets.org/snippets/1703/
|
||||
"""
|
||||
from django.views.generic.detail import SingleObjectTemplateResponseMixin
|
||||
from django.views.generic.edit import ModelFormMixin
|
||||
|
||||
from cookbook.models import ShareLink
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import user_passes_test
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from django.utils.translation import gettext as _
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.urls import reverse_lazy, reverse
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils.translation import gettext as _
|
||||
from rest_framework import permissions
|
||||
from rest_framework.permissions import SAFE_METHODS
|
||||
|
||||
from cookbook.models import ShareLink
|
||||
|
||||
|
||||
# Helper Functions
|
||||
|
||||
def get_allowed_groups(groups_required):
|
||||
"""
|
||||
@@ -34,8 +33,8 @@ def get_allowed_groups(groups_required):
|
||||
def has_group_permission(user, groups):
|
||||
"""
|
||||
Tests if a given user is member of a certain group (or any higher group)
|
||||
Superusers always bypass permission checks. Unauthenticated users cant be member of any
|
||||
group thus always return false.
|
||||
Superusers always bypass permission checks.
|
||||
Unauthenticated users cant be member of any group thus always return false.
|
||||
:param user: django auth user object
|
||||
:param groups: list or tuple of groups the user should be checked for
|
||||
:return: True if user is in allowed groups, false otherwise
|
||||
@@ -44,7 +43,7 @@ def has_group_permission(user, groups):
|
||||
return False
|
||||
groups_allowed = get_allowed_groups(groups)
|
||||
if user.is_authenticated:
|
||||
if user.is_superuser | bool(user.groups.filter(name__in=groups_allowed)):
|
||||
if bool(user.groups.filter(name__in=groups_allowed)):
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -52,24 +51,19 @@ def has_group_permission(user, groups):
|
||||
def is_object_owner(user, obj):
|
||||
"""
|
||||
Tests if a given user is the owner of a given object
|
||||
test performed by checking user against the objects user and create_by field (if exists)
|
||||
test performed by checking user against the objects user
|
||||
and create_by field (if exists)
|
||||
superusers bypass all checks, unauthenticated users cannot own anything
|
||||
:param user django auth user object
|
||||
:param obj any object that should be tested
|
||||
:return: true if user is owner of object, false otherwise
|
||||
"""
|
||||
# TODO this could be improved/cleaned up by adding get_owner methods to all models that allow owner checks
|
||||
if not user.is_authenticated:
|
||||
return False
|
||||
if user.is_superuser:
|
||||
return True
|
||||
if owner := getattr(obj, 'created_by', None):
|
||||
return owner == user
|
||||
if owner := getattr(obj, 'user', None):
|
||||
return owner == user
|
||||
if getattr(obj, 'get_owner', None):
|
||||
try:
|
||||
return obj.get_owner() == user
|
||||
return False
|
||||
except:
|
||||
return False
|
||||
|
||||
|
||||
def is_object_shared(user, obj):
|
||||
@@ -81,12 +75,11 @@ def is_object_shared(user, obj):
|
||||
:param obj any object that should be tested
|
||||
:return: true if user is shared for object, false otherwise
|
||||
"""
|
||||
# TODO this could be improved/cleaned up by adding share checks for relevant objects
|
||||
# TODO this could be improved/cleaned up by adding
|
||||
# share checks for relevant objects
|
||||
if not user.is_authenticated:
|
||||
return False
|
||||
if user.is_superuser:
|
||||
return True
|
||||
return user in obj.shared.all()
|
||||
return user in obj.get_shared()
|
||||
|
||||
|
||||
def share_link_valid(recipe, share):
|
||||
@@ -94,7 +87,7 @@ def share_link_valid(recipe, share):
|
||||
Verifies the validity of a share uuid
|
||||
:param recipe: recipe object
|
||||
:param share: share uuid
|
||||
:return: true if a share link with the given recipe and uuid exists, false otherwise
|
||||
:return: true if a share link with the given recipe and uuid exists
|
||||
"""
|
||||
try:
|
||||
return True if ShareLink.objects.filter(recipe=recipe, uuid=share).exists() else False
|
||||
@@ -106,8 +99,8 @@ def share_link_valid(recipe, share):
|
||||
|
||||
def group_required(*groups_required):
|
||||
"""
|
||||
Decorator that tests the requesting user to be member of at least one of the provided groups
|
||||
or higher level groups
|
||||
Decorator that tests the requesting user to be member
|
||||
of at least one of the provided groups or higher level groups
|
||||
:param groups_required: list of required groups
|
||||
:return: true if member of group, false otherwise
|
||||
"""
|
||||
@@ -115,7 +108,7 @@ def group_required(*groups_required):
|
||||
def in_groups(u):
|
||||
return has_group_permission(u, groups_required)
|
||||
|
||||
return user_passes_test(in_groups, login_url='index')
|
||||
return user_passes_test(in_groups, login_url='view_no_perm')
|
||||
|
||||
|
||||
class GroupRequiredMixin(object):
|
||||
@@ -127,8 +120,19 @@ class GroupRequiredMixin(object):
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if not has_group_permission(request.user, self.groups_required):
|
||||
messages.add_message(request, messages.ERROR, _('You do not have the required permissions to view this page!'))
|
||||
return HttpResponseRedirect(reverse_lazy('index'))
|
||||
if not request.user.is_authenticated:
|
||||
messages.add_message(request, messages.ERROR, _('You are not logged in and therefore cannot view this page!'))
|
||||
return HttpResponseRedirect(reverse_lazy('account_login') + '?next=' + request.path)
|
||||
else:
|
||||
messages.add_message(request, messages.ERROR, _('You do not have the required permissions to view this page!'))
|
||||
return HttpResponseRedirect(reverse_lazy('index'))
|
||||
try:
|
||||
obj = self.get_object()
|
||||
if obj.get_space() != request.space:
|
||||
messages.add_message(request, messages.ERROR, _('You do not have the required permissions to view this page!'))
|
||||
return HttpResponseRedirect(reverse_lazy('index'))
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
return super(GroupRequiredMixin, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
@@ -138,12 +142,20 @@ class OwnerRequiredMixin(object):
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if not request.user.is_authenticated:
|
||||
messages.add_message(request, messages.ERROR, _('You are not logged in and therefore cannot view this page!'))
|
||||
return HttpResponseRedirect(reverse_lazy('login'))
|
||||
return HttpResponseRedirect(reverse_lazy('account_login') + '?next=' + request.path)
|
||||
else:
|
||||
if not is_object_owner(request.user, self.get_object()):
|
||||
messages.add_message(request, messages.ERROR, _('You cannot interact with this object as its not owned by you!'))
|
||||
messages.add_message(request, messages.ERROR, _('You cannot interact with this object as it is not owned by you!'))
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
|
||||
try:
|
||||
obj = self.get_object()
|
||||
if obj.get_space() != request.space:
|
||||
messages.add_message(request, messages.ERROR, _('You do not have the required permissions to view this page!'))
|
||||
return HttpResponseRedirect(reverse_lazy('index'))
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
return super(OwnerRequiredMixin, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@@ -155,7 +167,7 @@ class CustomIsOwner(permissions.BasePermission):
|
||||
verifies user has ownership over object
|
||||
(either user or created_by or user is request user)
|
||||
"""
|
||||
message = _('You cannot interact with this object as its not owned by you!')
|
||||
message = _('You cannot interact with this object as it is not owned by you!') # noqa: E501
|
||||
|
||||
def has_permission(self, request, view):
|
||||
return request.user.is_authenticated
|
||||
@@ -164,12 +176,13 @@ class CustomIsOwner(permissions.BasePermission):
|
||||
return is_object_owner(request.user, obj)
|
||||
|
||||
|
||||
class CustomIsShared(permissions.BasePermission): # TODO function duplicate/too similar name
|
||||
# TODO function duplicate/too similar name
|
||||
class CustomIsShared(permissions.BasePermission):
|
||||
"""
|
||||
Custom permission class for django rest framework views
|
||||
verifies user is shared for the object he is trying to access
|
||||
"""
|
||||
message = _('You cannot interact with this object as its not owned by you!')
|
||||
message = _('You cannot interact with this object as it is not owned by you!') # noqa: E501
|
||||
|
||||
def has_permission(self, request, view):
|
||||
return request.user.is_authenticated
|
||||
|
||||
193
cookbook/helper/recipe_html_import.py
Normal file
193
cookbook/helper/recipe_html_import.py
Normal file
@@ -0,0 +1,193 @@
|
||||
import json
|
||||
import re
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from bs4.element import Tag
|
||||
from cookbook.helper import recipe_url_import as helper
|
||||
from cookbook.helper.scrapers.scrapers import text_scraper
|
||||
from json import JSONDecodeError
|
||||
from recipe_scrapers._utils import get_host_name, normalize_string
|
||||
from urllib.parse import unquote
|
||||
|
||||
|
||||
def get_recipe_from_source(text, url, space):
|
||||
def build_node(k, v):
|
||||
if isinstance(v, dict):
|
||||
node = {
|
||||
'name': k,
|
||||
'value': k,
|
||||
'children': get_children_dict(v)
|
||||
}
|
||||
elif isinstance(v, list):
|
||||
node = {
|
||||
'name': k,
|
||||
'value': k,
|
||||
'children': get_children_list(v)
|
||||
}
|
||||
else:
|
||||
node = {
|
||||
'name': k + ": " + normalize_string(str(v)),
|
||||
'value': normalize_string(str(v))
|
||||
}
|
||||
return node
|
||||
|
||||
def get_children_dict(children):
|
||||
kid_list = []
|
||||
for k, v in children.items():
|
||||
kid_list.append(build_node(k, v))
|
||||
return kid_list
|
||||
|
||||
def get_children_list(children):
|
||||
kid_list = []
|
||||
for kid in children:
|
||||
if type(kid) == list:
|
||||
node = {
|
||||
'name': "unknown list",
|
||||
'value': "unknown list",
|
||||
'children': get_children_list(kid)
|
||||
}
|
||||
kid_list.append(node)
|
||||
elif type(kid) == dict:
|
||||
for k, v in kid.items():
|
||||
kid_list.append(build_node(k, v))
|
||||
else:
|
||||
kid_list.append({
|
||||
'name': normalize_string(str(kid)),
|
||||
'value': normalize_string(str(kid))
|
||||
})
|
||||
return kid_list
|
||||
|
||||
recipe_json = {
|
||||
'name': '',
|
||||
'url': '',
|
||||
'description': '',
|
||||
'image': '',
|
||||
'keywords': [],
|
||||
'recipeIngredient': [],
|
||||
'recipeInstructions': '',
|
||||
'servings': '',
|
||||
'prepTime': '',
|
||||
'cookTime': ''
|
||||
}
|
||||
recipe_tree = []
|
||||
parse_list = []
|
||||
html_data = []
|
||||
images = []
|
||||
text = unquote(text)
|
||||
|
||||
try:
|
||||
parse_list.append(remove_graph(json.loads(text)))
|
||||
if not url and 'url' in parse_list[0]:
|
||||
url = parse_list[0]['url']
|
||||
scrape = text_scraper("<script type='application/ld+json'>" + text + "</script>", url=url)
|
||||
|
||||
except JSONDecodeError:
|
||||
soup = BeautifulSoup(text, "html.parser")
|
||||
html_data = get_from_html(soup)
|
||||
images += get_images_from_source(soup, url)
|
||||
for el in soup.find_all('script', type='application/ld+json'):
|
||||
el = remove_graph(el)
|
||||
if not url and 'url' in el:
|
||||
url = el['url']
|
||||
if type(el) == list:
|
||||
for le in el:
|
||||
parse_list.append(le)
|
||||
elif type(el) == dict:
|
||||
parse_list.append(el)
|
||||
for el in soup.find_all(type='application/json'):
|
||||
el = remove_graph(el)
|
||||
if type(el) == list:
|
||||
for le in el:
|
||||
parse_list.append(le)
|
||||
elif type(el) == dict:
|
||||
parse_list.append(el)
|
||||
scrape = text_scraper(text, url=url)
|
||||
|
||||
recipe_json = helper.get_from_scraper(scrape, space)
|
||||
|
||||
for el in parse_list:
|
||||
temp_tree = []
|
||||
if isinstance(el, Tag):
|
||||
try:
|
||||
el = json.loads(el.string)
|
||||
except TypeError:
|
||||
continue
|
||||
|
||||
for k, v in el.items():
|
||||
if isinstance(v, dict):
|
||||
node = {
|
||||
'name': k,
|
||||
'value': k,
|
||||
'children': get_children_dict(v)
|
||||
}
|
||||
elif isinstance(v, list):
|
||||
node = {
|
||||
'name': k,
|
||||
'value': k,
|
||||
'children': get_children_list(v)
|
||||
}
|
||||
else:
|
||||
node = {
|
||||
'name': k + ": " + normalize_string(str(v)),
|
||||
'value': normalize_string(str(v))
|
||||
}
|
||||
temp_tree.append(node)
|
||||
|
||||
if '@type' in el and el['@type'] == 'Recipe':
|
||||
recipe_tree += [{'name': 'ld+json', 'children': temp_tree}]
|
||||
else:
|
||||
recipe_tree += [{'name': 'json', 'children': temp_tree}]
|
||||
|
||||
return recipe_json, recipe_tree, html_data, images
|
||||
|
||||
|
||||
def get_from_html(soup):
|
||||
INVISIBLE_ELEMS = ('style', 'script', 'head', 'title')
|
||||
html = []
|
||||
for s in soup.strings:
|
||||
if ((s.parent.name not in INVISIBLE_ELEMS) and (len(s.strip()) > 0)):
|
||||
html.append(s)
|
||||
return html
|
||||
|
||||
|
||||
def get_images_from_source(soup, url):
|
||||
sources = ['src', 'srcset', 'data-src']
|
||||
images = []
|
||||
img_tags = soup.find_all('img')
|
||||
if url:
|
||||
site = get_host_name(url)
|
||||
prot = url.split(':')[0]
|
||||
|
||||
urls = []
|
||||
for img in img_tags:
|
||||
for src in sources:
|
||||
try:
|
||||
urls.append(img[src])
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
for u in urls:
|
||||
u = u.split('?')[0]
|
||||
filename = re.search(r'/([\w_-]+[.](jpg|jpeg|gif|png))$', u)
|
||||
if filename:
|
||||
if (('http' not in u) and (url)):
|
||||
# sometimes an image source can be relative
|
||||
# if it is provide the base url
|
||||
u = '{}://{}{}'.format(prot, site, u)
|
||||
if 'http' in u:
|
||||
images.append(u)
|
||||
return images
|
||||
|
||||
|
||||
def remove_graph(el):
|
||||
# recipes type might be wrapped in @graph type
|
||||
if isinstance(el, Tag):
|
||||
try:
|
||||
el = json.loads(el.string)
|
||||
if '@graph' in el:
|
||||
for x in el['@graph']:
|
||||
if '@type' in x and x['@type'] == 'Recipe':
|
||||
el = x
|
||||
except TypeError:
|
||||
pass
|
||||
return el
|
||||
72
cookbook/helper/recipe_search.py
Normal file
72
cookbook/helper/recipe_search.py
Normal file
@@ -0,0 +1,72 @@
|
||||
from datetime import datetime, timedelta
|
||||
from functools import reduce
|
||||
|
||||
from django.contrib.postgres.search import TrigramSimilarity
|
||||
from django.db.models import Q, Case, When, Value
|
||||
from django.forms import IntegerField
|
||||
|
||||
from cookbook.models import ViewLog
|
||||
from recipes import settings
|
||||
|
||||
|
||||
def search_recipes(request, queryset, params):
|
||||
search_string = params.get('query', '')
|
||||
search_keywords = params.getlist('keywords', [])
|
||||
search_foods = params.getlist('foods', [])
|
||||
search_books = params.getlist('books', [])
|
||||
|
||||
search_keywords_or = params.get('keywords_or', True)
|
||||
search_foods_or = params.get('foods_or', True)
|
||||
search_books_or = params.get('books_or', True)
|
||||
|
||||
search_internal = params.get('internal', None)
|
||||
search_random = params.get('random', False)
|
||||
search_last_viewed = int(params.get('last_viewed', 0))
|
||||
|
||||
if search_last_viewed > 0:
|
||||
last_viewed_recipes = ViewLog.objects.filter(created_by=request.user, space=request.space,
|
||||
created_at__gte=datetime.now() - timedelta(days=14)).order_by('pk').values_list('recipe__pk', flat=True).distinct()
|
||||
|
||||
return queryset.filter(pk__in=last_viewed_recipes[len(last_viewed_recipes) - min(len(last_viewed_recipes), search_last_viewed):])
|
||||
|
||||
queryset = queryset.annotate(
|
||||
new_recipe=Case(When(created_at__gte=(datetime.now() - timedelta(days=7)), then=Value(100)),
|
||||
default=Value(0), )).order_by('-new_recipe', 'name')
|
||||
|
||||
if settings.DATABASES['default']['ENGINE'] in ['django.db.backends.postgresql_psycopg2',
|
||||
'django.db.backends.postgresql']:
|
||||
queryset = queryset.annotate(similarity=TrigramSimilarity('name', search_string), ).filter(
|
||||
Q(similarity__gt=0.1) | Q(name__unaccent__icontains=search_string)).order_by('-similarity')
|
||||
else:
|
||||
queryset = queryset.filter(name__icontains=search_string)
|
||||
|
||||
if len(search_keywords) > 0:
|
||||
if search_keywords_or == 'true':
|
||||
queryset = queryset.filter(keywords__id__in=search_keywords)
|
||||
else:
|
||||
for k in search_keywords:
|
||||
queryset = queryset.filter(keywords__id=k)
|
||||
|
||||
if len(search_foods) > 0:
|
||||
if search_foods_or == 'true':
|
||||
queryset = queryset.filter(steps__ingredients__food__id__in=search_foods)
|
||||
else:
|
||||
for k in search_foods:
|
||||
queryset = queryset.filter(steps__ingredients__food__id=k)
|
||||
|
||||
if len(search_books) > 0:
|
||||
if search_books_or == 'true':
|
||||
queryset = queryset.filter(recipebookentry__book__id__in=search_books)
|
||||
else:
|
||||
for k in search_books:
|
||||
queryset = queryset.filter(recipebookentry__book__id=k)
|
||||
|
||||
queryset = queryset.distinct()
|
||||
|
||||
if search_internal == 'true':
|
||||
queryset = queryset.filter(internal=True)
|
||||
|
||||
if search_random == 'true':
|
||||
queryset = queryset.order_by("?")
|
||||
|
||||
return queryset
|
||||
@@ -1,199 +1,361 @@
|
||||
import json
|
||||
import random
|
||||
import re
|
||||
import unicodedata
|
||||
from json import JSONDecodeError
|
||||
|
||||
import microdata
|
||||
from bs4 import BeautifulSoup
|
||||
from django.http import JsonResponse
|
||||
from django.utils.dateparse import parse_duration
|
||||
from django.utils.translation import gettext as _
|
||||
from isodate import parse_duration as iso_parse_duration
|
||||
from isodate.isoerror import ISO8601Error
|
||||
from recipe_scrapers._exceptions import ElementNotFoundInHtml
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse as parse_single_ingredient
|
||||
from cookbook.models import Keyword
|
||||
from django.utils.dateparse import parse_duration
|
||||
from html import unescape
|
||||
from recipe_scrapers._schemaorg import SchemaOrgException
|
||||
from recipe_scrapers._utils import get_minutes
|
||||
|
||||
|
||||
def get_from_html(html_text, url):
|
||||
soup = BeautifulSoup(html_text, "html.parser")
|
||||
|
||||
# first try finding ld+json as its most common
|
||||
for ld in soup.find_all('script', type='application/ld+json'):
|
||||
def get_from_scraper(scrape, space):
|
||||
# converting the scrape_me object to the existing json format based on ld+json
|
||||
recipe_json = {}
|
||||
try:
|
||||
recipe_json['name'] = parse_name(scrape.title() or None)
|
||||
except Exception:
|
||||
recipe_json['name'] = None
|
||||
if not recipe_json['name']:
|
||||
try:
|
||||
ld_json = json.loads(ld.string.replace('\n', ''))
|
||||
if type(ld_json) != list:
|
||||
ld_json = [ld_json]
|
||||
recipe_json['name'] = scrape.schema.data.get('name') or ''
|
||||
except Exception:
|
||||
recipe_json['name'] = ''
|
||||
|
||||
for ld_json_item in ld_json:
|
||||
# recipes type might be wrapped in @graph type
|
||||
if '@graph' in ld_json_item:
|
||||
for x in ld_json_item['@graph']:
|
||||
if '@type' in x and x['@type'] == 'Recipe':
|
||||
ld_json_item = x
|
||||
try:
|
||||
description = scrape.schema.data.get("description") or ''
|
||||
except Exception:
|
||||
description = ''
|
||||
|
||||
if '@type' in ld_json_item and ld_json_item['@type'] == 'Recipe':
|
||||
return find_recipe_json(ld_json_item, url)
|
||||
except JSONDecodeError as e:
|
||||
return JsonResponse({'error': True, 'msg': _('The requested site provided malformed data and cannot be read.')}, status=400)
|
||||
recipe_json['description'] = parse_description(description)
|
||||
|
||||
# now try to find microdata
|
||||
items = microdata.get_items(html_text)
|
||||
for i in items:
|
||||
md_json = json.loads(i.json())
|
||||
if 'schema.org/Recipe' in str(md_json['type']):
|
||||
return find_recipe_json(md_json['properties'], url)
|
||||
|
||||
return JsonResponse({'error': True, 'msg': _('The requested site does not provide any recognized data format to import the recipe from.')}, status=400)
|
||||
|
||||
|
||||
def find_recipe_json(ld_json, url):
|
||||
if type(ld_json['name']) == list:
|
||||
try:
|
||||
servings = scrape.yields() or None
|
||||
except Exception:
|
||||
servings = None
|
||||
if not servings:
|
||||
try:
|
||||
ld_json['name'] = ld_json['name'][0]
|
||||
except:
|
||||
ld_json['name'] = 'ERROR'
|
||||
servings = scrape.schema.data.get('recipeYield') or 1
|
||||
except Exception:
|
||||
servings = 1
|
||||
if type(servings) != int:
|
||||
try:
|
||||
servings = int(re.findall(r'\b\d+\b', servings)[0])
|
||||
except Exception:
|
||||
servings = 1
|
||||
recipe_json['servings'] = max(servings, 1)
|
||||
|
||||
# some sites use ingredients instead of recipeIngredients
|
||||
if 'recipeIngredient' not in ld_json and 'ingredients' in ld_json:
|
||||
ld_json['recipeIngredient'] = ld_json['ingredients']
|
||||
try:
|
||||
recipe_json['prepTime'] = get_minutes(scrape.schema.data.get("prepTime")) or 0
|
||||
except Exception:
|
||||
recipe_json['prepTime'] = 0
|
||||
try:
|
||||
recipe_json['cookTime'] = get_minutes(scrape.schema.data.get("cookTime")) or 0
|
||||
except Exception:
|
||||
recipe_json['cookTime'] = 0
|
||||
if recipe_json['cookTime'] + recipe_json['prepTime'] == 0:
|
||||
try:
|
||||
recipe_json['prepTime'] = get_minutes(scrape.total_time()) or 0
|
||||
except Exception:
|
||||
try:
|
||||
get_minutes(scrape.schema.data.get("totalTime")) or 0
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if 'recipeIngredient' in ld_json:
|
||||
# some pages have comma separated ingredients in a single array entry
|
||||
if len(ld_json['recipeIngredient']) == 1 and len(ld_json['recipeIngredient'][0]) > 30:
|
||||
ld_json['recipeIngredient'] = ld_json['recipeIngredient'][0].split(',')
|
||||
try:
|
||||
recipe_json['image'] = parse_image(scrape.image()) or None
|
||||
except Exception:
|
||||
recipe_json['image'] = None
|
||||
if not recipe_json['image']:
|
||||
try:
|
||||
recipe_json['image'] = parse_image(scrape.schema.data.get('image')) or ''
|
||||
except Exception:
|
||||
recipe_json['image'] = ''
|
||||
|
||||
for x in ld_json['recipeIngredient']:
|
||||
if '\n' in x:
|
||||
ld_json['recipeIngredient'].remove(x)
|
||||
for i in x.split('\n'):
|
||||
ld_json['recipeIngredient'].insert(0, i)
|
||||
keywords = []
|
||||
try:
|
||||
if scrape.schema.data.get("keywords"):
|
||||
keywords += listify_keywords(scrape.schema.data.get("keywords"))
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
if scrape.schema.data.get('recipeCategory'):
|
||||
keywords += listify_keywords(scrape.schema.data.get("recipeCategory"))
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
if scrape.schema.data.get('recipeCuisine'):
|
||||
keywords += listify_keywords(scrape.schema.data.get("recipeCuisine"))
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
recipe_json['keywords'] = parse_keywords(list(set(map(str.casefold, keywords))), space)
|
||||
except AttributeError:
|
||||
recipe_json['keywords'] = keywords
|
||||
|
||||
try:
|
||||
ingredients = []
|
||||
for x in scrape.ingredients():
|
||||
try:
|
||||
amount, unit, ingredient, note = parse_single_ingredient(x)
|
||||
if ingredient:
|
||||
ingredients.append(
|
||||
{
|
||||
'amount': amount,
|
||||
'unit': {
|
||||
'text': unit,
|
||||
'id': random.randrange(10000, 99999)
|
||||
},
|
||||
'ingredient': {
|
||||
'text': ingredient,
|
||||
'id': random.randrange(10000, 99999)
|
||||
},
|
||||
'note': note,
|
||||
'original': x
|
||||
}
|
||||
)
|
||||
except Exception:
|
||||
ingredients.append(
|
||||
{
|
||||
'amount': 0,
|
||||
'unit': {
|
||||
'text': '',
|
||||
'id': random.randrange(10000, 99999)
|
||||
},
|
||||
'ingredient': {
|
||||
'text': x,
|
||||
'id': random.randrange(10000, 99999)
|
||||
},
|
||||
'note': '',
|
||||
'original': x
|
||||
}
|
||||
)
|
||||
recipe_json['recipeIngredient'] = ingredients
|
||||
except Exception:
|
||||
recipe_json['recipeIngredient'] = ingredients
|
||||
|
||||
for x in ld_json['recipeIngredient']:
|
||||
ingredient_split = x.split()
|
||||
ingredient = None
|
||||
amount = 0
|
||||
unit = ''
|
||||
if len(ingredient_split) > 2:
|
||||
ingredient = " ".join(ingredient_split[2:])
|
||||
unit = ingredient_split[1]
|
||||
try:
|
||||
recipe_json['recipeInstructions'] = parse_instructions(scrape.instructions())
|
||||
except Exception:
|
||||
recipe_json['recipeInstructions'] = ""
|
||||
|
||||
try:
|
||||
if 'fraction' in unicodedata.decomposition(ingredient_split[0]):
|
||||
frac_split = unicodedata.decomposition(ingredient_split[0]).split()
|
||||
amount = round(float((frac_split[1]).replace('003', '')) / float((frac_split[3]).replace('003', '')), 3)
|
||||
else:
|
||||
raise TypeError
|
||||
except TypeError: # raised by unicodedata.decomposition if there was no unicode character in parsed data
|
||||
try:
|
||||
amount = float(ingredient_split[0].replace(',', '.'))
|
||||
except ValueError:
|
||||
amount = 0
|
||||
ingredient = " ".join(ingredient_split)
|
||||
if len(ingredient_split) == 2:
|
||||
ingredient = " ".join(ingredient_split[1:])
|
||||
unit = ''
|
||||
try:
|
||||
amount = float(ingredient_split[0].replace(',', '.'))
|
||||
except ValueError:
|
||||
amount = 0
|
||||
ingredient = " ".join(ingredient_split)
|
||||
if len(ingredient_split) == 1:
|
||||
ingredient = " ".join(ingredient_split)
|
||||
if scrape.url:
|
||||
recipe_json['url'] = scrape.url
|
||||
recipe_json['recipeInstructions'] += "\n\nImported from " + scrape.url
|
||||
return recipe_json
|
||||
|
||||
if ingredient:
|
||||
ingredients.append({'amount': amount, 'unit': {'text': unit, 'id': random.randrange(10000, 99999)}, 'ingredient': {'text': ingredient, 'id': random.randrange(10000, 99999)}, 'original': x})
|
||||
|
||||
ld_json['recipeIngredient'] = ingredients
|
||||
else:
|
||||
ld_json['recipeIngredient'] = []
|
||||
def parse_name(name):
|
||||
if type(name) == list:
|
||||
try:
|
||||
name = name[0]
|
||||
except Exception:
|
||||
name = 'ERROR'
|
||||
return normalize_string(name)
|
||||
|
||||
if 'keywords' in ld_json:
|
||||
keywords = []
|
||||
|
||||
# keywords as string
|
||||
if type(ld_json['keywords']) == str:
|
||||
ld_json['keywords'] = ld_json['keywords'].split(',')
|
||||
def parse_ingredients(ingredients):
|
||||
# some pages have comma separated ingredients in a single array entry
|
||||
try:
|
||||
if type(ingredients[0]) == dict:
|
||||
return ingredients
|
||||
except (KeyError, IndexError):
|
||||
pass
|
||||
|
||||
# keywords as string in list
|
||||
if type(ld_json['keywords']) == list and len(ld_json['keywords']) == 1 and ',' in ld_json['keywords'][0]:
|
||||
ld_json['keywords'] = ld_json['keywords'][0].split(',')
|
||||
if (len(ingredients) == 1 and type(ingredients) == list):
|
||||
ingredients = ingredients[0].split(',')
|
||||
elif type(ingredients) == str:
|
||||
ingredients = ingredients.split(',')
|
||||
|
||||
# keywords as list
|
||||
for kw in ld_json['keywords']:
|
||||
if k := Keyword.objects.filter(name=kw).first():
|
||||
keywords.append({'id': str(k.id), 'text': str(k).strip()})
|
||||
for x in ingredients:
|
||||
if '\n' in x:
|
||||
ingredients.remove(x)
|
||||
for i in x.split('\n'):
|
||||
ingredients.insert(0, i)
|
||||
|
||||
ingredient_list = []
|
||||
|
||||
for x in ingredients:
|
||||
if x.replace(' ', '') != '':
|
||||
x = x.replace('½', "0.5").replace('¼', "0.25").replace('¾', "0.75")
|
||||
try:
|
||||
amount, unit, ingredient, note = parse_single_ingredient(x)
|
||||
if ingredient:
|
||||
ingredient_list.append(
|
||||
{
|
||||
'amount': amount,
|
||||
'unit': {
|
||||
'text': unit,
|
||||
'id': random.randrange(10000, 99999)
|
||||
},
|
||||
'ingredient': {
|
||||
'text': ingredient,
|
||||
'id': random.randrange(10000, 99999)
|
||||
},
|
||||
'note': note,
|
||||
'original': x
|
||||
}
|
||||
)
|
||||
except Exception:
|
||||
ingredient_list.append(
|
||||
{
|
||||
'amount': 0,
|
||||
'unit': {
|
||||
'text': '',
|
||||
'id': random.randrange(10000, 99999)
|
||||
},
|
||||
'ingredient': {
|
||||
'text': x,
|
||||
'id': random.randrange(10000, 99999)
|
||||
},
|
||||
'note': '',
|
||||
'original': x
|
||||
}
|
||||
)
|
||||
|
||||
ingredients = ingredient_list
|
||||
else:
|
||||
ingredients = []
|
||||
return ingredients
|
||||
|
||||
|
||||
def parse_description(description):
|
||||
return normalize_string(description)
|
||||
|
||||
|
||||
def parse_instructions(instructions):
|
||||
instruction_text = ''
|
||||
|
||||
# flatten instructions if they are in a list
|
||||
if type(instructions) == list:
|
||||
for i in instructions:
|
||||
if type(i) == str:
|
||||
instruction_text += i
|
||||
else:
|
||||
keywords.append({'id': "null", 'text': kw.strip()})
|
||||
|
||||
ld_json['keywords'] = keywords
|
||||
else:
|
||||
ld_json['keywords'] = []
|
||||
|
||||
if 'recipeInstructions' in ld_json:
|
||||
instructions = ''
|
||||
|
||||
# flatten instructions if they are in a list
|
||||
if type(ld_json['recipeInstructions']) == list:
|
||||
for i in ld_json['recipeInstructions']:
|
||||
if type(i) == str:
|
||||
instructions += i
|
||||
if 'text' in i:
|
||||
instruction_text += i['text'] + '\n\n'
|
||||
elif 'itemListElement' in i:
|
||||
for ile in i['itemListElement']:
|
||||
if type(ile) == str:
|
||||
instruction_text += ile + '\n\n'
|
||||
elif 'text' in ile:
|
||||
instruction_text += ile['text'] + '\n\n'
|
||||
else:
|
||||
if 'text' in i:
|
||||
instructions += i['text'] + '\n\n'
|
||||
elif 'itemListElement' in i:
|
||||
for ile in i['itemListElement']:
|
||||
if type(ile) == str:
|
||||
instructions += ile + '\n\n'
|
||||
elif 'text' in ile:
|
||||
instructions += ile['text'] + '\n\n'
|
||||
else:
|
||||
instructions += str(i)
|
||||
ld_json['recipeInstructions'] = instructions
|
||||
instruction_text += str(i)
|
||||
instructions = instruction_text
|
||||
|
||||
ld_json['recipeInstructions'] = re.sub(r'\n\s*\n', '\n\n', ld_json['recipeInstructions'])
|
||||
ld_json['recipeInstructions'] = re.sub(' +', ' ', ld_json['recipeInstructions'])
|
||||
ld_json['recipeInstructions'] = ld_json['recipeInstructions'].replace('<p>', '')
|
||||
ld_json['recipeInstructions'] = ld_json['recipeInstructions'].replace('</p>', '')
|
||||
else:
|
||||
ld_json['recipeInstructions'] = ''
|
||||
return normalize_string(instructions)
|
||||
|
||||
ld_json['recipeInstructions'] += '\n\n' + _('Imported from ') + url
|
||||
|
||||
if 'image' in ld_json:
|
||||
# check if list of images is returned, take first if so
|
||||
if (type(ld_json['image'])) == list:
|
||||
if type(ld_json['image'][0]) == str:
|
||||
ld_json['image'] = ld_json['image'][0]
|
||||
elif 'url' in ld_json['image'][0]:
|
||||
ld_json['image'] = ld_json['image'][0]['url']
|
||||
def parse_image(image):
|
||||
# check if list of images is returned, take first if so
|
||||
if not image:
|
||||
return None
|
||||
if type(image) == list:
|
||||
for pic in image:
|
||||
if (type(pic) == str) and (pic[:4] == 'http'):
|
||||
image = pic
|
||||
elif 'url' in pic:
|
||||
image = pic['url']
|
||||
elif type(image) == dict:
|
||||
if 'url' in image:
|
||||
image = image['url']
|
||||
|
||||
# ignore relative image paths
|
||||
if 'http' not in ld_json['image']:
|
||||
ld_json['image'] = ''
|
||||
# ignore relative image paths
|
||||
if image[:4] != 'http':
|
||||
image = ''
|
||||
return image
|
||||
|
||||
if 'cookTime' in ld_json:
|
||||
|
||||
def parse_servings(servings):
|
||||
if type(servings) == str:
|
||||
try:
|
||||
if type(ld_json['cookTime']) == list and len(ld_json['cookTime']) > 0:
|
||||
ld_json['cookTime'] = ld_json['cookTime'][0]
|
||||
ld_json['cookTime'] = round(parse_duration(ld_json['cookTime']).seconds / 60)
|
||||
except TypeError:
|
||||
ld_json['cookTime'] = 0
|
||||
else:
|
||||
ld_json['cookTime'] = 0
|
||||
|
||||
if 'prepTime' in ld_json:
|
||||
servings = int(re.search(r'\d+', servings).group())
|
||||
except AttributeError:
|
||||
servings = 1
|
||||
elif type(servings) == list:
|
||||
try:
|
||||
if type(ld_json['prepTime']) == list and len(ld_json['prepTime']) > 0:
|
||||
ld_json['prepTime'] = ld_json['prepTime'][0]
|
||||
ld_json['prepTime'] = round(parse_duration(ld_json['prepTime']).seconds / 60)
|
||||
except TypeError:
|
||||
ld_json['prepTime'] = 0
|
||||
else:
|
||||
ld_json['prepTime'] = 0
|
||||
servings = int(re.findall(r'\b\d+\b', servings[0])[0])
|
||||
except KeyError:
|
||||
servings = 1
|
||||
return servings
|
||||
|
||||
for key in list(ld_json):
|
||||
if key not in ['prepTime', 'cookTime', 'image', 'recipeInstructions', 'keywords', 'name', 'recipeIngredient']:
|
||||
ld_json.pop(key, None)
|
||||
|
||||
return JsonResponse(ld_json)
|
||||
def parse_cooktime(cooktime):
|
||||
if type(cooktime) not in [int, float]:
|
||||
try:
|
||||
cooktime = float(re.search(r'\d+', cooktime).group())
|
||||
except (ValueError, AttributeError):
|
||||
try:
|
||||
cooktime = round(iso_parse_duration(cooktime).seconds / 60)
|
||||
except ISO8601Error:
|
||||
try:
|
||||
if (type(cooktime) == list and len(cooktime) > 0):
|
||||
cooktime = cooktime[0]
|
||||
cooktime = round(parse_duration(cooktime).seconds / 60)
|
||||
except AttributeError:
|
||||
cooktime = 0
|
||||
|
||||
return cooktime
|
||||
|
||||
|
||||
def parse_preptime(preptime):
|
||||
if type(preptime) not in [int, float]:
|
||||
try:
|
||||
preptime = float(re.search(r'\d+', preptime).group())
|
||||
except ValueError:
|
||||
try:
|
||||
preptime = round(iso_parse_duration(preptime).seconds / 60)
|
||||
except ISO8601Error:
|
||||
try:
|
||||
if (type(preptime) == list and len(preptime) > 0):
|
||||
preptime = preptime[0]
|
||||
preptime = round(parse_duration(preptime).seconds / 60)
|
||||
except AttributeError:
|
||||
preptime = 0
|
||||
|
||||
return preptime
|
||||
|
||||
|
||||
def parse_keywords(keyword_json, space):
|
||||
keywords = []
|
||||
# keywords as list
|
||||
for kw in keyword_json:
|
||||
kw = normalize_string(kw)
|
||||
if len(kw) != 0:
|
||||
if k := Keyword.objects.filter(name=kw, space=space).first():
|
||||
keywords.append({'id': str(k.id), 'text': str(k)})
|
||||
else:
|
||||
keywords.append({'id': random.randrange(1111111, 9999999, 1), 'text': kw})
|
||||
|
||||
return keywords
|
||||
|
||||
|
||||
def listify_keywords(keyword_list):
|
||||
# keywords as string
|
||||
try:
|
||||
if type(keyword_list[0]) == dict:
|
||||
return keyword_list
|
||||
except (KeyError, IndexError):
|
||||
pass
|
||||
if type(keyword_list) == str:
|
||||
keyword_list = keyword_list.split(',')
|
||||
|
||||
# keywords as string in list
|
||||
if (type(keyword_list) == list and len(keyword_list) == 1 and ',' in keyword_list[0]):
|
||||
keyword_list = keyword_list[0].split(',')
|
||||
return [x.strip() for x in keyword_list]
|
||||
|
||||
|
||||
def normalize_string(string):
|
||||
# Convert all named and numeric character references (e.g. >, >)
|
||||
unescaped_string = unescape(string)
|
||||
unescaped_string = re.sub('<[^<]+?>', '', unescaped_string)
|
||||
unescaped_string = re.sub(' +', ' ', unescaped_string)
|
||||
unescaped_string = re.sub('</p>', '\n', unescaped_string)
|
||||
unescaped_string = re.sub(r'\n\s*\n', '\n\n', unescaped_string)
|
||||
unescaped_string = unescaped_string.replace("\xa0", " ").replace("\t", " ").strip()
|
||||
return unescaped_string
|
||||
|
||||
39
cookbook/helper/scope_middleware.py
Normal file
39
cookbook/helper/scope_middleware.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse
|
||||
from django_scopes import scope, scopes_disabled
|
||||
|
||||
from cookbook.views import views
|
||||
|
||||
|
||||
class ScopeMiddleware:
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
if request.user.is_authenticated:
|
||||
|
||||
if request.path.startswith('/admin/'):
|
||||
with scopes_disabled():
|
||||
return self.get_response(request)
|
||||
|
||||
if request.path.startswith('/signup/') or request.path.startswith('/invite/'):
|
||||
return self.get_response(request)
|
||||
|
||||
if request.path.startswith('/accounts/'):
|
||||
return self.get_response(request)
|
||||
|
||||
with scopes_disabled():
|
||||
if request.user.userpreference.space is None and not reverse('account_logout') in request.path:
|
||||
return views.no_space(request)
|
||||
|
||||
if request.user.groups.count() == 0 and not reverse('account_logout') in request.path:
|
||||
return views.no_groups(request)
|
||||
|
||||
request.space = request.user.userpreference.space
|
||||
# with scopes_disabled():
|
||||
with scope(space=request.space):
|
||||
return self.get_response(request)
|
||||
else:
|
||||
with scopes_disabled():
|
||||
request.space = None
|
||||
return self.get_response(request)
|
||||
68
cookbook/helper/scrapers/cooksillustrated.py
Normal file
68
cookbook/helper/scrapers/cooksillustrated.py
Normal file
@@ -0,0 +1,68 @@
|
||||
import json
|
||||
from recipe_scrapers._abstract import AbstractScraper
|
||||
|
||||
|
||||
class CooksIllustrated(AbstractScraper):
|
||||
@classmethod
|
||||
def host(cls, site='cooksillustrated'):
|
||||
return {
|
||||
'cooksillustrated': f"{site}.com",
|
||||
'americastestkitchen': f"{site}.com",
|
||||
'cookscountry': f"{site}.com",
|
||||
}.get(site)
|
||||
|
||||
def title(self):
|
||||
return self.schema.title()
|
||||
|
||||
def image(self):
|
||||
return self.schema.image()
|
||||
|
||||
def total_time(self):
|
||||
if not self.recipe:
|
||||
self.get_recipe()
|
||||
return self.recipe['recipeTimeNote']
|
||||
|
||||
def yields(self):
|
||||
if not self.recipe:
|
||||
self.get_recipe()
|
||||
return self.recipe['yields']
|
||||
|
||||
def ingredients(self):
|
||||
if not self.recipe:
|
||||
self.get_recipe()
|
||||
ingredients = []
|
||||
for group in self.recipe['ingredientGroups']:
|
||||
ingredients += group['fields']['recipeIngredientItems']
|
||||
return [
|
||||
"{} {} {}{}".format(
|
||||
i['fields']['qty'] or '',
|
||||
i['fields']['measurement'] or '',
|
||||
i['fields']['ingredient']['fields']['title'] or '',
|
||||
i['fields']['postText'] or ''
|
||||
)
|
||||
for i in ingredients
|
||||
]
|
||||
|
||||
def instructions(self):
|
||||
if not self.recipe:
|
||||
self.get_recipe()
|
||||
if self.recipe.get('headnote', False):
|
||||
i = ['Note: ' + self.recipe.get('headnote', '')]
|
||||
else:
|
||||
i = []
|
||||
return "\n".join(
|
||||
i
|
||||
+ [self.recipe.get('whyThisWorks', '')]
|
||||
+ [
|
||||
instruction['fields']['content']
|
||||
for instruction in self.recipe['instructions']
|
||||
]
|
||||
)
|
||||
|
||||
def nutrients(self):
|
||||
raise NotImplementedError("This should be implemented.")
|
||||
|
||||
def get_recipe(self):
|
||||
j = json.loads(self.soup.find(type='application/json').string)
|
||||
name = list(j['props']['initialState']['content']['documents'])[0]
|
||||
self.recipe = j['props']['initialState']['content']['documents'][name]
|
||||
43
cookbook/helper/scrapers/scrapers.py
Normal file
43
cookbook/helper/scrapers/scrapers.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from json import JSONDecodeError
|
||||
from recipe_scrapers import SCRAPERS, get_host_name
|
||||
from recipe_scrapers._factory import SchemaScraperFactory
|
||||
from recipe_scrapers._schemaorg import SchemaOrg
|
||||
|
||||
from .cooksillustrated import CooksIllustrated
|
||||
|
||||
CUSTOM_SCRAPERS = {
|
||||
CooksIllustrated.host(site="cooksillustrated"): CooksIllustrated,
|
||||
CooksIllustrated.host(site="americastestkitchen"): CooksIllustrated,
|
||||
CooksIllustrated.host(site="cookscountry"): CooksIllustrated,
|
||||
}
|
||||
SCRAPERS.update(CUSTOM_SCRAPERS)
|
||||
|
||||
|
||||
def text_scraper(text, url=None):
|
||||
domain = None
|
||||
if url:
|
||||
domain = get_host_name(url)
|
||||
if domain in SCRAPERS:
|
||||
scraper_class = SCRAPERS[domain]
|
||||
else:
|
||||
scraper_class = SchemaScraperFactory.SchemaScraper
|
||||
|
||||
class TextScraper(scraper_class):
|
||||
def __init__(
|
||||
self,
|
||||
page_data,
|
||||
url=None
|
||||
):
|
||||
self.wild_mode = False
|
||||
# self.exception_handling = None # TODO add new method here, old one was deprecated
|
||||
self.meta_http_equiv = False
|
||||
self.soup = BeautifulSoup(page_data, "html.parser")
|
||||
self.url = url
|
||||
self.recipe = None
|
||||
try:
|
||||
self.schema = SchemaOrg(page_data)
|
||||
except (JSONDecodeError, AttributeError):
|
||||
pass
|
||||
|
||||
return TextScraper(text, url)
|
||||
64
cookbook/helper/template_helper.py
Normal file
64
cookbook/helper/template_helper.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import bleach
|
||||
import markdown as md
|
||||
from bleach_allowlist import markdown_attrs, markdown_tags
|
||||
from cookbook.helper.mdx_attributes import MarkdownFormatExtension
|
||||
from cookbook.helper.mdx_urlize import UrlizeExtension
|
||||
from jinja2 import Template, TemplateSyntaxError, UndefinedError
|
||||
from gettext import gettext as _
|
||||
|
||||
class IngredientObject(object):
|
||||
amount = ""
|
||||
unit = ""
|
||||
food = ""
|
||||
note = ""
|
||||
|
||||
def __init__(self, ingredient):
|
||||
if ingredient.no_amount:
|
||||
self.amount = ""
|
||||
else:
|
||||
self.amount = f"<scalable-number v-bind:number='{bleach.clean(str(ingredient.amount))}' v-bind:factor='ingredient_factor'></scalable-number>"
|
||||
if ingredient.unit:
|
||||
self.unit = bleach.clean(str(ingredient.unit))
|
||||
else:
|
||||
self.unit = ""
|
||||
self.food = bleach.clean(str(ingredient.food))
|
||||
self.note = bleach.clean(str(ingredient.note))
|
||||
|
||||
def __str__(self):
|
||||
ingredient = self.amount
|
||||
if self.unit != "":
|
||||
ingredient += f' {self.unit}'
|
||||
return f'{ingredient} {self.food}'
|
||||
|
||||
|
||||
def render_instructions(step): # TODO deduplicate markdown cleanup code
|
||||
instructions = step.instruction
|
||||
|
||||
tags = markdown_tags + [
|
||||
'pre', 'table', 'td', 'tr', 'th', 'tbody', 'style', 'thead'
|
||||
]
|
||||
parsed_md = md.markdown(
|
||||
instructions,
|
||||
extensions=[
|
||||
'markdown.extensions.fenced_code', 'tables',
|
||||
UrlizeExtension(), MarkdownFormatExtension()
|
||||
]
|
||||
)
|
||||
markdown_attrs['*'] = markdown_attrs['*'] + ['class']
|
||||
|
||||
instructions = bleach.clean(parsed_md, tags, markdown_attrs)
|
||||
|
||||
ingredients = []
|
||||
|
||||
for i in step.ingredients.all():
|
||||
ingredients.append(IngredientObject(i))
|
||||
|
||||
try:
|
||||
template = Template(instructions)
|
||||
instructions = template.render(ingredients=ingredients)
|
||||
except TemplateSyntaxError:
|
||||
return _('Could not parse template code.') + ' Error: Template Syntax broken'
|
||||
except UndefinedError:
|
||||
return _('Could not parse template code.') + ' Error: Undefined Error'
|
||||
|
||||
return instructions
|
||||
59
cookbook/integration/Pepperplate.py
Normal file
59
cookbook/integration/Pepperplate.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import json
|
||||
import re
|
||||
from io import BytesIO
|
||||
from zipfile import ZipFile
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse, get_food, get_unit
|
||||
from cookbook.integration.integration import Integration
|
||||
from cookbook.models import Recipe, Step, Food, Unit, Ingredient, Keyword
|
||||
|
||||
|
||||
class Pepperplate(Integration):
|
||||
|
||||
def get_recipe_from_file(self, file):
|
||||
ingredient_mode = False
|
||||
direction_mode = False
|
||||
|
||||
ingredients = []
|
||||
directions = []
|
||||
for fl in file.readlines():
|
||||
line = fl.decode("utf-8")
|
||||
if 'Title:' in line:
|
||||
title = line.replace('Title:', '').replace('"', '').strip()
|
||||
if 'Description:' in line:
|
||||
description = line.replace('Description:', '').strip()
|
||||
if 'Original URL:' in line or 'Source:' in line or 'Yield:' in line or 'Total:' in line:
|
||||
if len(line.strip().split(':')[1]) > 0:
|
||||
directions.append(line.strip() + '\n')
|
||||
if ingredient_mode:
|
||||
if len(line) > 2 and 'Instructions:' not in line:
|
||||
ingredients.append(line.strip())
|
||||
if direction_mode:
|
||||
if len(line) > 2:
|
||||
directions.append(line.strip() + '\n')
|
||||
if 'Ingredients:' in line:
|
||||
ingredient_mode = True
|
||||
if 'Instructions:' in line:
|
||||
ingredient_mode = False
|
||||
direction_mode = True
|
||||
|
||||
recipe = Recipe.objects.create(name=title, description=description, created_by=self.request.user, internal=True, space=self.request.space)
|
||||
|
||||
step = Step.objects.create(
|
||||
instruction='\n'.join(directions) + '\n\n'
|
||||
)
|
||||
|
||||
for ingredient in ingredients:
|
||||
if len(ingredient.strip()) > 0:
|
||||
amount, unit, ingredient, note = parse(ingredient)
|
||||
f = get_food(ingredient, self.request.space)
|
||||
u = get_unit(unit, self.request.space)
|
||||
step.ingredients.add(Ingredient.objects.create(
|
||||
food=f, unit=u, amount=amount, note=note
|
||||
))
|
||||
recipe.steps.add(step)
|
||||
|
||||
return recipe
|
||||
|
||||
def get_file_from_recipe(self, recipe):
|
||||
raise NotImplementedError('Method not implemented in storage integration')
|
||||
60
cookbook/integration/cheftap.py
Normal file
60
cookbook/integration/cheftap.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import re
|
||||
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse, get_food, get_unit
|
||||
from cookbook.integration.integration import Integration
|
||||
from cookbook.models import Recipe, Step, Food, Unit, Ingredient
|
||||
|
||||
|
||||
class ChefTap(Integration):
|
||||
|
||||
def import_file_name_filter(self, zip_info_object):
|
||||
print("testing", zip_info_object.filename)
|
||||
return re.match(r'^cheftap_export/([A-Za-z\d\w\s-])+.txt$', zip_info_object.filename) or re.match(r'^([A-Za-z\d\w\s-])+.txt$', zip_info_object.filename)
|
||||
|
||||
def get_recipe_from_file(self, file):
|
||||
source_url = ''
|
||||
|
||||
ingredient_mode = 0
|
||||
|
||||
ingredients = []
|
||||
directions = []
|
||||
for i, fl in enumerate(file.readlines(), start=0):
|
||||
line = fl.decode("utf-8")
|
||||
if i == 0:
|
||||
title = line.strip()
|
||||
else:
|
||||
if line.startswith('https:') or line.startswith('http:'):
|
||||
source_url = line.strip()
|
||||
else:
|
||||
if ingredient_mode == 1 and len(line.strip()) == 0:
|
||||
ingredient_mode = 2
|
||||
if re.match(r'^([0-9])[^.](.)*$', line) and ingredient_mode < 2:
|
||||
ingredient_mode = 1
|
||||
ingredients.append(line.strip())
|
||||
else:
|
||||
directions.append(line.strip())
|
||||
|
||||
recipe = Recipe.objects.create(name=title, created_by=self.request.user, internal=True, space=self.request.space, )
|
||||
|
||||
step = Step.objects.create(instruction='\n'.join(directions))
|
||||
|
||||
if source_url != '':
|
||||
step.instruction += '\n' + source_url
|
||||
step.save()
|
||||
|
||||
for ingredient in ingredients:
|
||||
if len(ingredient.strip()) > 0:
|
||||
amount, unit, ingredient, note = parse(ingredient)
|
||||
f = get_food(ingredient, self.request.space)
|
||||
u = get_unit(unit, self.request.space)
|
||||
step.ingredients.add(Ingredient.objects.create(
|
||||
food=f, unit=u, amount=amount, note=note
|
||||
))
|
||||
recipe.steps.add(step)
|
||||
|
||||
return recipe
|
||||
|
||||
def get_file_from_recipe(self, recipe):
|
||||
raise NotImplementedError('Method not implemented in storage integration')
|
||||
79
cookbook/integration/chowdown.py
Normal file
79
cookbook/integration/chowdown.py
Normal file
@@ -0,0 +1,79 @@
|
||||
import json
|
||||
import re
|
||||
from io import BytesIO
|
||||
from zipfile import ZipFile
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse, get_food, get_unit
|
||||
from cookbook.integration.integration import Integration
|
||||
from cookbook.models import Recipe, Step, Food, Unit, Ingredient, Keyword
|
||||
|
||||
|
||||
class Chowdown(Integration):
|
||||
|
||||
def import_file_name_filter(self, zip_info_object):
|
||||
print("testing", zip_info_object.filename)
|
||||
return re.match(r'^(_)*recipes/([A-Za-z\d\s-])+.md$', zip_info_object.filename)
|
||||
|
||||
def get_recipe_from_file(self, file):
|
||||
ingredient_mode = False
|
||||
direction_mode = False
|
||||
description_mode = False
|
||||
|
||||
ingredients = []
|
||||
directions = []
|
||||
descriptions = []
|
||||
for fl in file.readlines():
|
||||
line = fl.decode("utf-8")
|
||||
if 'title:' in line:
|
||||
title = line.replace('title:', '').replace('"', '').strip()
|
||||
if 'image:' in line:
|
||||
image = line.replace('image:', '').strip()
|
||||
if 'tags:' in line:
|
||||
tags = line.replace('tags:', '').strip()
|
||||
if ingredient_mode:
|
||||
if len(line) > 2 and 'directions:' not in line:
|
||||
ingredients.append(line[2:])
|
||||
if '---' in line and direction_mode:
|
||||
direction_mode = False
|
||||
description_mode = True
|
||||
if direction_mode:
|
||||
if len(line) > 2:
|
||||
directions.append(line[2:])
|
||||
if 'ingredients:' in line:
|
||||
ingredient_mode = True
|
||||
if 'directions:' in line:
|
||||
ingredient_mode = False
|
||||
direction_mode = True
|
||||
if description_mode and len(line) > 3 and '---' not in line:
|
||||
descriptions.append(line)
|
||||
|
||||
recipe = Recipe.objects.create(name=title, created_by=self.request.user, internal=True, space=self.request.space)
|
||||
|
||||
for k in tags.split(','):
|
||||
keyword, created = Keyword.objects.get_or_create(name=k.strip(), space=self.request.space)
|
||||
recipe.keywords.add(keyword)
|
||||
|
||||
step = Step.objects.create(
|
||||
instruction='\n'.join(directions) + '\n\n' + '\n'.join(descriptions)
|
||||
)
|
||||
|
||||
for ingredient in ingredients:
|
||||
amount, unit, ingredient, note = parse(ingredient)
|
||||
f = get_food(ingredient, self.request.space)
|
||||
u = get_unit(unit, self.request.space)
|
||||
step.ingredients.add(Ingredient.objects.create(
|
||||
food=f, unit=u, amount=amount, note=note
|
||||
))
|
||||
recipe.steps.add(step)
|
||||
|
||||
for f in self.files:
|
||||
if '.zip' in f['name']:
|
||||
import_zip = ZipFile(f['file'])
|
||||
for z in import_zip.filelist:
|
||||
if re.match(f'^images/{image}$', z.filename):
|
||||
self.import_recipe_image(recipe, BytesIO(import_zip.read(z.filename)))
|
||||
|
||||
return recipe
|
||||
|
||||
def get_file_from_recipe(self, recipe):
|
||||
raise NotImplementedError('Method not implemented in storage integration')
|
||||
34
cookbook/integration/default.py
Normal file
34
cookbook/integration/default.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import json
|
||||
from io import BytesIO
|
||||
from zipfile import ZipFile
|
||||
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
|
||||
from cookbook.integration.integration import Integration
|
||||
from cookbook.serializer import RecipeExportSerializer
|
||||
|
||||
|
||||
class Default(Integration):
|
||||
|
||||
def get_recipe_from_file(self, file):
|
||||
recipe_zip = ZipFile(file)
|
||||
|
||||
recipe_string = recipe_zip.read('recipe.json').decode("utf-8")
|
||||
recipe = self.decode_recipe(recipe_string)
|
||||
if 'image.png' in recipe_zip.namelist():
|
||||
self.import_recipe_image(recipe, BytesIO(recipe_zip.read('image.png')))
|
||||
return recipe
|
||||
|
||||
def decode_recipe(self, string):
|
||||
data = json.loads(string)
|
||||
serialized_recipe = RecipeExportSerializer(data=data, context={'request': self.request})
|
||||
if serialized_recipe.is_valid():
|
||||
recipe = serialized_recipe.save()
|
||||
return recipe
|
||||
|
||||
return None
|
||||
|
||||
def get_file_from_recipe(self, recipe):
|
||||
export = RecipeExportSerializer(recipe).data
|
||||
|
||||
return 'recipe.json', JSONRenderer().render(export).decode("utf-8")
|
||||
56
cookbook/integration/domestica.py
Normal file
56
cookbook/integration/domestica.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import base64
|
||||
import json
|
||||
from io import BytesIO
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse, get_food, get_unit
|
||||
from cookbook.integration.integration import Integration
|
||||
from cookbook.models import Recipe, Step, Ingredient
|
||||
|
||||
|
||||
class Domestica(Integration):
|
||||
|
||||
def get_recipe_from_file(self, file):
|
||||
|
||||
recipe = Recipe.objects.create(
|
||||
name=file['name'].strip(),
|
||||
created_by=self.request.user, internal=True,
|
||||
space=self.request.space)
|
||||
|
||||
if file['servings'] != '':
|
||||
recipe.servings = file['servings']
|
||||
|
||||
if file['timeCook'] != '':
|
||||
recipe.waiting_time = file['timeCook']
|
||||
|
||||
if file['timePrep'] != '':
|
||||
recipe.working_time = file['timePrep']
|
||||
|
||||
recipe.save()
|
||||
|
||||
step = Step.objects.create(
|
||||
instruction=file['directions']
|
||||
)
|
||||
|
||||
if file['source'] != '':
|
||||
step.instruction += '\n' + file['source']
|
||||
|
||||
for ingredient in file['ingredients'].split('\n'):
|
||||
if len(ingredient.strip()) > 0:
|
||||
amount, unit, ingredient, note = parse(ingredient)
|
||||
f = get_food(ingredient, self.request.space)
|
||||
u = get_unit(unit, self.request.space)
|
||||
step.ingredients.add(Ingredient.objects.create(
|
||||
food=f, unit=u, amount=amount, note=note
|
||||
))
|
||||
recipe.steps.add(step)
|
||||
|
||||
if file['image'] != '':
|
||||
self.import_recipe_image(recipe, BytesIO(base64.b64decode(file['image'].replace('data:image/jpeg;base64,', ''))))
|
||||
|
||||
return recipe
|
||||
|
||||
def get_file_from_recipe(self, recipe):
|
||||
raise NotImplementedError('Method not implemented in storage integration')
|
||||
|
||||
def split_recipe_file(self, file):
|
||||
return json.loads(file.read().decode("utf-8"))
|
||||
207
cookbook/integration/integration.py
Normal file
207
cookbook/integration/integration.py
Normal file
@@ -0,0 +1,207 @@
|
||||
import datetime
|
||||
import json
|
||||
import uuid
|
||||
from io import BytesIO, StringIO
|
||||
from zipfile import ZipFile, BadZipFile
|
||||
|
||||
from django.core.files import File
|
||||
from django.http import HttpResponse
|
||||
from django.utils.formats import date_format
|
||||
from django.utils.translation import gettext as _
|
||||
from django_scopes import scope
|
||||
|
||||
from cookbook.forms import ImportExportBase
|
||||
from cookbook.models import Keyword, Recipe
|
||||
|
||||
|
||||
class Integration:
|
||||
request = None
|
||||
keyword = None
|
||||
files = None
|
||||
export_type = None
|
||||
ignored_recipes = []
|
||||
|
||||
def __init__(self, request, export_type):
|
||||
"""
|
||||
Integration for importing and exporting recipes
|
||||
:param request: request context of import session (used to link user to created objects)
|
||||
"""
|
||||
self.request = request
|
||||
self.export_type = export_type
|
||||
self.keyword = Keyword.objects.create(
|
||||
name=f'Import {export_type} {date_format(datetime.datetime.now(), "DATETIME_FORMAT")}.{datetime.datetime.now().strftime("%S")}',
|
||||
description=f'Imported by {request.user.get_user_name()} at {date_format(datetime.datetime.now(), "DATETIME_FORMAT")}. Type: {export_type}',
|
||||
icon='📥',
|
||||
space=request.space
|
||||
)
|
||||
|
||||
def do_export(self, recipes):
|
||||
"""
|
||||
Perform the export based on a list of recipes
|
||||
:param recipes: list of recipe objects
|
||||
:return: HttpResponse with a ZIP file that is directly downloaded
|
||||
"""
|
||||
|
||||
# TODO this is temporary, find a better solution for different export formats when doing other exporters
|
||||
if self.export_type != ImportExportBase.RECIPESAGE:
|
||||
export_zip_stream = BytesIO()
|
||||
export_zip_obj = ZipFile(export_zip_stream, 'w')
|
||||
|
||||
for r in recipes:
|
||||
if r.internal and r.space == self.request.space:
|
||||
recipe_zip_stream = BytesIO()
|
||||
recipe_zip_obj = ZipFile(recipe_zip_stream, 'w')
|
||||
|
||||
recipe_stream = StringIO()
|
||||
filename, data = self.get_file_from_recipe(r)
|
||||
recipe_stream.write(data)
|
||||
recipe_zip_obj.writestr(filename, recipe_stream.getvalue())
|
||||
recipe_stream.close()
|
||||
try:
|
||||
recipe_zip_obj.writestr('image.png', r.image.file.read())
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
recipe_zip_obj.close()
|
||||
export_zip_obj.writestr(str(r.pk) + '.zip', recipe_zip_stream.getvalue())
|
||||
|
||||
export_zip_obj.close()
|
||||
|
||||
response = HttpResponse(export_zip_stream.getvalue(), content_type='application/force-download')
|
||||
response['Content-Disposition'] = 'attachment; filename="export.zip"'
|
||||
return response
|
||||
else:
|
||||
json_list = []
|
||||
for r in recipes:
|
||||
json_list.append(self.get_file_from_recipe(r))
|
||||
|
||||
response = HttpResponse(json.dumps(json_list), content_type='application/force-download')
|
||||
response['Content-Disposition'] = 'attachment; filename="recipes.json"'
|
||||
return response
|
||||
|
||||
def import_file_name_filter(self, zip_info_object):
|
||||
"""
|
||||
Since zipfile.namelist() returns all files in all subdirectories this function allows filtering of files
|
||||
If false is returned the file will be ignored
|
||||
By default all files are included
|
||||
:param zip_info_object: ZipInfo object
|
||||
:return: Boolean if object should be included
|
||||
"""
|
||||
return True
|
||||
|
||||
def do_import(self, files, il, import_duplicates):
|
||||
"""
|
||||
Imports given files
|
||||
:param import_duplicates: if true duplicates are imported as well
|
||||
:param files: List of in memory files
|
||||
:param il: Import Log object to refresh while running
|
||||
:return: HttpResponseRedirect to the recipe search showing all imported recipes
|
||||
"""
|
||||
with scope(space=self.request.space):
|
||||
self.keyword.name = _('Import') + ' ' + str(il.pk)
|
||||
self.keyword.save()
|
||||
|
||||
try:
|
||||
self.files = files
|
||||
for f in files:
|
||||
if '.zip' in f['name'] or '.paprikarecipes' in f['name']:
|
||||
import_zip = ZipFile(f['file'])
|
||||
for z in import_zip.filelist:
|
||||
if self.import_file_name_filter(z):
|
||||
try:
|
||||
recipe = self.get_recipe_from_file(BytesIO(import_zip.read(z.filename)))
|
||||
recipe.keywords.add(self.keyword)
|
||||
il.msg += f'{recipe.pk} - {recipe.name} \n'
|
||||
self.handle_duplicates(recipe, import_duplicates)
|
||||
except Exception as e:
|
||||
il.msg += f'-------------------- \n ERROR \n{e}\n--------------------\n'
|
||||
import_zip.close()
|
||||
elif '.json' in f['name'] or '.txt' in f['name']:
|
||||
data_list = self.split_recipe_file(f['file'])
|
||||
for d in data_list:
|
||||
try:
|
||||
recipe = self.get_recipe_from_file(d)
|
||||
recipe.keywords.add(self.keyword)
|
||||
il.msg += f'{recipe.pk} - {recipe.name} \n'
|
||||
self.handle_duplicates(recipe, import_duplicates)
|
||||
except Exception as e:
|
||||
il.msg += f'-------------------- \n ERROR \n{e}\n--------------------\n'
|
||||
elif '.rtk' in f['name']:
|
||||
import_zip = ZipFile(f['file'])
|
||||
for z in import_zip.filelist:
|
||||
if self.import_file_name_filter(z):
|
||||
data_list = self.split_recipe_file(import_zip.read(z.filename).decode('utf-8'))
|
||||
for d in data_list:
|
||||
try:
|
||||
recipe = self.get_recipe_from_file(d)
|
||||
recipe.keywords.add(self.keyword)
|
||||
il.msg += f'{recipe.pk} - {recipe.name} \n'
|
||||
self.handle_duplicates(recipe, import_duplicates)
|
||||
except Exception as e:
|
||||
il.msg += f'-------------------- \n ERROR \n{e}\n--------------------\n'
|
||||
import_zip.close()
|
||||
else:
|
||||
recipe = self.get_recipe_from_file(f['file'])
|
||||
recipe.keywords.add(self.keyword)
|
||||
il.msg += f'{recipe.pk} - {recipe.name} \n'
|
||||
self.handle_duplicates(recipe, import_duplicates)
|
||||
except BadZipFile:
|
||||
il.msg += 'ERROR ' + _(
|
||||
'Importer expected a .zip file. Did you choose the correct importer type for your data ?') + '\n'
|
||||
|
||||
if len(self.ignored_recipes) > 0:
|
||||
il.msg += '\n' + _(
|
||||
'The following recipes were ignored because they already existed:') + ' ' + ', '.join(
|
||||
self.ignored_recipes) + '\n\n'
|
||||
|
||||
il.keyword = self.keyword
|
||||
il.msg += (_('Imported %s recipes.') % Recipe.objects.filter(keywords=self.keyword).count()) + '\n'
|
||||
il.running = False
|
||||
il.save()
|
||||
|
||||
def handle_duplicates(self, recipe, import_duplicates):
|
||||
"""
|
||||
Checks if a recipe is already present, if so deletes it
|
||||
:param recipe: Recipe object
|
||||
:param import_duplicates: if duplicates should be imported
|
||||
"""
|
||||
if Recipe.objects.filter(space=self.request.space, name=recipe.name).count() > 1 and not import_duplicates:
|
||||
recipe.delete()
|
||||
self.ignored_recipes.append(recipe.name)
|
||||
|
||||
@staticmethod
|
||||
def import_recipe_image(recipe, image_file):
|
||||
"""
|
||||
Adds an image to a recipe naming it correctly
|
||||
:param recipe: Recipe object
|
||||
:param image_file: ByteIO stream containing the image
|
||||
"""
|
||||
recipe.image = File(image_file, name=f'{uuid.uuid4()}_{recipe.pk}.png')
|
||||
recipe.save()
|
||||
|
||||
def get_recipe_from_file(self, file):
|
||||
"""
|
||||
Takes any file like object and converts it into a recipe
|
||||
:param file: ByteIO or any file like object, depends on provider
|
||||
:return: Recipe object
|
||||
"""
|
||||
raise NotImplementedError('Method not implemented in integration')
|
||||
|
||||
def split_recipe_file(self, file):
|
||||
"""
|
||||
Takes a file that contains multiple recipes and splits it into a list of strings of various formats (e.g. json, text, ..)
|
||||
:param file: ByteIO or any file like object, depends on provider
|
||||
:return: list of strings
|
||||
"""
|
||||
raise NotImplementedError('Method not implemented in integration')
|
||||
|
||||
def get_file_from_recipe(self, recipe):
|
||||
"""
|
||||
Takes a recipe object and converts it to a string (depending on the format)
|
||||
returns both the filename of the exported file and the file contents
|
||||
:param recipe: Recipe object that should be converted
|
||||
:returns:
|
||||
- name - file name in export
|
||||
- data - string content for file to get created in export zip
|
||||
"""
|
||||
raise NotImplementedError('Method not implemented in integration')
|
||||
57
cookbook/integration/mealie.py
Normal file
57
cookbook/integration/mealie.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import json
|
||||
import re
|
||||
from io import BytesIO
|
||||
from zipfile import ZipFile
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse, get_food, get_unit
|
||||
from cookbook.integration.integration import Integration
|
||||
from cookbook.models import Recipe, Step, Food, Unit, Ingredient
|
||||
|
||||
|
||||
class Mealie(Integration):
|
||||
|
||||
def import_file_name_filter(self, zip_info_object):
|
||||
return re.match(r'^recipes/([A-Za-z\d-])+.json$', zip_info_object.filename)
|
||||
|
||||
def get_recipe_from_file(self, file):
|
||||
recipe_json = json.loads(file.getvalue().decode("utf-8"))
|
||||
|
||||
description = '' if len(recipe_json['description'].strip()) > 500 else recipe_json['description'].strip()
|
||||
|
||||
recipe = Recipe.objects.create(
|
||||
name=recipe_json['name'].strip(), description=description,
|
||||
created_by=self.request.user, internal=True, space=self.request.space)
|
||||
|
||||
# TODO parse times (given in PT2H3M )
|
||||
|
||||
ingredients_added = False
|
||||
for s in recipe_json['recipeInstructions']:
|
||||
step = Step.objects.create(
|
||||
instruction=s['text']
|
||||
)
|
||||
if not ingredients_added:
|
||||
ingredients_added = True
|
||||
|
||||
if len(recipe_json['description'].strip()) > 500:
|
||||
step.instruction = recipe_json['description'].strip() + '\n\n' + step.instruction
|
||||
|
||||
for ingredient in recipe_json['recipeIngredient']:
|
||||
amount, unit, ingredient, note = parse(ingredient)
|
||||
f = get_food(ingredient, self.request.space)
|
||||
u = get_unit(unit, self.request.space)
|
||||
step.ingredients.add(Ingredient.objects.create(
|
||||
food=f, unit=u, amount=amount, note=note
|
||||
))
|
||||
recipe.steps.add(step)
|
||||
|
||||
for f in self.files:
|
||||
if '.zip' in f['name']:
|
||||
import_zip = ZipFile(f['file'])
|
||||
for z in import_zip.filelist:
|
||||
if re.match(f'^images/{recipe_json["slug"]}.jpg$', z.filename):
|
||||
self.import_recipe_image(recipe, BytesIO(import_zip.read(z.filename)))
|
||||
|
||||
return recipe
|
||||
|
||||
def get_file_from_recipe(self, recipe):
|
||||
raise NotImplementedError('Method not implemented in storage integration')
|
||||
83
cookbook/integration/mealmaster.py
Normal file
83
cookbook/integration/mealmaster.py
Normal file
@@ -0,0 +1,83 @@
|
||||
import json
|
||||
import re
|
||||
from io import BytesIO
|
||||
from zipfile import ZipFile
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse, get_food, get_unit
|
||||
from cookbook.integration.integration import Integration
|
||||
from cookbook.models import Recipe, Step, Food, Unit, Ingredient, Keyword
|
||||
|
||||
|
||||
class MealMaster(Integration):
|
||||
|
||||
def get_recipe_from_file(self, file):
|
||||
print('------------ getting recipe')
|
||||
servings = 1
|
||||
ingredients = []
|
||||
directions = []
|
||||
for line in file.replace('\r', '').split('\n'):
|
||||
print('testing line')
|
||||
if not line.startswith('MMMMM') and line.strip != '':
|
||||
if 'Title:' in line:
|
||||
title = line.replace('Title:', '').strip()
|
||||
else:
|
||||
if 'Categories:' in line:
|
||||
tags = line.replace('Categories:', '').strip()
|
||||
else:
|
||||
if 'Yield:' in line:
|
||||
servings_text = line.replace('Yield:', '').strip()
|
||||
else:
|
||||
if re.match('\s{2,}([0-9])+', line):
|
||||
ingredients.append(line.strip())
|
||||
else:
|
||||
directions.append(line.strip())
|
||||
|
||||
try:
|
||||
servings = re.findall('([0-9])+', servings_text)[0]
|
||||
except Exception as e:
|
||||
print('failed parsing servings ', e)
|
||||
|
||||
recipe = Recipe.objects.create(name=title, servings=servings, created_by=self.request.user, internal=True, space=self.request.space)
|
||||
|
||||
for k in tags.split(','):
|
||||
keyword, created = Keyword.objects.get_or_create(name=k.strip(), space=self.request.space)
|
||||
recipe.keywords.add(keyword)
|
||||
|
||||
step = Step.objects.create(
|
||||
instruction='\n'.join(directions) + '\n\n'
|
||||
)
|
||||
|
||||
for ingredient in ingredients:
|
||||
if len(ingredient.strip()) > 0:
|
||||
amount, unit, ingredient, note = parse(ingredient)
|
||||
f = get_food(ingredient, self.request.space)
|
||||
u = get_unit(unit, self.request.space)
|
||||
step.ingredients.add(Ingredient.objects.create(
|
||||
food=f, unit=u, amount=amount, note=note
|
||||
))
|
||||
recipe.steps.add(step)
|
||||
|
||||
return recipe
|
||||
|
||||
def get_file_from_recipe(self, recipe):
|
||||
raise NotImplementedError('Method not implemented in storage integration')
|
||||
|
||||
def split_recipe_file(self, file):
|
||||
recipe_list = []
|
||||
current_recipe = ''
|
||||
|
||||
for fl in file.readlines():
|
||||
line = fl.decode("ANSI")
|
||||
if (line.startswith('MMMMM') or line.startswith('-----')) and 'meal-master' in line.lower():
|
||||
if current_recipe != '':
|
||||
recipe_list.append(current_recipe)
|
||||
current_recipe = ''
|
||||
else:
|
||||
current_recipe = ''
|
||||
else:
|
||||
current_recipe += line + '\n'
|
||||
|
||||
if current_recipe != '':
|
||||
recipe_list.append(current_recipe)
|
||||
|
||||
return recipe_list
|
||||
59
cookbook/integration/nextcloud_cookbook.py
Normal file
59
cookbook/integration/nextcloud_cookbook.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import json
|
||||
import re
|
||||
from io import BytesIO
|
||||
from zipfile import ZipFile
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse, get_food, get_unit
|
||||
from cookbook.integration.integration import Integration
|
||||
from cookbook.models import Recipe, Step, Food, Unit, Ingredient
|
||||
|
||||
|
||||
class NextcloudCookbook(Integration):
|
||||
|
||||
def import_file_name_filter(self, zip_info_object):
|
||||
return zip_info_object.filename.endswith('.json')
|
||||
|
||||
def get_recipe_from_file(self, file):
|
||||
recipe_json = json.loads(file.getvalue().decode("utf-8"))
|
||||
|
||||
description = '' if len(recipe_json['description'].strip()) > 500 else recipe_json['description'].strip()
|
||||
|
||||
recipe = Recipe.objects.create(
|
||||
name=recipe_json['name'].strip(), description=description,
|
||||
created_by=self.request.user, internal=True,
|
||||
servings=recipe_json['recipeYield'], space=self.request.space)
|
||||
|
||||
# TODO parse times (given in PT2H3M )
|
||||
# TODO parse keywords
|
||||
|
||||
ingredients_added = False
|
||||
for s in recipe_json['recipeInstructions']:
|
||||
step = Step.objects.create(
|
||||
instruction=s
|
||||
)
|
||||
if not ingredients_added:
|
||||
if len(recipe_json['description'].strip()) > 500:
|
||||
step.instruction = recipe_json['description'].strip() + '\n\n' + step.instruction
|
||||
|
||||
ingredients_added = True
|
||||
|
||||
for ingredient in recipe_json['recipeIngredient']:
|
||||
amount, unit, ingredient, note = parse(ingredient)
|
||||
f = get_food(ingredient, self.request.space)
|
||||
u = get_unit(unit, self.request.space)
|
||||
step.ingredients.add(Ingredient.objects.create(
|
||||
food=f, unit=u, amount=amount, note=note
|
||||
))
|
||||
recipe.steps.add(step)
|
||||
|
||||
for f in self.files:
|
||||
if '.zip' in f['name']:
|
||||
import_zip = ZipFile(f['file'])
|
||||
for z in import_zip.filelist:
|
||||
if re.match(f'^Recipes/{recipe.name}/full.jpg$', z.filename):
|
||||
self.import_recipe_image(recipe, BytesIO(import_zip.read(z.filename)))
|
||||
|
||||
return recipe
|
||||
|
||||
def get_file_from_recipe(self, recipe):
|
||||
raise NotImplementedError('Method not implemented in storage integration')
|
||||
86
cookbook/integration/paprika.py
Normal file
86
cookbook/integration/paprika.py
Normal file
@@ -0,0 +1,86 @@
|
||||
import base64
|
||||
import gzip
|
||||
import json
|
||||
import re
|
||||
from io import BytesIO
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse, get_food, get_unit
|
||||
from cookbook.integration.integration import Integration
|
||||
from cookbook.models import Recipe, Step, Ingredient, Keyword
|
||||
from gettext import gettext as _
|
||||
|
||||
|
||||
class Paprika(Integration):
|
||||
|
||||
def get_file_from_recipe(self, recipe):
|
||||
raise NotImplementedError('Method not implemented in storage integration')
|
||||
|
||||
def get_recipe_from_file(self, file):
|
||||
with gzip.open(file, 'r') as recipe_zip:
|
||||
recipe_json = json.loads(recipe_zip.read().decode("utf-8"))
|
||||
|
||||
recipe = Recipe.objects.create(
|
||||
name=recipe_json['name'].strip(), created_by=self.request.user, internal=True, space=self.request.space)
|
||||
|
||||
if 'description' in recipe_json:
|
||||
recipe.description = '' if len(recipe_json['description'].strip()) > 500 else recipe_json['description'].strip()
|
||||
|
||||
try:
|
||||
if re.match(r'([0-9])+\s(.)*', recipe_json['servings']):
|
||||
s = recipe_json['servings'].split(' ')
|
||||
recipe.servings = s[0]
|
||||
recipe.servings_text = s[1]
|
||||
|
||||
if len(recipe_json['cook_time'].strip()) > 0:
|
||||
recipe.waiting_time = re.findall(r'\d+', recipe_json['cook_time'])[0]
|
||||
|
||||
if len(recipe_json['prep_time'].strip()) > 0:
|
||||
recipe.working_time = re.findall(r'\d+', recipe_json['prep_time'])[0]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
recipe.save()
|
||||
|
||||
instructions = recipe_json['directions']
|
||||
if recipe_json['notes'] and len(recipe_json['notes'].strip()) > 0:
|
||||
instructions += '\n\n### ' + _('Notes') + ' \n' + recipe_json['notes']
|
||||
|
||||
if recipe_json['nutritional_info'] and len(recipe_json['nutritional_info'].strip()) > 0:
|
||||
instructions += '\n\n### ' + _('Nutritional Information') + ' \n' + recipe_json['nutritional_info']
|
||||
|
||||
try:
|
||||
if len(recipe_json['source'].strip()) > 0 or len(recipe_json['source_url'].strip()) > 0:
|
||||
instructions += '\n\n### ' + _('Source') + ' \n' + recipe_json['source'].strip() + ' \n' + recipe_json['source_url'].strip()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
step = Step.objects.create(
|
||||
instruction=instructions
|
||||
)
|
||||
|
||||
if len(recipe_json['description'].strip()) > 500:
|
||||
step.instruction = recipe_json['description'].strip() + '\n\n' + step.instruction
|
||||
|
||||
if 'categories' in recipe_json:
|
||||
for c in recipe_json['categories']:
|
||||
keyword, created = Keyword.objects.get_or_create(name=c.strip(), space=self.request.space)
|
||||
recipe.keywords.add(keyword)
|
||||
|
||||
try:
|
||||
for ingredient in recipe_json['ingredients'].split('\n'):
|
||||
if len(ingredient.strip()) > 0:
|
||||
amount, unit, ingredient, note = parse(ingredient)
|
||||
f = get_food(ingredient, self.request.space)
|
||||
u = get_unit(unit, self.request.space)
|
||||
step.ingredients.add(Ingredient.objects.create(
|
||||
food=f, unit=u, amount=amount, note=note
|
||||
))
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
recipe.steps.add(step)
|
||||
|
||||
if recipe_json.get("photo_data", None):
|
||||
self.import_recipe_image(recipe, BytesIO(base64.b64decode(recipe_json['photo_data'])))
|
||||
|
||||
return recipe
|
||||
135
cookbook/integration/recettetek.py
Normal file
135
cookbook/integration/recettetek.py
Normal file
@@ -0,0 +1,135 @@
|
||||
import re
|
||||
import json
|
||||
import base64
|
||||
import requests
|
||||
from io import BytesIO
|
||||
from zipfile import ZipFile
|
||||
import imghdr
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse, get_food, get_unit
|
||||
from cookbook.integration.integration import Integration
|
||||
from cookbook.models import Recipe, Step, Food, Unit, Ingredient, Keyword
|
||||
|
||||
|
||||
class RecetteTek(Integration):
|
||||
|
||||
def import_file_name_filter(self, zip_info_object):
|
||||
print("testing", zip_info_object.filename)
|
||||
return re.match(r'^recipes_0.json$', zip_info_object.filename) or re.match(r'^recipes.json$', zip_info_object.filename)
|
||||
|
||||
def split_recipe_file(self, file):
|
||||
|
||||
recipe_json = json.loads(file)
|
||||
|
||||
recipe_list = [r for r in recipe_json]
|
||||
|
||||
return recipe_list
|
||||
|
||||
def get_recipe_from_file(self, file):
|
||||
|
||||
# Create initial recipe with just a title and a decription
|
||||
recipe = Recipe.objects.create(name=file['title'], created_by=self.request.user, internal=True, space=self.request.space, )
|
||||
|
||||
# set the description as an empty string for later use for the source URL, incase there is no description text.
|
||||
recipe.description = ''
|
||||
|
||||
try:
|
||||
if file['description'] != '':
|
||||
recipe.description = file['description'].strip()
|
||||
except Exception as e:
|
||||
print(recipe.name, ': failed to parse recipe description ', str(e))
|
||||
|
||||
instructions = file['instructions']
|
||||
if not instructions:
|
||||
instructions = ''
|
||||
|
||||
step = Step.objects.create(instruction=instructions)
|
||||
|
||||
# Append the original import url to the step (if it exists)
|
||||
try:
|
||||
if file['url'] != '':
|
||||
step.instruction += '\n\nImported from: ' + file['url']
|
||||
step.save()
|
||||
except Exception as e:
|
||||
print(recipe.name, ': failed to import source url ', str(e))
|
||||
|
||||
try:
|
||||
# Process the ingredients. Assumes 1 ingredient per line.
|
||||
for ingredient in file['ingredients'].split('\n'):
|
||||
if len(ingredient.strip()) > 0:
|
||||
amount, unit, ingredient, note = parse(ingredient)
|
||||
f = get_food(ingredient, self.request.space)
|
||||
u = get_unit(unit, self.request.space)
|
||||
step.ingredients.add(Ingredient.objects.create(
|
||||
food=f, unit=u, amount=amount, note=note
|
||||
))
|
||||
except Exception as e:
|
||||
print(recipe.name, ': failed to parse recipe ingredients ', str(e))
|
||||
recipe.steps.add(step)
|
||||
|
||||
# Attempt to import prep/cooking times
|
||||
# quick hack, this assumes only one number in the quantity field.
|
||||
try:
|
||||
if file['quantity'] != '':
|
||||
for item in file['quantity'].split(' '):
|
||||
if item.isdigit():
|
||||
recipe.servings = int(item)
|
||||
break
|
||||
except Exception as e:
|
||||
print(recipe.name, ': failed to parse quantity ', str(e))
|
||||
|
||||
try:
|
||||
if file['totalTime'] != '':
|
||||
recipe.waiting_time = int(file['totalTime'])
|
||||
except Exception as e:
|
||||
print(recipe.name, ': failed to parse total times ', str(e))
|
||||
|
||||
try:
|
||||
if file['preparationTime'] != '':
|
||||
recipe.working_time = int(file['preparationTime'])
|
||||
except Exception as e:
|
||||
print(recipe.name, ': failed to parse prep time ', str(e))
|
||||
|
||||
try:
|
||||
if file['cookingTime'] != '':
|
||||
recipe.waiting_time = int(file['cookingTime'])
|
||||
except Exception as e:
|
||||
print(recipe.name, ': failed to parse cooking time ', str(e))
|
||||
|
||||
recipe.save()
|
||||
|
||||
# Import the recipe keywords
|
||||
try:
|
||||
if file['keywords'] != '':
|
||||
for keyword in file['keywords'].split(';'):
|
||||
k, created = Keyword.objects.get_or_create(name=keyword.strip(), space=self.request.space)
|
||||
recipe.keywords.add(k)
|
||||
recipe.save()
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
# TODO: Parse Nutritional Information
|
||||
|
||||
# Import the original image from the zip file, if we cannot do that, attempt to download it again.
|
||||
try:
|
||||
if file['pictures'][0] !='':
|
||||
image_file_name = file['pictures'][0].split('/')[-1]
|
||||
for f in self.files:
|
||||
if '.rtk' in f['name']:
|
||||
import_zip = ZipFile(f['file'])
|
||||
self.import_recipe_image(recipe, BytesIO(import_zip.read(image_file_name)))
|
||||
else:
|
||||
if file['originalPicture'] != '':
|
||||
response=requests.get(file['originalPicture'])
|
||||
if imghdr.what(BytesIO(response.content)) != None:
|
||||
self.import_recipe_image(recipe, BytesIO(response.content))
|
||||
else:
|
||||
raise Exception("Original image failed to download.")
|
||||
except Exception as e:
|
||||
print(recipe.name, ': failed to import image ', str(e))
|
||||
|
||||
return recipe
|
||||
|
||||
def get_file_from_recipe(self, recipe):
|
||||
raise NotImplementedError('Method not implemented in storage integration')
|
||||
93
cookbook/integration/recipesage.py
Normal file
93
cookbook/integration/recipesage.py
Normal file
@@ -0,0 +1,93 @@
|
||||
import base64
|
||||
import json
|
||||
from io import BytesIO
|
||||
|
||||
import requests
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse, get_food, get_unit
|
||||
from cookbook.integration.integration import Integration
|
||||
from cookbook.models import Recipe, Step, Ingredient
|
||||
|
||||
|
||||
class RecipeSage(Integration):
|
||||
|
||||
def get_recipe_from_file(self, file):
|
||||
|
||||
recipe = Recipe.objects.create(
|
||||
name=file['name'].strip(),
|
||||
created_by=self.request.user, internal=True,
|
||||
space=self.request.space)
|
||||
|
||||
try:
|
||||
if file['recipeYield'] != '':
|
||||
recipe.servings = int(file['recipeYield'])
|
||||
|
||||
if file['totalTime'] != '':
|
||||
recipe.waiting_time = int(file['totalTime']) - int(file['timePrep'])
|
||||
|
||||
if file['prepTime'] != '':
|
||||
recipe.working_time = int(file['timePrep'])
|
||||
|
||||
recipe.save()
|
||||
except Exception as e:
|
||||
print('failed to parse yield or time ', str(e))
|
||||
|
||||
ingredients_added = False
|
||||
for s in file['recipeInstructions']:
|
||||
step = Step.objects.create(
|
||||
instruction=s['text']
|
||||
)
|
||||
if not ingredients_added:
|
||||
ingredients_added = True
|
||||
|
||||
for ingredient in file['recipeIngredient']:
|
||||
amount, unit, ingredient, note = parse(ingredient)
|
||||
f = get_food(ingredient, self.request.space)
|
||||
u = get_unit(unit, self.request.space)
|
||||
step.ingredients.add(Ingredient.objects.create(
|
||||
food=f, unit=u, amount=amount, note=note
|
||||
))
|
||||
recipe.steps.add(step)
|
||||
|
||||
if len(file['image']) > 0:
|
||||
try:
|
||||
response = requests.get(file['image'][0])
|
||||
self.import_recipe_image(recipe, BytesIO(response.content))
|
||||
except Exception as e:
|
||||
print('failed to import image ', str(e))
|
||||
|
||||
return recipe
|
||||
|
||||
def get_file_from_recipe(self, recipe):
|
||||
data = {
|
||||
'@context': 'http://schema.org',
|
||||
'@type': 'Recipe',
|
||||
'creditText': '',
|
||||
'isBasedOn': '',
|
||||
'name': recipe.name,
|
||||
'description': recipe.description,
|
||||
'prepTime': str(recipe.working_time),
|
||||
'totalTime': str(recipe.waiting_time + recipe.working_time),
|
||||
'recipeYield': str(recipe.servings),
|
||||
'image': [],
|
||||
'recipeCategory': [],
|
||||
'comment': [],
|
||||
'recipeIngredient': [],
|
||||
'recipeInstructions': [],
|
||||
}
|
||||
|
||||
for s in recipe.steps.all():
|
||||
if s.type != Step.TIME:
|
||||
data['recipeInstructions'].append({
|
||||
'@type': 'HowToStep',
|
||||
'text': s.instruction
|
||||
})
|
||||
|
||||
for i in s.ingredients.all():
|
||||
data['recipeIngredient'].append(f'{float(i.amount)} {i.unit} {i.food}')
|
||||
|
||||
return data
|
||||
|
||||
def split_recipe_file(self, file):
|
||||
return json.loads(file.read().decode("utf-8"))
|
||||
82
cookbook/integration/rezkonv.py
Normal file
82
cookbook/integration/rezkonv.py
Normal file
@@ -0,0 +1,82 @@
|
||||
import json
|
||||
import re
|
||||
from io import BytesIO
|
||||
from zipfile import ZipFile
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse, get_food, get_unit
|
||||
from cookbook.integration.integration import Integration
|
||||
from cookbook.models import Recipe, Step, Food, Unit, Ingredient, Keyword
|
||||
|
||||
|
||||
class RezKonv(Integration):
|
||||
|
||||
def get_recipe_from_file(self, file):
|
||||
|
||||
ingredient_mode = False
|
||||
direction_mode = False
|
||||
|
||||
ingredients = []
|
||||
directions = []
|
||||
for line in file.replace('\r', '').split('\n'):
|
||||
if 'Titel:' in line:
|
||||
title = line.replace('Titel:', '').strip()
|
||||
if 'Kategorien:' in line:
|
||||
tags = line.replace('Kategorien:', '').strip()
|
||||
if ingredient_mode and ('quelle' in line.lower() or 'source' in line.lower()):
|
||||
ingredient_mode = False
|
||||
if ingredient_mode:
|
||||
if line != '' and '===' not in line and 'Zubereitung' not in line:
|
||||
ingredients.append(line.strip())
|
||||
if direction_mode:
|
||||
if line.strip() != '' and line.strip() != '=====':
|
||||
directions.append(line.strip())
|
||||
if 'Zutaten:' in line:
|
||||
ingredient_mode = True
|
||||
if 'Zubereitung:' in line:
|
||||
ingredient_mode = False
|
||||
direction_mode = True
|
||||
|
||||
recipe = Recipe.objects.create(name=title, created_by=self.request.user, internal=True, space=self.request.space)
|
||||
|
||||
for k in tags.split(','):
|
||||
keyword, created = Keyword.objects.get_or_create(name=k.strip(), space=self.request.space)
|
||||
recipe.keywords.add(keyword)
|
||||
|
||||
step = Step.objects.create(
|
||||
instruction='\n'.join(directions) + '\n\n'
|
||||
)
|
||||
|
||||
for ingredient in ingredients:
|
||||
if len(ingredient.strip()) > 0:
|
||||
amount, unit, ingredient, note = parse(ingredient)
|
||||
f = get_food(ingredient, self.request.space)
|
||||
u = get_unit(unit, self.request.space)
|
||||
step.ingredients.add(Ingredient.objects.create(
|
||||
food=f, unit=u, amount=amount, note=note
|
||||
))
|
||||
recipe.steps.add(step)
|
||||
|
||||
return recipe
|
||||
|
||||
def get_file_from_recipe(self, recipe):
|
||||
raise NotImplementedError('Method not implemented in storage integration')
|
||||
|
||||
def split_recipe_file(self, file):
|
||||
recipe_list = []
|
||||
current_recipe = ''
|
||||
|
||||
for fl in file.readlines():
|
||||
line = fl.decode("ANSI")
|
||||
if line.startswith('=====') and 'rezkonv' in line.lower():
|
||||
if current_recipe != '':
|
||||
recipe_list.append(current_recipe)
|
||||
current_recipe = ''
|
||||
else:
|
||||
current_recipe = ''
|
||||
else:
|
||||
current_recipe += line + '\n'
|
||||
|
||||
if current_recipe != '':
|
||||
recipe_list.append(current_recipe)
|
||||
|
||||
return recipe_list
|
||||
60
cookbook/integration/safron.py
Normal file
60
cookbook/integration/safron.py
Normal file
@@ -0,0 +1,60 @@
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse, get_food, get_unit
|
||||
from cookbook.integration.integration import Integration
|
||||
from cookbook.models import Recipe, Step, Food, Unit, Ingredient
|
||||
|
||||
|
||||
class Safron(Integration):
|
||||
|
||||
def get_recipe_from_file(self, file):
|
||||
ingredient_mode = False
|
||||
direction_mode = False
|
||||
|
||||
ingredients = []
|
||||
directions = []
|
||||
for fl in file.readlines():
|
||||
line = fl.decode("utf-8")
|
||||
if 'Title:' in line:
|
||||
title = line.replace('Title:', '').strip()
|
||||
if 'Description:' in line:
|
||||
description = line.replace('Description:', '').strip()
|
||||
if 'Yield:' in line:
|
||||
directions.append(_('Servings') + ' ' + line.replace('Yield:', '').strip() + '\n')
|
||||
if 'Cook:' in line:
|
||||
directions.append(_('Waiting time') + ' ' + line.replace('Cook:', '').strip() + '\n')
|
||||
if 'Prep:' in line:
|
||||
directions.append(_('Preparation Time') + ' ' + line.replace('Prep:', '').strip() + '\n')
|
||||
if 'Cookbook:' in line:
|
||||
directions.append(_('Cookbook') + ' ' + line.replace('Cookbook:', '').strip() + '\n')
|
||||
if 'Section:' in line:
|
||||
directions.append(_('Section') + ' ' + line.replace('Section:', '').strip() + '\n')
|
||||
if ingredient_mode:
|
||||
if len(line) > 2 and 'Instructions:' not in line:
|
||||
ingredients.append(line.strip())
|
||||
if direction_mode:
|
||||
if len(line) > 2:
|
||||
directions.append(line.strip())
|
||||
if 'Ingredients:' in line:
|
||||
ingredient_mode = True
|
||||
if 'Instructions:' in line:
|
||||
ingredient_mode = False
|
||||
direction_mode = True
|
||||
|
||||
recipe = Recipe.objects.create(name=title, description=description, created_by=self.request.user, internal=True, space=self.request.space, )
|
||||
|
||||
step = Step.objects.create(instruction='\n'.join(directions))
|
||||
|
||||
for ingredient in ingredients:
|
||||
amount, unit, ingredient, note = parse(ingredient)
|
||||
f = get_food(ingredient, self.request.space)
|
||||
u = get_unit(unit, self.request.space)
|
||||
step.ingredients.add(Ingredient.objects.create(
|
||||
food=f, unit=u, amount=amount, note=note
|
||||
))
|
||||
recipe.steps.add(step)
|
||||
|
||||
return recipe
|
||||
|
||||
def get_file_from_recipe(self, recipe):
|
||||
raise NotImplementedError('Method not implemented in storage integration')
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
cookbook/locale/cs/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/cs/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
1871
cookbook/locale/cs/LC_MESSAGES/django.po
Normal file
1871
cookbook/locale/cs/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
cookbook/locale/es/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/es/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
2053
cookbook/locale/es/LC_MESSAGES/django.po
Normal file
2053
cookbook/locale/es/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
cookbook/locale/hu_HU/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/hu_HU/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
1835
cookbook/locale/hu_HU/LC_MESSAGES/django.po
Normal file
1835
cookbook/locale/hu_HU/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
BIN
cookbook/locale/hy/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/hy/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
1881
cookbook/locale/hy/LC_MESSAGES/django.po
Normal file
1881
cookbook/locale/hy/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
BIN
cookbook/locale/it/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/it/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
2006
cookbook/locale/it/LC_MESSAGES/django.po
Normal file
2006
cookbook/locale/it/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
BIN
cookbook/locale/lv/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/lv/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
1986
cookbook/locale/lv/LC_MESSAGES/django.po
Normal file
1986
cookbook/locale/lv/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
1832
cookbook/locale/nb_NO/LC_MESSAGES/django.po
Normal file
1832
cookbook/locale/nb_NO/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
cookbook/locale/pl/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/pl/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
1797
cookbook/locale/pl/LC_MESSAGES/django.po
Normal file
1797
cookbook/locale/pl/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
1853
cookbook/locale/sv/LC_MESSAGES/django.po
Normal file
1853
cookbook/locale/sv/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
cookbook/locale/vi/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/vi/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
1787
cookbook/locale/vi/LC_MESSAGES/django.po
Normal file
1787
cookbook/locale/vi/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
BIN
cookbook/locale/zh_CN/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/zh_CN/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
1824
cookbook/locale/zh_CN/LC_MESSAGES/django.po
Normal file
1824
cookbook/locale/zh_CN/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,20 +1,22 @@
|
||||
# Generated by Django 3.0.2 on 2020-01-30 09:59
|
||||
|
||||
from django.db import migrations
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
|
||||
def migrate_ingredient_units(apps, schema_editor):
|
||||
Unit = apps.get_model('cookbook', 'Unit')
|
||||
RecipeIngredients = apps.get_model('cookbook', 'RecipeIngredients')
|
||||
with scopes_disabled():
|
||||
Unit = apps.get_model('cookbook', 'Unit')
|
||||
RecipeIngredients = apps.get_model('cookbook', 'RecipeIngredients')
|
||||
|
||||
for u in RecipeIngredients.objects.values('unit').distinct():
|
||||
unit = Unit()
|
||||
unit.name = u['unit']
|
||||
unit.save()
|
||||
for u in RecipeIngredients.objects.values('unit').distinct():
|
||||
unit = Unit()
|
||||
unit.name = u['unit']
|
||||
unit.save()
|
||||
|
||||
for i in RecipeIngredients.objects.all():
|
||||
i.unit_key = Unit.objects.get(name=i.unit)
|
||||
i.save()
|
||||
for i in RecipeIngredients.objects.all():
|
||||
i.unit_key = Unit.objects.get(name=i.unit)
|
||||
i.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
# Generated by Django 3.0.2 on 2020-02-16 22:09
|
||||
from django.db import migrations
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
|
||||
def migrate_ingredients(apps, schema_editor):
|
||||
Ingredient = apps.get_model('cookbook', 'Ingredient')
|
||||
RecipeIngredient = apps.get_model('cookbook', 'RecipeIngredient')
|
||||
with scopes_disabled():
|
||||
Ingredient = apps.get_model('cookbook', 'Ingredient')
|
||||
RecipeIngredient = apps.get_model('cookbook', 'RecipeIngredient')
|
||||
|
||||
for u in RecipeIngredient.objects.values('name').distinct():
|
||||
ingredient = Ingredient()
|
||||
ingredient.name = u['name']
|
||||
ingredient.save()
|
||||
for u in RecipeIngredient.objects.values('name').distinct():
|
||||
ingredient = Ingredient()
|
||||
ingredient.name = u['name']
|
||||
ingredient.save()
|
||||
|
||||
for i in RecipeIngredient.objects.all():
|
||||
i.ingredient = Ingredient.objects.get(name=i.name)
|
||||
i.save()
|
||||
for i in RecipeIngredient.objects.all():
|
||||
i.ingredient = Ingredient.objects.get(name=i.name)
|
||||
i.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
# Generated by Django 3.0.5 on 2020-04-26 14:14
|
||||
|
||||
from django.db import migrations
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
|
||||
def apply_migration(apps, schema_editor):
|
||||
Group = apps.get_model('auth', 'Group')
|
||||
Group.objects.bulk_create([
|
||||
Group(name=u'guest'),
|
||||
Group(name=u'user'),
|
||||
Group(name=u'admin'),
|
||||
])
|
||||
with scopes_disabled():
|
||||
Group = apps.get_model('auth', 'Group')
|
||||
Group.objects.bulk_create([
|
||||
Group(name=u'guest'),
|
||||
Group(name=u'user'),
|
||||
Group(name=u'admin'),
|
||||
])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
# Generated by Django 3.0.5 on 2020-04-27 16:00
|
||||
|
||||
from django.db import migrations
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
|
||||
def apply_migration(apps, schema_editor):
|
||||
Group = apps.get_model('auth', 'Group')
|
||||
User = apps.get_model('auth', 'User')
|
||||
for u in User.objects.all():
|
||||
if u.groups.count() < 1:
|
||||
u.groups.add(Group.objects.get(name='admin'))
|
||||
u.save()
|
||||
with scopes_disabled():
|
||||
Group = apps.get_model('auth', 'Group')
|
||||
User = apps.get_model('auth', 'User')
|
||||
for u in User.objects.all():
|
||||
if u.groups.count() < 1:
|
||||
u.groups.add(Group.objects.get(name='admin'))
|
||||
u.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@@ -2,43 +2,45 @@
|
||||
|
||||
from django.db import migrations
|
||||
from django.utils.translation import gettext as _
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
|
||||
def migrate_meal_types(apps, schema_editor):
|
||||
MealPlan = apps.get_model('cookbook', 'MealPlan')
|
||||
MealType = apps.get_model('cookbook', 'MealType')
|
||||
with scopes_disabled():
|
||||
MealPlan = apps.get_model('cookbook', 'MealPlan')
|
||||
MealType = apps.get_model('cookbook', 'MealType')
|
||||
|
||||
breakfast = MealType.objects.create(
|
||||
name=_('Breakfast'),
|
||||
order=0,
|
||||
)
|
||||
breakfast = MealType.objects.create(
|
||||
name=_('Breakfast'),
|
||||
order=0,
|
||||
)
|
||||
|
||||
lunch = MealType.objects.create(
|
||||
name=_('Lunch'),
|
||||
order=0,
|
||||
)
|
||||
lunch = MealType.objects.create(
|
||||
name=_('Lunch'),
|
||||
order=0,
|
||||
)
|
||||
|
||||
dinner = MealType.objects.create(
|
||||
name=_('Dinner'),
|
||||
order=0,
|
||||
)
|
||||
dinner = MealType.objects.create(
|
||||
name=_('Dinner'),
|
||||
order=0,
|
||||
)
|
||||
|
||||
other = MealType.objects.create(
|
||||
name=_('Other'),
|
||||
order=0,
|
||||
)
|
||||
other = MealType.objects.create(
|
||||
name=_('Other'),
|
||||
order=0,
|
||||
)
|
||||
|
||||
for m in MealPlan.objects.all():
|
||||
if m.meal == 'BREAKFAST':
|
||||
m.meal_type = breakfast
|
||||
if m.meal == 'LUNCH':
|
||||
m.meal_type = lunch
|
||||
if m.meal == 'DINNER':
|
||||
m.meal_type = dinner
|
||||
if m.meal == 'OTHER':
|
||||
m.meal_type = other
|
||||
for m in MealPlan.objects.all():
|
||||
if m.meal == 'BREAKFAST':
|
||||
m.meal_type = breakfast
|
||||
if m.meal == 'LUNCH':
|
||||
m.meal_type = lunch
|
||||
if m.meal == 'DINNER':
|
||||
m.meal_type = dinner
|
||||
if m.meal == 'OTHER':
|
||||
m.meal_type = other
|
||||
|
||||
m.save()
|
||||
m.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@@ -2,22 +2,24 @@
|
||||
|
||||
from django.db import migrations
|
||||
from django.db.models import Q
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
|
||||
def migrate_meal_types(apps, schema_editor):
|
||||
MealPlan = apps.get_model('cookbook', 'MealPlan')
|
||||
MealType = apps.get_model('cookbook', 'MealType')
|
||||
User = apps.get_model('auth', 'User')
|
||||
with scopes_disabled():
|
||||
MealPlan = apps.get_model('cookbook', 'MealPlan')
|
||||
MealType = apps.get_model('cookbook', 'MealType')
|
||||
User = apps.get_model('auth', 'User')
|
||||
|
||||
for u in User.objects.all():
|
||||
for t in MealType.objects.filter(created_by=None).all():
|
||||
user_type = MealType.objects.create(
|
||||
name=t.name,
|
||||
created_by=u,
|
||||
)
|
||||
MealPlan.objects.filter(Q(created_by=u) and Q(meal_type=t)).update(meal_type=user_type)
|
||||
for u in User.objects.all():
|
||||
for t in MealType.objects.filter(created_by=None).all():
|
||||
user_type = MealType.objects.create(
|
||||
name=t.name,
|
||||
created_by=u,
|
||||
)
|
||||
MealPlan.objects.filter(Q(created_by=u) and Q(meal_type=t)).update(meal_type=user_type)
|
||||
|
||||
MealType.objects.filter(created_by=None).delete()
|
||||
MealType.objects.filter(created_by=None).delete()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@@ -3,11 +3,14 @@
|
||||
from django.db import migrations, models
|
||||
import uuid
|
||||
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
|
||||
def invalidate_shares(apps, schema_editor):
|
||||
ShareLink = apps.get_model('cookbook', 'ShareLink')
|
||||
with scopes_disabled():
|
||||
ShareLink = apps.get_model('cookbook', 'ShareLink')
|
||||
|
||||
ShareLink.objects.all().delete()
|
||||
ShareLink.objects.all().delete()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-25 19:37
|
||||
|
||||
from django.db import migrations
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
|
||||
def migrate_ingredients(apps, schema_editor):
|
||||
Recipe = apps.get_model('cookbook', 'Recipe')
|
||||
Ingredient = apps.get_model('cookbook', 'Ingredient')
|
||||
with scopes_disabled():
|
||||
Recipe = apps.get_model('cookbook', 'Recipe')
|
||||
Ingredient = apps.get_model('cookbook', 'Ingredient')
|
||||
|
||||
for r in Recipe.objects.all():
|
||||
for i in Ingredient.objects.filter(recipe=r).all():
|
||||
r.ingredients.add(i)
|
||||
r.save()
|
||||
for r in Recipe.objects.all():
|
||||
for i in Ingredient.objects.filter(recipe=r).all():
|
||||
r.ingredients.add(i)
|
||||
r.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-25 20:19
|
||||
|
||||
from django.db import migrations, models
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
|
||||
def create_default_step(apps, schema_editor):
|
||||
Recipe = apps.get_model('cookbook', 'Recipe')
|
||||
Step = apps.get_model('cookbook', 'Step')
|
||||
with scopes_disabled():
|
||||
Recipe = apps.get_model('cookbook', 'Recipe')
|
||||
Step = apps.get_model('cookbook', 'Step')
|
||||
|
||||
for r in Recipe.objects.filter(internal=True).all():
|
||||
s = Step.objects.create(
|
||||
instruction=r.instructions
|
||||
)
|
||||
for i in r.ingredients.all():
|
||||
s.ingredients.add(i)
|
||||
s.save()
|
||||
r.steps.add(s)
|
||||
r.save()
|
||||
for r in Recipe.objects.filter(internal=True).all():
|
||||
s = Step.objects.create(
|
||||
instruction=r.instructions
|
||||
)
|
||||
for i in r.ingredients.all():
|
||||
s.ingredients.add(i)
|
||||
s.save()
|
||||
r.steps.add(s)
|
||||
r.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@@ -2,27 +2,29 @@
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
|
||||
def convert_old_specials(apps, schema_editor):
|
||||
Ingredient = apps.get_model('cookbook', 'Ingredient')
|
||||
Food = apps.get_model('cookbook', 'Food')
|
||||
Unit = apps.get_model('cookbook', 'Unit')
|
||||
with scopes_disabled():
|
||||
Ingredient = apps.get_model('cookbook', 'Ingredient')
|
||||
Food = apps.get_model('cookbook', 'Food')
|
||||
Unit = apps.get_model('cookbook', 'Unit')
|
||||
|
||||
for i in Ingredient.objects.all():
|
||||
if i.amount == 0:
|
||||
i.no_amount = True
|
||||
if i.unit.name == 'Special:Header':
|
||||
i.header = True
|
||||
i.unit = None
|
||||
i.food = None
|
||||
i.save()
|
||||
for i in Ingredient.objects.all():
|
||||
if i.amount == 0:
|
||||
i.no_amount = True
|
||||
if i.unit.name == 'Special:Header':
|
||||
i.header = True
|
||||
i.unit = None
|
||||
i.food = None
|
||||
i.save()
|
||||
|
||||
try:
|
||||
Unit.objects.filter(name='Special:Header').delete()
|
||||
Food.objects.filter(name='Header').delete()
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
Unit.objects.filter(name='Special:Header').delete()
|
||||
Food.objects.filter(name='Header').delete()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
26
cookbook/migrations/0091_auto_20201226_1551.py
Normal file
26
cookbook/migrations/0091_auto_20201226_1551.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# Generated by Django 3.1.4 on 2020-12-26 14:51
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def migrate_empty_units(apps, schema_editor):
|
||||
Unit = apps.get_model('cookbook', 'Unit')
|
||||
Ingredient = apps.get_model('cookbook', 'Ingredient')
|
||||
|
||||
empty_units = Unit.objects.filter(name='').all()
|
||||
for x in empty_units:
|
||||
for i in Ingredient.objects.all():
|
||||
if i.unit == x:
|
||||
i.unit = None
|
||||
i.save()
|
||||
x.delete()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('cookbook', '0090_auto_20201214_1359'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(migrate_empty_units),
|
||||
]
|
||||
18
cookbook/migrations/0092_recipe_servings.py
Normal file
18
cookbook/migrations/0092_recipe_servings.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.0.7 on 2020-08-30 13:32
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0091_auto_20201226_1551'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='recipe',
|
||||
name='servings',
|
||||
field=models.IntegerField(default=1),
|
||||
),
|
||||
]
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user