small PDF export tweaks
This commit is contained in:
parent
0a6abf9688
commit
d506952602
@ -145,3 +145,7 @@ REVERSE_PROXY_AUTH=0
|
||||
#AUTH_LDAP_BIND_DN=
|
||||
#AUTH_LDAP_BIND_PASSWORD=
|
||||
#AUTH_LDAP_USER_SEARCH_BASE_DN=
|
||||
|
||||
# Enables exporting PDF (see export docs)
|
||||
# Disabled by default, uncomment to enable
|
||||
# ENABLE_PDF_EXPORT=1
|
@ -19,10 +19,6 @@ class PDFexport(Integration):
|
||||
def get_recipe_from_file(self, file):
|
||||
raise NotImplementedError('Method not implemented in storage integration')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
async def get_files_from_recipes_async(self, recipes, cookie):
|
||||
cmd = runserver.Command()
|
||||
|
||||
@ -33,8 +29,8 @@ class PDFexport(Integration):
|
||||
ignoreHTTPSErrors=True
|
||||
)
|
||||
|
||||
cookies = {'domain': cmd.default_addr, 'name': 'sessionid', 'value': cookie['sessionid'],}
|
||||
options = { 'format': 'letter',
|
||||
cookies = {'domain': cmd.default_addr, 'name': 'sessionid', 'value': cookie['sessionid'], }
|
||||
options = {'format': 'letter',
|
||||
'margin': {
|
||||
'top': '0.75in',
|
||||
'bottom': '0.75in',
|
||||
@ -49,14 +45,11 @@ class PDFexport(Integration):
|
||||
|
||||
files = []
|
||||
for recipe in recipes:
|
||||
await page.goto('http://'+cmd.default_addr+':'+cmd.default_port+'/view/recipe/'+str(recipe.id), {'waitUntil': 'networkidle0',})
|
||||
files.append([ recipe.name+'.pdf', await page.pdf(options) ])
|
||||
|
||||
await page.goto('http://' + cmd.default_addr + ':' + cmd.default_port + '/view/recipe/' + str(recipe.id), {'waitUntil': 'networkidle0', })
|
||||
files.append([recipe.name + '.pdf', await page.pdf(options)])
|
||||
|
||||
await browser.close()
|
||||
return files
|
||||
|
||||
|
||||
|
||||
def get_files_from_recipes(self, recipes, cookie):
|
||||
return asyncio.run(self.get_files_from_recipes_async(recipes, cookie))
|
||||
|
@ -30,6 +30,7 @@ from cookbook.integration.rezkonv import RezKonv
|
||||
from cookbook.integration.saffron import Saffron
|
||||
from cookbook.integration.pdfexport import PDFexport
|
||||
from cookbook.models import Recipe, ImportLog, UserPreference
|
||||
from recipes import settings
|
||||
|
||||
|
||||
def get_integration(request, export_type):
|
||||
@ -121,6 +122,10 @@ def export_recipe(request):
|
||||
recipes = form.cleaned_data['recipes']
|
||||
if form.cleaned_data['all']:
|
||||
recipes = Recipe.objects.filter(space=request.space, internal=True).all()
|
||||
|
||||
if form.cleaned_data['type'] == ImportExportBase.PDF and not settings.ENABLE_PDF_EXPORT:
|
||||
messages.add_message(request, messages.ERROR, _('The PDF Exporter is not enabled on this instance as it is still in an experimental state.'))
|
||||
return render(request, 'export.html', {'form': form})
|
||||
integration = get_integration(request, form.cleaned_data['type'])
|
||||
return integration.do_export(recipes)
|
||||
except NotImplementedError:
|
||||
|
@ -21,12 +21,12 @@ if your favorite one is missing.
|
||||
Overview of the capabilities of the different integrations.
|
||||
|
||||
| Integration | Import | Export | Images |
|
||||
| ----------- | ------ | ------ | ------ |
|
||||
|--------------------| ------ | ------ | ------ |
|
||||
| Default | ✔️ | ✔️ | ✔️ |
|
||||
| Nextcloud | ✔️ | ⌚ | ✔️ |
|
||||
| Mealie | ✔️ | ⌚ | ✔️ |
|
||||
| Chowdown | ✔️ | ⌚ | ✔️ |
|
||||
| Safron | ✔️ | ⌚ | ❌ |
|
||||
| Safron | ✔️ | ✔ | ❌ |
|
||||
| Paprika | ✔️ | ⌚ | ✔️ |
|
||||
| ChefTap | ✔️ | ❌ | ❌ |
|
||||
| Pepperplate | ✔️ | ⌚ | ❌ |
|
||||
@ -38,6 +38,7 @@ Overview of the capabilities of the different integrations.
|
||||
| Plantoeat | ✔️ | ❌ | ✔ |
|
||||
| CookBookApp | ✔️ | ⌚ | ✔️ |
|
||||
| CopyMeThat | ✔️ | ❌ | ✔️ |
|
||||
| PDF (experimental) | ⌚️ | ✔ | ✔️ |
|
||||
|
||||
✔ = implemented, ❌ = not implemented and not possible/planned, ⌚ = not yet implemented
|
||||
|
||||
@ -223,3 +224,13 @@ CookBookApp can export .zip files containing .html files. Upload the entire ZIP
|
||||
## CopyMeThat
|
||||
|
||||
CopyMeThat can export .zip files containing an `.html` file as well as a folder containing all the images. Upload the entire ZIP to Tandoor to import all included recipes.
|
||||
|
||||
## PDF
|
||||
|
||||
The PDF Exporter is an experimental feature that uses the puppeteer browser renderer to render each recipe and export it to PDF.
|
||||
For that to work it downloads a chromium binary of about 140 MB to your server and then renders the PDF files using that.
|
||||
|
||||
Since that is something some server administrators might not want there the PDF exporter is disabled by default and can be enabled with `ENABLE_PDF_EXPORT=1` in `.env`.
|
||||
|
||||
See [this issue](https://github.com/TandoorRecipes/recipes/pull/1211) for more discussion on this and
|
||||
[this issue](https://github.com/TandoorRecipes/recipes/issues/781) for the future plans to support server side rendering.
|
@ -137,6 +137,8 @@ ENABLE_SIGNUP = bool(int(os.getenv('ENABLE_SIGNUP', False)))
|
||||
|
||||
ENABLE_METRICS = bool(int(os.getenv('ENABLE_METRICS', False)))
|
||||
|
||||
ENABLE_PDF_EXPORT = bool(int(os.getenv('ENABLE_PDF_EXPORT', False)))
|
||||
|
||||
MIDDLEWARE = [
|
||||
'corsheaders.middleware.CorsMiddleware',
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
|
Loading…
Reference in New Issue
Block a user