From 0d9be8a72af9c57ad03dc018a1559d063bb24fbd Mon Sep 17 00:00:00 2001 From: yukitya-1811 Date: Sat, 22 Jun 2024 16:00:55 +0530 Subject: [PATCH 1/3] Link gallery images with recipes for easy access --- recipify/recipify/templates/gallery.html | 2 + recipify/recipify/templates/pick.html | 117 +++++++++++++++++++++++ recipify/recipify/templates/upload.html | 12 --- recipify/recipify/urls.py | 1 + recipify/recipify/views.py | 44 ++------- recipify/static/css/pick.css | 36 +++++++ 6 files changed, 166 insertions(+), 46 deletions(-) create mode 100644 recipify/recipify/templates/pick.html create mode 100644 recipify/static/css/pick.css diff --git a/recipify/recipify/templates/gallery.html b/recipify/recipify/templates/gallery.html index 6caf6b5..80ced54 100644 --- a/recipify/recipify/templates/gallery.html +++ b/recipify/recipify/templates/gallery.html @@ -98,7 +98,9 @@

{% for image in images %}
+ Gallery image +
{% endfor %} diff --git a/recipify/recipify/templates/pick.html b/recipify/recipify/templates/pick.html new file mode 100644 index 0000000..2757991 --- /dev/null +++ b/recipify/recipify/templates/pick.html @@ -0,0 +1,117 @@ +{% load static %} + + + + + + + RecipifyAI + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/recipify/recipify/templates/upload.html b/recipify/recipify/templates/upload.html index a56a419..4c7fb5b 100644 --- a/recipify/recipify/templates/upload.html +++ b/recipify/recipify/templates/upload.html @@ -159,18 +159,6 @@

Show Recipe - {% comment %}
Nutrients Present
- -
Nutrients Absent
- {% endcomment %} {% endfor %} diff --git a/recipify/recipify/urls.py b/recipify/recipify/urls.py index 1179218..936696f 100644 --- a/recipify/recipify/urls.py +++ b/recipify/recipify/urls.py @@ -32,6 +32,7 @@ path("gallery/", views.gallery, name="gallery"), path("contact/",views.contact,name="contact"), path("show_recipe/", views.show_recipe, name="show_recipe"), + path("pick_recipe/", views.pick_recipe, name="pick_recipe") ] if settings.DEBUG: diff --git a/recipify/recipify/views.py b/recipify/recipify/views.py index 2298700..d40ca8a 100644 --- a/recipify/recipify/views.py +++ b/recipify/recipify/views.py @@ -79,40 +79,6 @@ def logoutPage(request): logout(request) return redirect('login') -# def image_upload_view(request): -# recipe_text = None # Initialize recipe_text to avoid UnboundLocalError -# if request.method == 'POST': -# form = UploadFileForm(request.POST, request.FILES) -# if form.is_valid(): -# img_instance = form.save() -# # Open the image using PIL -# try: -# img = Image.open(img_instance.image.path) -# except IOError: -# return HttpResponse("Image not found or cannot be opened.", status=404) - -# # Process the image with CLIENT.infer -# try: -# result = CLIENT.infer(img, model_id="fridge-object/3") -# logger.debug("Infer result: %s", result) -# ingredients = [prediction['class'] for prediction in result['predictions']] - -# # Get recipes using the detected ingredients -# recipe_text = getRecipes(ingredients) -# if not recipe_text: -# messages.error(request, "Failed to retrieve recipes.") - -# # Optionally, you can process the image -# processed_image = image_formatter(img) -# print(processed_image) -# except json.JSONDecodeError as e: -# logger.error("JSON decode error: %s", e) -# return HttpResponse(f"Error processing image: {e}", status=500) -# else: -# form = UploadFileForm() - -# return render(request, 'upload.html', {'form': form, 'recipe': recipe_text}) - @login_required def image_upload_view(request): if request.method == 'POST' and 'image-input' in request.FILES: @@ -186,3 +152,13 @@ def clean(item): return item.capitalize() + +def pick_recipe(request, img_id): + image = get_object_or_404(FoodImage, id=img_id) + recipes = Recipe.objects.filter(image=image) + context = { + "recipes": recipes + } + + return render(request, 'pick.html', context) + diff --git a/recipify/static/css/pick.css b/recipify/static/css/pick.css new file mode 100644 index 0000000..9cbce94 --- /dev/null +++ b/recipify/static/css/pick.css @@ -0,0 +1,36 @@ +body { + padding-top: 65px; /* Adjust based on the height of the nav bar */ +} + +.recipe-display { + display: flex; + gap: 100px; + align-items: flex-start; + justify-content: center; +} + +.recipe-title { + font-weight: 900; + font-size: 20px; + white-space: nowrap; + overflow: break-word; + text-overflow: ellipsis; + min-width: 300px; + max-width: 100%; + overflow: auto; + box-sizing: border-box; +} + +.recipe-section { + margin-top: 100px; + display: flex; + gap: 60px; + justify-content: center; + align-items: flex-start; +} + + +.ingredients-title { + font-weight: 700; + font-size: 15px; +} From b635bd90ff073d10f2adafb289157b5a7d6566bc Mon Sep 17 00:00:00 2001 From: yukitya-1811 Date: Sat, 22 Jun 2024 16:18:22 +0530 Subject: [PATCH 2/3] Add margins --- recipify/recipify/templates/pick.html | 2 +- recipify/static/css/pick.css | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/recipify/recipify/templates/pick.html b/recipify/recipify/templates/pick.html index 2757991..121739f 100644 --- a/recipify/recipify/templates/pick.html +++ b/recipify/recipify/templates/pick.html @@ -102,7 +102,7 @@
{{ recipe.name }}
Ingredients Required
-
    +
      {{recipe.ingredients}}
+ class="text-white bg-gradient-to-r from-purple-500 via-purple-600 to-purple-700 hover:bg-gradient-to-br focus:ring-4 focus:outline-none focus:ring-purple-300 dark:focus:ring-purple-800 font-medium rounded-lg text-sm px-5 py-2.5 text-center me-2 mb-2">Show Recipe + +
{% endfor %} diff --git a/recipify/recipify/urls.py b/recipify/recipify/urls.py index 936696f..4b9622f 100644 --- a/recipify/recipify/urls.py +++ b/recipify/recipify/urls.py @@ -32,7 +32,8 @@ path("gallery/", views.gallery, name="gallery"), path("contact/",views.contact,name="contact"), path("show_recipe/", views.show_recipe, name="show_recipe"), - path("pick_recipe/", views.pick_recipe, name="pick_recipe") + path("pick_recipe/", views.pick_recipe, name="pick_recipe"), + path("delete_recipe/", views.delete_recipe, name="delete_recipe") ] if settings.DEBUG: diff --git a/recipify/recipify/views.py b/recipify/recipify/views.py index d40ca8a..f0d022e 100644 --- a/recipify/recipify/views.py +++ b/recipify/recipify/views.py @@ -1,6 +1,7 @@ from django.shortcuts import render, get_object_or_404 from django.contrib import messages from django.shortcuts import redirect +from django.urls import reverse from .forms import SignupForm, LoginForm from .models import FoodImage from .models import Recipe @@ -162,3 +163,15 @@ def pick_recipe(request, img_id): return render(request, 'pick.html', context) +def delete_recipe(request, id): + recipe = get_object_or_404(Recipe, id=id) + img = recipe.image + recipe.delete() + + associated_recipes = img.recipe_set.all() + if not associated_recipes: + img.delete() + return redirect(reverse('gallery')) + + return redirect(reverse('pick_recipe', args=[img.id])) +