From 16cf81ab4a2a51e2121eaf791a3a10978e6c71b9 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Thu, 14 Nov 2019 08:57:50 +0100 Subject: [PATCH] view local recipes --- cookbook/models.py | 2 +- cookbook/templates/index.html | 1 + cookbook/templates/recipe_view.html | 6 +++++- cookbook/views/api.py | 5 ++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cookbook/models.py b/cookbook/models.py index 44d8d8f83..f5d6c0ac4 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -67,7 +67,7 @@ class Recipe(models.Model): @property def all_tags(self): - return ', '.join([(x.icon + x.name) for x in self.keywords.all()]) + return ' '.join([(x.icon + x.name) for x in self.keywords.all()]) class RecipeIngredients(models.Model): diff --git a/cookbook/templates/index.html b/cookbook/templates/index.html index 2323b72a4..71741487a 100644 --- a/cookbook/templates/index.html +++ b/cookbook/templates/index.html @@ -96,6 +96,7 @@ var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function () { if (this.readyState === 4 && this.status === 200) { + window.open(this.responseText); link.attr("href", this.responseText); link.show(); $('#div_loader').hide(); diff --git a/cookbook/templates/recipe_view.html b/cookbook/templates/recipe_view.html index 302e78fa8..8be5a7a96 100644 --- a/cookbook/templates/recipe_view.html +++ b/cookbook/templates/recipe_view.html @@ -7,7 +7,11 @@ {% block content %} -

{{ recipe.name }}

+

{{ recipe.name }}

+ {% if recipe.all_tags %} + {{ recipe.all_tags }} +
+ {% endif %}
diff --git a/cookbook/views/api.py b/cookbook/views/api.py index f369c8d60..ac57e8c5d 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -1,5 +1,6 @@ from django.contrib import messages -from django.http import HttpResponse +from django.http import HttpResponse, HttpResponseRedirect +from django.urls import reverse_lazy, reverse from django.utils.translation import gettext as _ from django.contrib.auth.decorators import login_required from django.shortcuts import redirect @@ -12,6 +13,8 @@ from cookbook.helper import dropbox def get_file_link(request, recipe_id): recipe = Recipe.objects.get(id=recipe_id) + if recipe.instructions: + return HttpResponse(reverse('view_recipe', args=[recipe_id])) if recipe.storage.method == Storage.DROPBOX: if recipe.link == "": recipe.link = dropbox.get_share_link(recipe) # TODO response validation