Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
vabene1111 committed Sep 23, 2022
2 parents fd325c1 + 36c30f9 commit 16c0189
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 204 deletions.
2 changes: 1 addition & 1 deletion cookbook/helper/recipe_url_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_from_scraper(scrape, request):
# 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)
recipe_json['name'] = parse_name(scrape.title()[:128] or None)
except Exception:
recipe_json['name'] = None
if not recipe_json['name']:
Expand Down
10 changes: 5 additions & 5 deletions cookbook/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ def update(self, instance, validated_data):
class Meta:
model = Recipe
fields = (
'id', 'name', 'description', 'image', 'keywords', 'working_time',
'id', 'name', 'description', 'image', 'keywords', 'working_time',
'waiting_time', 'created_by', 'created_at', 'updated_at',
'internal', 'servings', 'servings_text', 'rating', 'last_cooked', 'new', 'recent'
)
Expand All @@ -721,8 +721,8 @@ class RecipeSerializer(RecipeBaseSerializer):
steps = StepSerializer(many=True)
keywords = KeywordSerializer(many=True)
shared = UserSerializer(many=True, required=False)
rating = CustomDecimalField(required=False, allow_null=True)
last_cooked = serializers.DateTimeField(required=False, allow_null=True)
rating = CustomDecimalField(required=False, allow_null=True, read_only=True)
last_cooked = serializers.DateTimeField(required=False, allow_null=True, read_only=True)

class Meta:
model = Recipe
Expand Down Expand Up @@ -1124,14 +1124,14 @@ class AccessTokenSerializer(serializers.ModelSerializer):
token = serializers.SerializerMethodField('get_token')

def create(self, validated_data):
validated_data['token'] = f'tda_{str(uuid.uuid4()).replace("-","_")}'
validated_data['token'] = f'tda_{str(uuid.uuid4()).replace("-", "_")}'
validated_data['user'] = self.context['request'].user
return super().create(validated_data)

def get_token(self, obj):
if (timezone.now() - obj.created).seconds < 15:
return obj.token
return f'tda_************_******_***********{obj.token[len(obj.token)-4:]}'
return f'tda_************_******_***********{obj.token[len(obj.token) - 4:]}'

class Meta:
model = AccessToken
Expand Down
1 change: 1 addition & 0 deletions cookbook/templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ <h5 class="card-title">{% trans 'Precise' %}</h5>

function applyPreset(preset) {
$('#id_search-preset').val(preset);
$('#id_search-search').val('plain');
$('#search_form_button').click();
}
</script>
Expand Down
56 changes: 28 additions & 28 deletions cookbook/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ def shopping_settings(request):

