2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
2020-05-08 11:06:48 +08:00
<!doctype html>
< html lang = "en" class = "no-js" >
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "width=device-width,initial-scale=1" >
2024-09-30 20:56:16 +08:00
< meta http-equiv = "x-ua-compatible" content = "ie=edge" >
2020-05-08 11:06:48 +08:00
< meta name = "description" content = "Docs for the Pinry project." >
2024-09-30 20:58:34 +08:00
< link rel = "canonical" href = "https://pinry.github.io/pinry/plugin-system/" >
2024-09-30 20:56:16 +08:00
2020-05-08 11:06:48 +08:00
< meta name = "author" content = "Pinry's Contributors" >
2024-09-30 20:56:16 +08:00
< meta name = "lang:clipboard.copy" content = "Copy to clipboard" >
< meta name = "lang:clipboard.copied" content = "Copied to clipboard" >
< meta name = "lang:search.language" content = "en" >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< meta name = "lang:search.pipeline.stopwords" content = "True" >
< meta name = "lang:search.pipeline.trimmer" content = "True" >
< meta name = "lang:search.result.none" content = "No matching documents" >
< meta name = "lang:search.result.one" content = "1 matching document" >
< meta name = "lang:search.result.other" content = "# matching documents" >
< meta name = "lang:search.tokenizer" content = "[\s\-]+" >
< link rel = "shortcut icon" href = "../assets/images/favicon.png" >
< meta name = "generator" content = "mkdocs-1.0.4, mkdocs-material-4.6.0" >
2020-05-08 11:06:48 +08:00
2020-05-08 11:25:54 +08:00
< title > Plugin System - Pinry Docs< / title >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< link rel = "stylesheet" href = "../assets/stylesheets/application.1b62728e.css" >
< link rel = "stylesheet" href = "../assets/stylesheets/application-palette.a8b3c06d.css" >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< meta name = "theme-color" content = "#3f51b5" >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< script src = "../assets/javascripts/modernizr.268332fc.js" > < / script >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< link href = "https://fonts.gstatic.com" rel = "preconnect" crossorigin >
2021-03-06 21:00:26 +08:00
< link rel = "stylesheet" href = "https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700%7CRoboto+Mono&display=fallback" >
2024-09-30 20:56:16 +08:00
< style > body , input { font-family : "Roboto" , "Helvetica Neue" , Helvetica , Arial , sans-serif } code , kbd , pre { font-family : "Roboto Mono" , "Courier New" , Courier , monospace } < / style >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< link rel = "stylesheet" href = "../assets/fonts/material-icons.css" >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< link rel = "manifest" href = "../manifest.webmanifest" >
2020-05-08 11:06:48 +08:00
< / head >
2024-09-30 20:56:16 +08:00
< body dir = "ltr" data-md-color-primary = "indigo" data-md-color-accent = "indigo" >
2021-03-06 21:00:26 +08:00
2024-09-30 20:56:16 +08:00
< svg class = "md-svg" >
< defs >
< svg xmlns = "http://www.w3.org/2000/svg" width = "416" height = "448" viewBox = "0 0 416 448" id = "__github" > < path fill = "currentColor" d = "M160 304q0 10-3.125 20.5t-10.75 19T128 352t-18.125-8.5-10.75-19T96 304t3.125-20.5 10.75-19T128 256t18.125 8.5 10.75 19T160 304zm160 0q0 10-3.125 20.5t-10.75 19T288 352t-18.125-8.5-10.75-19T256 304t3.125-20.5 10.75-19T288 256t18.125 8.5 10.75 19T320 304zm40 0q0-30-17.25-51T296 232q-10.25 0-48.75 5.25Q229.5 240 208 240t-39.25-2.75Q130.75 232 120 232q-29.5 0-46.75 21T56 304q0 22 8 38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0 37.25-1.75t35-7.375 30.5-15 20.25-25.75T360 304zm56-44q0 51.75-15.25 82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5T212 416q-19.5 0-35.5-.75t-36.875-3.125-38.125-7.5-34.25-12.875T37 371.5t-21.5-28.75Q0 312 0 260q0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25 30.875Q171.5 96 212 96q37 0 70 8 26.25-20.5 46.75-30.25T376 64q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34 99.5z" / > < / svg >
< / defs >
< / svg >
2021-03-06 21:00:26 +08:00
< input class = "md-toggle" data-md-toggle = "drawer" type = "checkbox" id = "__drawer" autocomplete = "off" >
< input class = "md-toggle" data-md-toggle = "search" type = "checkbox" id = "__search" autocomplete = "off" >
2024-09-30 20:56:16 +08:00
< label class = "md-overlay" data-md-component = "overlay" for = "__drawer" > < / label >
< a href = "#new-plugin-system-for-pinry" tabindex = "1" class = "md-skip" >
Skip to content
< / a >
2021-03-06 21:00:26 +08:00
2022-02-18 22:30:02 -08:00
< header class = "md-header" data-md-component = "header" >
2024-09-30 20:56:16 +08:00
< nav class = "md-header-nav md-grid" >
< div class = "md-flex" >
< div class = "md-flex__cell md-flex__cell--shrink" >
2024-09-30 20:58:34 +08:00
< a href = "https://pinry.github.io/pinry/" title = "Pinry Docs" class = "md-header-nav__button md-logo" >
2024-09-30 20:56:16 +08:00
< i class = "md-icon" > < / i >
< / a >
< / div >
< div class = "md-flex__cell md-flex__cell--shrink" >
< label class = "md-icon md-icon--menu md-header-nav__button" for = "__drawer" > < / label >
< / div >
< div class = "md-flex__cell md-flex__cell--stretch" >
< div class = "md-flex__ellipsis md-header-nav__title" data-md-component = "title" >
< span class = "md-header-nav__topic" >
Pinry Docs
< / span >
< span class = "md-header-nav__topic" >
Plugin System
< / span >
2020-05-08 11:06:48 +08:00
< / div >
< / div >
2024-09-30 20:56:16 +08:00
< div class = "md-flex__cell md-flex__cell--shrink" >
< label class = "md-icon md-icon--search md-header-nav__button" for = "__search" > < / label >
2020-05-08 11:06:48 +08:00
< div class = "md-search" data-md-component = "search" role = "dialog" >
< label class = "md-search__overlay" for = "__search" > < / label >
< div class = "md-search__inner" role = "search" >
< form class = "md-search__form" name = "search" >
2024-09-30 20:56:16 +08:00
< input type = "text" class = "md-search__input" name = "query" placeholder = "Search" autocapitalize = "off" autocorrect = "off" autocomplete = "off" spellcheck = "false" data-md-component = "query" data-md-state = "active" >
< label class = "md-icon md-search__icon" for = "__search" > < / label >
< button type = "reset" class = "md-icon md-search__icon" data-md-component = "reset" tabindex = "-1" >

