Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/filepreviews/wagtail-filepreviews
Extend Wagtail's Documents with image previews and metadata from FilePreviews
https://github.com/filepreviews/wagtail-filepreviews
django filepreviews python wagtail
Last synced: 7 days ago
JSON representation
Extend Wagtail's Documents with image previews and metadata from FilePreviews
- Host: GitHub
- URL: https://github.com/filepreviews/wagtail-filepreviews
- Owner: filepreviews
- License: mit
- Created: 2017-04-16T13:08:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-06-17T20:15:13.000Z (over 3 years ago)
- Last Synced: 2024-04-25T06:22:20.621Z (7 months ago)
- Topics: django, filepreviews, python, wagtail
- Language: Python
- Homepage: http://filepreviews.io/blog/2017/04/20/adding-document-previews-to-wagtail/
- Size: 27.3 KB
- Stars: 21
- Watchers: 2
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
- awesome-wagtail - Wagtail FilePreviews - Extend Wagtail's Documents with image previews and metadata from FilePreviews.io. (Apps / Media)
README
wagtail-filepreviews
====================.. image:: https://travis-ci.org/filepreviews/wagtail-filepreviews.svg?branch=master
:target: https://travis-ci.org/filepreviews/wagtail-filepreviews.. image:: https://img.shields.io/pypi/v/wagtaildocs_previews.svg
:target: https://pypi.python.org/pypi/wagtaildocs_previewsExtend Wagtail's Documents with image previews and metadata from `FilePreviews.io`_
Installing
----------Install with **pip**:
.. code-block:: sh
$ pip install wagtaildocs_previews
Settings
~~~~~~~~In your settings file, add ``wagtaildocs_previews`` to ``INSTALLED_APPS``:
.. code:: python
INSTALLED_APPS = [
# ...
'wagtaildocs_previews',
# ...
]You'll also need to set ``WAGTAILDOCS_DOCUMENT_MODEL``.
.. code:: python
WAGTAILDOCS_DOCUMENT_MODEL = 'wagtaildocs_previews.PreviewableDocument'
URL configuration
~~~~~~~~~~~~~~~~~.. code:: python
from wagtaildocs_previews import urls as wagtaildocs_urls
urlpatterns = [
# ...
url(r'^documents/', include(wagtaildocs_urls)),
# ...
]FilePreviews.io API Keys
~~~~~~~~~~~~~~~~~~~~~~~~For previews to be generated for your documents, you'll need to have a
`FilePreviews.io`_ account and an application's credentials. Once you have
the credentials, add them under the ``FilePreviews`` settings in your
Wagtail admin.Usage
-----Since we're extending via ``WAGTAILDOCS_DOCUMENT_MODEL`` you should be using
``get_document_model()`` to reference the correct Document model... code:: python
from wagtail.core.models import Page
from wagtail.documents.models import get_document_model
from wagtail.documents.edit_handlers import DocumentChooserPanelclass BookPage(Page):
book_file = models.ForeignKey(
get_document_model(),
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)content_panels = Page.content_panels + [
DocumentChooserPanel('book_file'),
]In your template now you'll be able to access the ``preview_data`` field.
.. code:: html
{% extends "base.html" %}
{% load wagtailcore_tags %}{% block body_class %}resource-page{% endblock %}
{% block content %}
Book
{{ page.book_file.title }}
{% endblock %}Configuring thumbnail sizes and other options
---------------------------------------------By default, image previews and not resized at all. If you want to specify additional `FilePreviews options`_ like thumbnail size or metadata, specify the ``WAGTAILDOCS_PREVIEWS_OPTIONS_CALLBACK`` option in your settings.
.. code:: python
WAGTAILDOCS_PREVIEWS_OPTIONS_CALLBACK='mysite.utils.get_preview_options'
In the ``mysite.utils`` module, create a `get_preview_options` method.
.. code:: python
def get_preview_options(document):
return {
'sizes': [300],
'metadata': ['ocr']
}Bonus: Coding video session
---------------------------Here’s a coding session video building up to the released package.
.. image:: https://cloud.githubusercontent.com/assets/83319/25309749/3bb64e16-27a3-11e7-8057-350a52484a0a.png
:target: https://www.youtube.com/watch?v=p2VY9zX2nNw.. _FilePreviews.io: http://filepreviews.io/
.. _FilePreviews options: http://filepreviews.io/docs/endpoints/