fixed external recipe viewer

This commit is contained in:
vabene1111
2025-04-26 18:53:14 +02:00
parent ca28a44743
commit 302528256c
4 changed files with 41 additions and 2 deletions

View File

@@ -0,0 +1,31 @@
{% load static %}
<!DOCTYPE html>
<html lang="en" height="100%">
<head>
<meta charset="UTF-8">
<title>PDF</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>PDF</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
overflow: hidden; /* Prevent scrollbars on the body itself */
}
iframe {
display: block; /* Prevents potential extra space below the iframe */
width: 100%;
height: 100%;
border: none; /* Remove default iframe border */
}
</style>
</head>
<body >
<iframe src="{% static 'pdfjs/web/viewer.html' %}?file={% url 'api_get_recipe_file' recipe_id %}" ></iframe>
</body>
</html>

View File

@@ -100,12 +100,13 @@ urlpatterns = [
path('edit/recipe/convert/<int:pk>/', edit.convert_recipe, name='edit_convert_recipe'),
path('edit/storage/<int:pk>/', edit.edit_storage, name='edit_storage'),
path('delete/recipe-source/<int:pk>/', delete.delete_recipe_source, name='delete_recipe_source'),
path('view-recipe-pdf/<int:pk>/', views.recipe_pdf_viewer, name='view_recipe_pdf'),
# Tandoor v1 redirects
path('view/recipe/<int:pk>', views.redirect_recipe_view, name='redirect_recipe_view'),
path('view/recipe/<int:pk>/<slug:share>', views.redirect_recipe_share_view, name='redirect_recipe_share_view'),
# TODO move to generic "new" view
path('data/sync', data.sync, name='data_sync'),
path('data/batch/edit', data.batch_edit, name='data_batch_edit'),
path('data/batch/import', data.batch_import, name='data_batch_import'),

View File

@@ -32,6 +32,7 @@ from cookbook.models import Comment, CookLog, InviteLink, SearchFields, SearchPr
from cookbook.tables import CookLogTable, ViewLogTable
from cookbook.templatetags.theming_tags import get_theming_values
from cookbook.version_info import VERSION_INFO
from cookbook.views.api import get_recipe_provider
from recipes.settings import PLUGINS
@@ -196,6 +197,12 @@ def meal_plan(request):
return render(request, 'meal_plan.html', {})
@group_required('guest')
def recipe_pdf_viewer(request, pk):
recipe = get_object_or_404(Recipe, pk=pk, space=request.space)
return render(request, 'pdf_viewer.html', {'recipe_id': pk})
@group_required('guest')
def user_settings(request):
if request.space.demo:

View File

@@ -1,6 +1,6 @@
<template>
<v-card class="mt-1 h-100">
<iframe width="100%" height="700px" :src="`${getDjangoUrl('/static/pdfjs/web/viewer.html', false)}?file=${getDjangoUrl('/api/get_recipe_file/')}${props.recipe.id}/`" v-if="isPdf"></iframe>
<iframe width="100%" height="700px" :src="`${getDjangoUrl('/view-recipe-pdf/')}${props.recipe.id}/`" v-if="isPdf"></iframe>
<v-img :src="`${getDjangoUrl('/api/get_recipe_file/')}${props.recipe.id}/`" v-if="isImage"></v-img>
</v-card>