2020-05-08 11:06:48 +08:00
< / button >
< / form >
< div class = "md-search__output" >
< div class = "md-search__scrollwrap" data-md-scrollfix >
2024-09-30 20:56:16 +08:00
< div class = "md-search-result" data-md-component = "result" >
2020-05-08 11:06:48 +08:00
< div class = "md-search-result__meta" >
2024-09-30 20:56:16 +08:00
Type to start searching
2020-05-08 11:06:48 +08:00
< / div >
< ol class = "md-search-result__list" > < / ol >
< / div >
< / div >
< / div >
< / div >
< / div >
2024-09-30 20:56:16 +08:00
< / div >
< div class = "md-flex__cell md-flex__cell--shrink" >
< div class = "md-header-nav__source" >
< a href = "https://github.com/pinry/pinry/" title = "Go to repository" class = "md-source" data-md-source = "github" >
< div class = "md-source__icon" >
< svg viewBox = "0 0 24 24" width = "24" height = "24" >
< use xlink:href = "#__github" width = "24" height = "24" > < / use >
< / svg >
< / div >
2020-05-08 11:06:48 +08:00
< div class = "md-source__repository" >
pinry/pinry
< / div >
< / a >
2024-09-30 20:56:16 +08:00
< / div >
< / div >
< / div >
2020-05-08 11:06:48 +08:00
< / nav >
< / header >
2024-09-30 20:56:16 +08:00
< div class = "md-container" >
2020-05-08 11:06:48 +08:00
2021-03-06 21:00:26 +08:00
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< main class = "md-main" role = "main" >
< div class = "md-main__inner md-grid" data-md-component = "container" >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< div class = "md-sidebar md-sidebar--primary" data-md-component = "navigation" >
2020-05-08 11:06:48 +08:00
< div class = "md-sidebar__scrollwrap" >
< div class = "md-sidebar__inner" >
2024-09-30 20:56:16 +08:00
< nav class = "md-nav md-nav--primary" data-md-level = "0" >
< label class = "md-nav__title md-nav__title--site" for = "__drawer" >
2024-09-30 20:58:34 +08:00
< a href = "https://pinry.github.io/pinry/" title = "Pinry Docs" class = "md-nav__button md-logo" >
2024-09-30 20:56:16 +08:00
< i class = "md-icon" > < / i >
2020-05-08 11:06:48 +08:00
< / a >
Pinry Docs
< / label >
< div class = "md-nav__source" >
2024-09-30 20:56:16 +08:00
< a href = "https://github.com/pinry/pinry/" title = "Go to repository" class = "md-source" data-md-source = "github" >
< div class = "md-source__icon" >
< svg viewBox = "0 0 24 24" width = "24" height = "24" >
< use xlink:href = "#__github" width = "24" height = "24" > < / use >
< / svg >
< / div >
2020-05-08 11:06:48 +08:00
< div class = "md-source__repository" >
pinry/pinry
< / div >
< / a >
< / div >
< ul class = "md-nav__list" data-md-scrollfix >
2024-09-30 20:56:16 +08:00
< li class = "md-nav__item" >
< a href = ".." title = "Home" class = "md-nav__link" >
Home
< / a >
< / li >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< li class = "md-nav__item" >
< a href = "../screenshots/" title = "Screenshots" class = "md-nav__link" >
Screenshots
< / a >
< / li >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< li class = "md-nav__item" >
< a href = "../extensions/" title = "Extensions" class = "md-nav__link" >
Extensions
< / a >
< / li >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< li class = "md-nav__item" >
< a href = "../theories/" title = "Theories" class = "md-nav__link" >
Theories
< / a >
< / li >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< li class = "md-nav__item" >
< a href = "../install-with-docker/" title = "Install with Docker" class = "md-nav__link" >
Install with Docker
< / a >
< / li >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< li class = "md-nav__item" >
< a href = "../development/" title = "Development" class = "md-nav__link" >
Development
< / a >
< / li >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< li class = "md-nav__item" >
< a href = "../api/" title = "API support" class = "md-nav__link" >
API support
< / a >
< / li >
2022-02-18 22:30:02 -08:00
2024-09-30 20:56:16 +08:00
< li class = "md-nav__item md-nav__item--active" >
< input class = "md-toggle md-nav__toggle" data-md-toggle = "toc" type = "checkbox" id = "__toc" >
2020-05-08 11:06:48 +08:00
2021-03-06 21:00:26 +08:00
2024-09-30 20:56:16 +08:00
< a href = "./" title = "Plugin System" class = "md-nav__link md-nav__link--active" >
Plugin System
< / a >
< / li >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< li class = "md-nav__item" >
< a href = "../upgrade-guide/" title = "Upgrade Guide" class = "md-nav__link" >
Upgrade Guide
< / a >
< / li >
2020-07-18 16:35:25 +08:00
2024-09-30 20:56:16 +08:00
< li class = "md-nav__item" >
< a href = "../docs/" title = "Docs" class = "md-nav__link" >
Docs
< / a >
< / li >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< li class = "md-nav__item" >
< a href = "../passwords/" title = "Passwords" class = "md-nav__link" >
Passwords
< / a >
< / li >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< li class = "md-nav__item" >
< a href = "../assets/" title = "Assets" class = "md-nav__link" >
Assets
< / a >
< / li >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< li class = "md-nav__item" >
< a href = "../contributing/" title = "Contributing" class = "md-nav__link" >
Contributing
< / a >
< / li >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< li class = "md-nav__item" >
< a href = "../license/" title = "License" class = "md-nav__link" >
License
< / a >
< / li >
2020-05-08 11:06:48 +08:00
< / ul >
< / nav >
< / div >
< / div >
< / div >
2024-09-30 20:56:16 +08:00
< div class = "md-sidebar md-sidebar--secondary" data-md-component = "toc" >
2020-05-08 11:06:48 +08:00
< div class = "md-sidebar__scrollwrap" >
< div class = "md-sidebar__inner" >
2024-09-30 20:56:16 +08:00
< nav class = "md-nav md-nav--secondary" >
2020-05-08 11:06:48 +08:00
< / nav >
< / div >
< / div >
< / div >
2024-09-30 20:56:16 +08:00
< div class = "md-content" >
2020-05-08 11:06:48 +08:00
< article class = "md-content__inner md-typeset" >
2024-09-30 20:56:16 +08:00
< a href = "https://github.com/pinry/pinry/edit/master/docs/src/plugin-system.md" title = "Edit this page" class = "md-icon md-content__icon" >  < / a >
2020-05-08 11:06:48 +08:00
< h1 id = "new-plugin-system-for-pinry" > New plugin system for Pinry< a class = "headerlink" href = "#new-plugin-system-for-pinry" title = "Permanent link" > ¶ < / a > < / h1 >
2020-05-08 11:25:54 +08:00
< p > New plugin system is under development and a naive version has been released.< / p >
< p > A < code > PinryPlugin< / code > is a python class or object which is callable.
2020-05-08 13:01:53 +08:00
The plugin loader will call the < code > Plugin< / code > target only once and use the plugin
2020-05-08 11:25:54 +08:00
instance after specified events triggered just like the way django-middleware works.< / p >
2020-05-08 13:01:53 +08:00
< p > You could create a plugin as python-package with content below:< / p >
2024-09-30 20:56:16 +08:00
< div class = "codehilite" > < pre > < span > < / span > < span class = "kn" > from< / span > < span class = "nn" > core.models< / span > < span class = "kn" > import< / span > < span class = "n" > Image< / span >
2020-05-08 11:25:54 +08:00
< span class = "kn" > from< / span > < span class = "nn" > django_images.models< / span > < span class = "kn" > import< / span > < span class = "n" > Thumbnail< / span >
< span class = "k" > class< / span > < span class = "nc" > Plugin< / span > < span class = "p" > :< / span >
< span class = "k" > def< / span > < span class = "fm" > __init__< / span > < span class = "p" > (< / span > < span class = "bp" > self< / span > < span class = "p" > ):< / span >
2020-05-08 13:01:53 +08:00
< span class = "c1" > # do something you want, just be called only once< / span >
2020-05-08 11:25:54 +08:00
< span class = "k" > pass< / span >
< span class = "k" > def< / span > < span class = "nf" > process_image_pre_creation< / span > < span class = "p" > (< / span > < span class = "bp" > self< / span > < span class = "p" > ,< / span > < span class = "n" > django_settings< / span > < span class = "p" > ,< / span > < span class = "n" > image_instance< / span > < span class = "p" > :< / span > < span class = "n" > Image< / span > < span class = "p" > ):< / span >
< span class = "k" > pass< / span >
< span class = "k" > def< / span > < span class = "nf" > process_thumbnail_pre_creation< / span > < span class = "p" > (< / span > < span class = "bp" > self< / span > < span class = "p" > ,< / span > < span class = "n" > django_settings< / span > < span class = "p" > ,< / span > < span class = "n" > thumbnail_instance< / span > < span class = "p" > :< / span > < span class = "n" > Thumbnail< / span > < span class = "p" > ):< / span >
< span class = "k" > pass< / span >
2024-09-30 20:56:16 +08:00
< / pre > < / div >
2020-05-08 11:25:54 +08:00
2022-02-18 22:30:02 -08:00
2020-05-08 11:25:54 +08:00
< p > You could make some changes on Image object and Thumbnail object
before they actually be saved (for example, add water-mark to them).< / p >
< p > You could access example plugin via < code > pinry_plugins/batteries/plugin_example.py< / code > .< / p >
< p > After all, enable the plugin in local_settings.py:< / p >
2024-09-30 20:56:16 +08:00
< div class = "codehilite" > < pre > < span > < / span > ENABLED_PLUGINS = [
2021-03-06 21:00:26 +08:00
' pinry_plugins.batteries.plugin_example.Plugin' ,
]
2024-09-30 20:56:16 +08:00
< / pre > < / div >
2020-05-08 11:06:48 +08:00
2022-02-18 22:30:02 -08:00
2020-05-08 11:06:48 +08:00
< p > Now the plugin will work like a charm!< / p >
2020-05-08 11:25:54 +08:00
< h1 id = "list-of-available-plugins" > List of Available Plugins< a class = "headerlink" href = "#list-of-available-plugins" title = "Permanent link" > ¶ < / a > < / h1 >
< p > left blank to fill, coming soon...< / p >
< h1 id = "install-plugin-in-docker" > Install Plugin in Docker< a class = "headerlink" href = "#install-plugin-in-docker" title = "Permanent link" > ¶ < / a > < / h1 >
2020-05-08 12:59:32 +08:00
< p > If you have a plugin named < code > hello.py< / code > and it have a < code > Plugin< / code > class inside.< / p >
< p > You could just copy it to directory < code > pinry_plugins/batteries< / code > .< / p >
2020-05-08 11:25:54 +08:00
< p > Now add config to local_settings.py< / p >
2024-09-30 20:56:16 +08:00
< div class = "codehilite" > < pre > < span > < / span > ENABLED_PLUGINS = [
2021-03-06 21:00:26 +08:00
' pinry_plugins.batteries.hello.Plugin' ,
]
2024-09-30 20:56:16 +08:00
< / pre > < / div >
2020-05-08 11:25:54 +08:00
2022-02-18 22:30:02 -08:00
2020-05-08 11:25:54 +08:00
< p > Then, rebuild your docker image, the plugin will work
if no further python dependencies required.< / p >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
2020-05-08 11:06:48 +08:00
< / article >
< / div >
< / div >
< / main >
< footer class = "md-footer" >
2024-09-30 20:56:16 +08:00
< div class = "md-footer-nav" >
< nav class = "md-footer-nav__inner md-grid" >
< a href = "../api/" title = "API support" class = "md-flex md-footer-nav__link md-footer-nav__link--prev" rel = "prev" >
< div class = "md-flex__cell md-flex__cell--shrink" >
< i class = "md-icon md-icon--arrow-back md-footer-nav__button" > < / i >
< / div >
< div class = "md-flex__cell md-flex__cell--stretch md-footer-nav__title" >
< span class = "md-flex__ellipsis" >
< span class = "md-footer-nav__direction" >
Previous
< / span >
API support
2020-05-08 11:06:48 +08:00
< / span >
< / div >
2024-09-30 20:56:16 +08:00
< / a >
< a href = "../upgrade-guide/" title = "Upgrade Guide" class = "md-flex md-footer-nav__link md-footer-nav__link--next" rel = "next" >
< div class = "md-flex__cell md-flex__cell--stretch md-footer-nav__title" >
< span class = "md-flex__ellipsis" >
< span class = "md-footer-nav__direction" >
Next
< / span >
Upgrade Guide
2020-05-08 11:06:48 +08:00
< / span >
< / div >
2024-09-30 20:56:16 +08:00
< div class = "md-flex__cell md-flex__cell--shrink" >
< i class = "md-icon md-icon--arrow-forward md-footer-nav__button" > < / i >
< / div >
< / a >
< / nav >
< / div >
2020-05-08 11:06:48 +08:00
< div class = "md-footer-meta md-typeset" >
< div class = "md-footer-meta__inner md-grid" >
< div class = "md-footer-copyright" >
< div class = "md-footer-copyright__highlight" >
Copyright © 2019 Pinry's Contributors
< / div >
2024-09-30 20:56:16 +08:00
powered by
< a href = "https://www.mkdocs.org" > MkDocs< / a >
and
< a href = "https://squidfunk.github.io/mkdocs-material/" >
Material for MkDocs< / a >
2020-05-08 11:06:48 +08:00
< / div >
< div class = "md-footer-social" >
2024-09-30 20:56:16 +08:00
< link rel = "stylesheet" href = "../assets/fonts/font-awesome.css" >
2020-05-08 11:06:48 +08:00
2024-09-30 20:56:16 +08:00
< a href = "https://github.com/pinry/pinry" class = "md-footer-social__link fa fa-" > < / a >
2020-05-08 11:06:48 +08:00
< / div >
< / div >
< / div >
< / footer >
< / div >
2021-03-06 21:00:26 +08:00
2024-09-30 20:56:16 +08:00
< script src = "../assets/javascripts/application.808e90bb.js" > < / script >
< script > app . initialize ( { version : "1.0.4" , url : { base : ".." } } ) < / script >
2020-05-08 11:06:48 +08:00
< / body >
< / html >