ingredient linking fixed + tests fixed

This commit is contained in:
vabene1111 2021-01-19 21:26:20 +01:00
parent 523a2b41d1
commit b563447674
5 changed files with 36 additions and 29 deletions

View File

@ -139,7 +139,7 @@ def find_recipe_json(ld_json, url):
if k := Keyword.objects.filter(name=kw).first(): if k := Keyword.objects.filter(name=kw).first():
keywords.append({'id': str(k.id), 'text': str(k).strip()}) keywords.append({'id': str(k.id), 'text': str(k).strip()})
else: else:
keywords.append({'id': random.randrange(0, 9999999, 1), 'text': kw.strip()}) keywords.append({'id': random.randrange(1111111, 9999999, 1), 'text': kw.strip()})
ld_json['keywords'] = keywords ld_json['keywords'] = keywords
else: else:

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -10,14 +10,14 @@ class TestEditsRecipe(TestBase):
# flake8: noqa # flake8: noqa
def test_ld_json(self): def test_ld_json(self):
test_list = [ test_list = [
{'file': 'cookbook/tests/resources/websites/ld_json_1.html', 'result_length': 3218}, {'file': 'cookbook/tests/resources/websites/ld_json_1.html', 'result_length': 3222},
{'file': 'cookbook/tests/resources/websites/ld_json_2.html', 'result_length': 1510}, {'file': 'cookbook/tests/resources/websites/ld_json_2.html', 'result_length': 1510},
{'file': 'cookbook/tests/resources/websites/ld_json_3.html', 'result_length': 1629}, {'file': 'cookbook/tests/resources/websites/ld_json_3.html', 'result_length': 1629},
{'file': 'cookbook/tests/resources/websites/ld_json_4.html', 'result_length': 1729}, {'file': 'cookbook/tests/resources/websites/ld_json_4.html', 'result_length': 1729},
{'file': 'cookbook/tests/resources/websites/ld_json_itemList.html', 'result_length': 3200}, {'file': 'cookbook/tests/resources/websites/ld_json_itemList.html', 'result_length': 3206},
{'file': 'cookbook/tests/resources/websites/ld_json_multiple.html', 'result_length': 1606}, {'file': 'cookbook/tests/resources/websites/ld_json_multiple.html', 'result_length': 1606},
{'file': 'cookbook/tests/resources/websites/micro_data_1.html', 'result_length': 1079}, {'file': 'cookbook/tests/resources/websites/micro_data_1.html', 'result_length': 1079},
{'file': 'cookbook/tests/resources/websites/micro_data_2.html', 'result_length': 1429}, {'file': 'cookbook/tests/resources/websites/micro_data_2.html', 'result_length': 1438},
{'file': 'cookbook/tests/resources/websites/micro_data_3.html', 'result_length': 1148}, {'file': 'cookbook/tests/resources/websites/micro_data_3.html', 'result_length': 1148},
{'file': 'cookbook/tests/resources/websites/micro_data_4.html', 'result_length': 4396}, {'file': 'cookbook/tests/resources/websites/micro_data_4.html', 'result_length': 4396},
] ]

View File

@ -1,35 +1,39 @@
<template> <template>
<tr @click="$emit('checked-state-changed', ingredient)"> <tr @click="$emit('checked-state-changed', ingredient)">
<td> <td>
<i class="far fa-check-circle text-success" v-if="ingredient.checked"></i> <i class="far fa-check-circle text-success" v-if="ingredient.checked"></i>
<i class="far fa-check-circle text-primary" v-if="!ingredient.checked"></i> <i class="far fa-check-circle text-primary" v-if="!ingredient.checked"></i>
</td> </td>
<td> <td>
<span v-if="ingredient.amount !== 0">{{ calculateAmount(ingredient.amount) }}</span> <span v-if="ingredient.amount !== 0">{{ calculateAmount(ingredient.amount) }}</span>
</td> </td>
<td> <td>
<span v-if="ingredient.unit !== null">{{ ingredient.unit.name }}</span> <span v-if="ingredient.unit !== null">{{ ingredient.unit.name }}</span>
</td> </td>
<td> <td>
<span v-if="ingredient.food !== null">{{ ingredient.food.name }}</span> <template v-if="ingredient.food !== null">
</td> <a :href="resolveDjangoUrl('view_recipe', ingredient.food.recipe)" v-if="ingredient.food.recipe !== null"
<td> target="_blank" rel="noopener noreferrer">{{ ingredient.food.name }}</a>
<div v-if="ingredient.note"> <span v-if="ingredient.food.recipe === null">{{ ingredient.food.name }}</span>
</template>
</td>
<td>
<div v-if="ingredient.note">
<span v-b-popover.hover="ingredient.note" <span v-b-popover.hover="ingredient.note"
class="d-print-none"> <i class="far fa-comment"></i> class="d-print-none"> <i class="far fa-comment"></i>
</span> </span>
<div class="d-none d-print-block"> <div class="d-none d-print-block">
<i class="far fa-comment-alt"></i> {{ ingredient.note }} <i class="far fa-comment-alt"></i> {{ ingredient.note }}
</div>
</div> </div>
</td> </div>
</tr> </td>
</tr>
</template> </template>
<script> <script>
import {calculateAmount} from "@/utils/utils"; import {calculateAmount, ResolveUrlMixin} from "@/utils/utils";
export default { export default {
name: 'Ingredient', name: 'Ingredient',
@ -40,6 +44,9 @@ export default {
default: 1, default: 1,
} }
}, },
mixins: [
ResolveUrlMixin
],
data() { data() {
return { return {
checked: false checked: false