if request.method == "POST":
if 'search_form' in request.POST:
active_tab = 'search'
search_form = SearchPreferenceForm(request.POST, prefix='search')
if search_form.is_valid():
if not sp:
Expand All @@ -226,7 +225,28 @@ def shopping_settings(request):
+ len(search_form.cleaned_data['trigram'])
+ len(search_form.cleaned_data['fulltext'])
)
if fields_searched == 0:
if search_form.cleaned_data['preset'] == 'fuzzy':
sp.search = SearchPreference.SIMPLE
sp.lookup = True
sp.unaccent.set([SearchFields.objects.get(name='Name')])
sp.icontains.set([SearchFields.objects.get(name='Name')])
sp.istartswith.clear()
sp.trigram.set([SearchFields.objects.get(name='Name')])
sp.fulltext.clear()
sp.trigram_threshold = 0.2
sp.save()
elif search_form.cleaned_data['preset'] == 'precise':
sp.search = SearchPreference.WEB
sp.lookup = True
sp.unaccent.set(SearchFields.objects.all())
# full text on food is very slow, add search_vector field and index it (including Admin functions and postsave signal to rebuild index)
sp.icontains.set([SearchFields.objects.get(name='Name')])
sp.istartswith.set([SearchFields.objects.get(name='Name')])
sp.trigram.clear()
sp.fulltext.set(SearchFields.objects.filter(name__in=['Ingredients']))
sp.trigram_threshold = 0.2
sp.save()
elif fields_searched == 0:
search_form.add_error(None, _('You must select at least one field to search!'))
search_error = True
elif search_form.cleaned_data['search'] in ['websearch', 'raw'] and len(
Expand All @@ -247,29 +267,9 @@ def shopping_settings(request):
sp.trigram.set(search_form.cleaned_data['trigram'])
sp.fulltext.set(search_form.cleaned_data['fulltext'])
sp.trigram_threshold = search_form.cleaned_data['trigram_threshold']

if search_form.cleaned_data['preset'] == 'fuzzy':
sp.search = SearchPreference.SIMPLE
sp.lookup = True
sp.unaccent.set([SearchFields.objects.get(name='Name')])
sp.icontains.set([SearchFields.objects.get(name='Name')])
sp.istartswith.clear()
sp.trigram.set([SearchFields.objects.get(name='Name')])
sp.fulltext.clear()
sp.trigram_threshold = 0.2

if search_form.cleaned_data['preset'] == 'precise':
sp.search = SearchPreference.WEB
sp.lookup = True
sp.unaccent.set(SearchFields.objects.all())
# full text on food is very slow, add search_vector field and index it (including Admin functions and postsave signal to rebuild index)
sp.icontains.set([SearchFields.objects.get(name='Name')])
sp.istartswith.set([SearchFields.objects.get(name='Name')])
sp.trigram.clear()
sp.fulltext.set(SearchFields.objects.filter(name__in=['Ingredients']))
sp.trigram_threshold = 0.2

sp.save()
else:
search_error = True

fields_searched = len(sp.icontains.all()) + len(sp.istartswith.all()) + len(sp.trigram.all()) + len(
sp.fulltext.all())
Expand All @@ -281,10 +281,10 @@ def shopping_settings(request):
# these fields require postgresql - just disable them if postgresql isn't available
if not settings.DATABASES['default']['ENGINE'] in ['django.db.backends.postgresql_psycopg2',
'django.db.backends.postgresql']:
search_form.fields['search'].disabled = True
search_form.fields['lookup'].disabled = True
search_form.fields['trigram'].disabled = True
search_form.fields['fulltext'].disabled = True
sp.search = SearchPreference.SIMPLE
sp.trigram.clear()
sp.fulltext.clear()
sp.save()

return render(request, 'settings.html', {
'search_form': search_form,
Expand Down
2 changes: 1 addition & 1 deletion vue/src/apps/RecipeView/RecipeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
</div>

<div class="col col-md-2 col-2 mt-2 mt-md-0 text-right">
<recipe-context-menu v-bind:recipe="recipe" :servings="servings"></recipe-context-menu>
<recipe-context-menu v-bind:recipe="recipe" :servings="servings" :disabled_options="{print:false}"></recipe-context-menu>
</div>
</div>
<hr/>
Expand Down
11 changes: 6 additions & 5 deletions vue/src/components/RecipeCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<template v-if="recipe && recipe.loading">
<b-card no-body v-hover>
<b-card-img-lazy style="height: 15vh; object-fit: cover" class="" :src="placeholder_image"
v-bind:alt="$t('Recipe_Image')" top></b-card-img-lazy>
v-bind:alt="$t('Recipe_Image')" top></b-card-img-lazy>

<b-card-body class="p-4">
<b-card-body class="p-4">
<h6>
<b-skeleton width="95%"></b-skeleton>
</h6>

<b-card-text>
<b-skeleton height="12px" :width="(45 + Math.random() * 45).toString() + '%'"></b-skeleton>
<b-skeleton height="12px" :width="(45 + Math.random() * 45).toString() + '%'"></b-skeleton>
<b-skeleton height="12px" :width="(20 + Math.random() * 25).toString() + '%'"></b-skeleton>
<b-skeleton height="12px" :width="(30 + Math.random() * 35).toString() + '%'"></b-skeleton>
</b-card-text>
Expand All @@ -28,7 +28,7 @@
class="card-img-overlay h-100 d-flex flex-column justify-content-right float-right text-right pt-2 pr-1"
v-if="show_context_menu">
<a>
<recipe-context-menu :recipe="recipe" class="float-right"
<recipe-context-menu :recipe="recipe" class="float-right" :disabled_options="context_disabled_options"
v-if="recipe !== null"></recipe-context-menu>
</a>
</div>
Expand Down Expand Up @@ -124,7 +124,8 @@ export default {
footer_text: String,
footer_icon: String,
detailed: {type: Boolean, default: true},
show_context_menu: {type: Boolean, default: true}
show_context_menu: {type: Boolean, default: true},
context_disabled_options: Object,
},
data() {
return {
Expand Down
26 changes: 15 additions & 11 deletions vue/src/components/RecipeContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,54 @@
</a>

<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
<a class="dropdown-item" :href="resolveDjangoUrl('edit_recipe', recipe.id)"><i
<a class="dropdown-item" :href="resolveDjangoUrl('edit_recipe', recipe.id)" v-if="!disabled_options.edit"><i
class="fas fa-pencil-alt fa-fw"></i> {{ $t("Edit") }}</a>

<a class="dropdown-item" :href="resolveDjangoUrl('edit_convert_recipe', recipe.id)"
v-if="!recipe.internal"><i class="fas fa-exchange-alt fa-fw"></i> {{ $t("convert_internal") }}</a>
v-if="!recipe.internal && !disabled_options.convert"><i class="fas fa-exchange-alt fa-fw"></i> {{ $t("convert_internal") }}</a>

<a href="javascript:void(0);">
<button class="dropdown-item" @click="$bvModal.show(`id_modal_add_book_${modal_id}`)"><i
<button class="dropdown-item" @click="$bvModal.show(`id_modal_add_book_${modal_id}`)" v-if="!disabled_options.books"><i
class="fas fa-bookmark fa-fw"></i> {{ $t("Manage_Books") }}
</button>
</a>

<a class="dropdown-item" v-if="recipe.internal" @click="addToShopping" href="#"> <i
<a class="dropdown-item" v-if="recipe.internal && !disabled_options.shopping" @click="addToShopping" href="#" > <i
class="fas fa-shopping-cart fa-fw"></i> {{ $t("Add_to_Shopping") }} </a>

<a class="dropdown-item" @click="createMealPlan" href="javascript:void(0);"><i
<a class="dropdown-item" @click="createMealPlan" href="javascript:void(0);" v-if="!disabled_options.plan"><i
class="fas fa-calendar fa-fw"></i> {{ $t("Add_to_Plan") }} </a>

<a href="javascript:void(0);">
<button class="dropdown-item" @click="$bvModal.show(`id_modal_cook_log_${modal_id}`)"><i
<button class="dropdown-item" @click="$bvModal.show(`id_modal_cook_log_${modal_id}`)" v-if="!disabled_options.log"><i
class="fas fa-clipboard-list fa-fw"></i> {{ $t("Log_Cooking") }}
</button>
</a>

<a href="javascript:void(0);">
<button class="dropdown-item" onclick="window.print()">
<button class="dropdown-item" onclick="window.print()" v-if="!disabled_options.print">
<i class="fas fa-print fa-fw"></i>
{{ $t("Print") }}
</button>
</a>
<a href="javascript:void(0);">
<button class="dropdown-item" @click="copyToNew"><i class="fas fa-copy fa-fw"></i>
<button class="dropdown-item" @click="copyToNew" v-if="!disabled_options.copy"><i class="fas fa-copy fa-fw"></i>
{{ $t("copy_to_new") }}
</button>
</a>

<a class="dropdown-item" :href="resolveDjangoUrl('view_export') + '?r=' + recipe.id" target="_blank"
rel="noopener noreferrer"><i class="fas fa-file-export fa-fw"></i> {{ $t("Export") }}</a>
rel="noopener noreferrer" v-if="!disabled_options.export"><i class="fas fa-file-export fa-fw"></i> {{ $t("Export") }}</a>

<a href="javascript:void(0);">
<button class="dropdown-item" @click="pinRecipe()">
<button class="dropdown-item" @click="pinRecipe()" v-if="!disabled_options.pin">
<i class="fas fa-thumbtack fa-fw"></i>
{{ $t("Pin") }}
</button>
</a>

<a href="javascript:void(0);">
<button class="dropdown-item" @click="createShareLink()" v-if="recipe.internal"><i
<button class="dropdown-item" @click="createShareLink()" v-if="recipe.internal && !disabled_options.share" ><i
class="fas fa-share-alt fa-fw"></i> {{ $t("Share") }}
</button>
</a>
Expand Down Expand Up @@ -147,6 +147,10 @@ export default {
type: Number,
default: -1,
},
disabled_options: {
type: Object,
default: () => ({print:true}),
},
},
mounted() {
this.servings_value = this.servings === -1 ? this.recipe.servings : this.servings
Expand Down
11 changes: 5 additions & 6 deletions vue/src/components/ShoppingLineItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,23 @@
</b-col>
<b-col cols="8">
<b-row class="d-flex h-100">
<b-col cols="6" md="3" class="d-flex align-items-center"
<b-col cols="6" md="3" class="d-flex align-items-center" v-touch:start="startHandler" v-touch:moving="moveHandler" v-touch:end="endHandler"
v-if="Object.entries(formatAmount).length == 1">
<strong class="mr-1">{{ Object.entries(formatAmount)[0][1] }}</strong>
{{ Object.entries(formatAmount)[0][0] }}
</b-col>
<b-col cols="6" md="3" class="d-flex flex-column"
<b-col cols="6" md="3" class="d-flex flex-column" v-touch:start="startHandler" v-touch:moving="moveHandler" v-touch:end="endHandler"
v-if="Object.entries(formatAmount).length != 1">
<div class="small" v-for="(x, i) in Object.entries(formatAmount)" :key="i">
{{ x[1] }} &ensp;
{{ x[0] }}
</div>
</b-col>

<b-col cols="6" md="6" class="align-items-center d-flex pl-0 pr-0 pl-md-2 pr-md-2"
v-touch:start="startHandler" v-touch:moving="moveHandler" v-touch:end="endHandler">
<b-col cols="6" md="6" class="align-items-center d-flex pl-0 pr-0 pl-md-2 pr-md-2">
{{ formatFood }}
</b-col>
<b-col cols="3" data-html2canvas-ignore="true"
<b-col cols="3" data-html2canvas-ignore="true" v-touch:start="startHandler" v-touch:moving="moveHandler" v-touch:end="endHandler"
class="align-items-center d-none d-md-flex justify-content-end">
<b-button size="sm" @click="showDetails = !showDetails"
class="p-0 mr-0 mr-md-2 p-md-2 text-decoration-none" variant="link">
Expand All @@ -62,7 +61,7 @@
</b-col>
</b-row>
</b-col>
<b-col cols="2" class="justify-content-start align-items-center d-flex d-md-none pl-0 pr-0"
<b-col cols="2" class="justify-content-start align-items-center d-flex d-md-none pl-0 pr-0" v-touch:start="startHandler" v-touch:moving="moveHandler" v-touch:end="endHandler"
v-if="!settings.left_handed">
<b-button size="sm" @click="showDetails = !showDetails" class="d-inline-block d-md-none p-0"
variant="link">
Expand Down
34 changes: 19 additions & 15 deletions vue/src/locales/pt.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"warning_feature_beta": "",
"err_fetching_resource": "",
"err_creating_resource": "",
"err_updating_resource": "",
"err_deleting_resource": "",
"err_moving_resource": "",
"err_merging_resource": "",
"success_fetching_resource": "",
"success_creating_resource": "",
"success_updating_resource": "",
"success_deleting_resource": "",
"success_moving_resource": "",
"success_merging_resource": "",
"file_upload_disabled": "",
"warning_feature_beta": "Este recurso está atualmente em BETA (sendo testado). Tenha em mente que podem existir bugs atualmente e haja mudanças drásticas no futuro (que podem causar perda de dados) quando utilizar este recurso.",
"err_fetching_resource": "Ocorreu um erro buscando um recurso!",
"err_creating_resource": "Ocorreu um erro criando um recurso!",
"err_updating_resource": "Ocorreu um erro atualizando um recurso!",
"err_deleting_resource": "Ocorreu um erro deletando um recurso!",
"err_moving_resource": "Ocorreu um erro movendo o recurso!",
"err_merging_resource": "Ocorreu um erro mesclando os recursos!",
"success_fetching_resource": "Recurso carregado com sucesso!",
"success_creating_resource": "Recurso criado com sucesso!",
"success_updating_resource": "Recurso atualizado com sucesso!",
"success_deleting_resource": "Recurso deletado com sucesso!",
"success_moving_resource": "Recurso movido com sucesso!",
"success_merging_resource": "Recurso mesclado com sucesso!",
"file_upload_disabled": "Upload de arquivos não está habilitado para seu espaço.",
"step_time_minutes": "",
"confirm_delete": "",
"import_running": "",
Expand Down Expand Up @@ -378,5 +378,9 @@
"Page": "Página",
"Reset": "Reiniciar",
"Create Food": "Criar Comida",
"create_food_desc": "Criar a comida e ligar a esta receita."
"create_food_desc": "Criar a comida e ligar a esta receita.",
"err_deleting_protected_resource": "O objeto que você está tentando deletar ainda está sendo utilizado, portanto não pode ser deletado.",
"food_inherit_info": "Campos no alimento que devem ser herdados por padrão.",
"warning_space_delete": "Você pode deletar seu espaço, inclusive todas as receitas, listas de mercado, planos de comida e tudo mais que você criou. Esta ação não poderá ser desfeita! Você tem certeza que quer fazer isto?",
"facet_count_info": "Mostrar quantidade de receitas nos filtros de busca."
}
Loading

0 comments on commit 16c0189

Please sign in to comment.