Merge remote-tracking branch 'upstream/master' into basic_auth
This commit is contained in:
commit
9a899af02b
@ -11,6 +11,7 @@
|
||||
Dedication along with this software. If not, see
|
||||
<http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
|
||||
.. _plugin-api-chapter:
|
||||
|
||||
==========
|
||||
Plugin API
|
||||
@ -23,7 +24,27 @@ Authors are encouraged to develop plugins and work with the
|
||||
MediaGoblin community to keep them up to date, but this API will be a
|
||||
moving target for a few releases.
|
||||
|
||||
Please check the release notes for updates!
|
||||
Please check the :ref:`release-notes` for updates!
|
||||
|
||||
|
||||
How are hooks added? Where do I find them?
|
||||
-------------------------------------------
|
||||
|
||||
Much of this document talks about hooks, both as in terms of regular
|
||||
hooks and template hooks. But where do they come from, and how can
|
||||
you find a list of them?
|
||||
|
||||
For the moment, the best way to find available hooks is to check the
|
||||
source code itself. (Yes, we should start a more official hook
|
||||
listing with descriptions soon.) But many hooks you may need do not
|
||||
exist yet: what to do then?
|
||||
|
||||
The plan at present is that we are adding hooks as people need them,
|
||||
with community discussion. If you find that you need a hook and
|
||||
MediaGoblin at present doesn't provide it at present, please
|
||||
`http://mediagoblin.org/pages/join.html <talk to us>`_! We'll
|
||||
evaluate what to do from there.
|
||||
|
||||
|
||||
:mod:`pluginapi` Module
|
||||
-----------------------
|
||||
@ -172,3 +193,104 @@ object, so you can access this in your templates like:
|
||||
|
||||
<img alt="A funny bunny"
|
||||
src="{{ request.staticdirect('images/funnybunny.png', 'mystaticname') }}" />
|
||||
|
||||
|
||||
Additional hook tips
|
||||
--------------------
|
||||
|
||||
This section aims to explain some tips in regards to adding hooks to
|
||||
the MediaGoblin repository.
|
||||
|
||||
WTForms hooks
|
||||
+++++++++++++
|
||||
|
||||
We haven't totally settled on a way to tranform wtforms form objects,
|
||||
but here's one way. In your view::
|
||||
|
||||
from mediagoblin.foo.forms import SomeForm
|
||||
|
||||
def some_view(request)
|
||||
form_class = hook_transform('some_form_transform', SomeForm)
|
||||
form = form_class(request.form)
|
||||
|
||||
Then to hook into this form, do something in your plugin like::
|
||||
|
||||
import wtforms
|
||||
|
||||
class SomeFormAdditions(wtforms.Form):
|
||||
new_datefield = wtforms.DateField()
|
||||
|
||||
def transform_some_form(orig_form):
|
||||
class ModifiedForm(orig_form, SomeFormAdditions)
|
||||
return ModifiedForm
|
||||
|
||||
hooks = {
|
||||
'some_form_transform': transform_some_form}
|
||||
|
||||
|
||||
Interfaces
|
||||
++++++++++
|
||||
|
||||
If you want to add a pseudo-interface, it's not difficult to do so.
|
||||
Just write the interface like so::
|
||||
|
||||
class FrobInterface(object):
|
||||
"""
|
||||
Interface for Frobbing.
|
||||
|
||||
Classes implementing this interface should provide defrob and frob.
|
||||
They may also implement double_frob, but it is not required; if
|
||||
not provided, we will use a general technique.
|
||||
"""
|
||||
|
||||
def defrob(self, frobbed_obj):
|
||||
"""
|
||||
Take a frobbed_obj and defrob it. Returns the defrobbed object.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def frob(self, normal_obj):
|
||||
"""
|
||||
Take a normal object and frob it. Returns the frobbed object.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def double_frob(self, normal_obj):
|
||||
"""
|
||||
Frob this object and return it multiplied by two.
|
||||
"""
|
||||
return self.frob(normal_obj) * 2
|
||||
|
||||
|
||||
def some_frob_using_method():
|
||||
# something something something
|
||||
frobber = hook_handle(FrobInterface)
|
||||
frobber.frob(blah)
|
||||
|
||||
# alternately you could have a default
|
||||
frobber = hook_handle(FrobInterface) or DefaultFrobber
|
||||
frobber.defrob(foo)
|
||||
|
||||
|
||||
It's fine to use your interface as the key instead of a string if you
|
||||
like. (Usually this is messy, but since interfaces are public and
|
||||
since you need to import them into your plugin anyway, interfaces
|
||||
might as well be keys.)
|
||||
|
||||
Then a plugin providing your interface can be like::
|
||||
|
||||
from mediagoblin.foo.frobfrogs import FrobInterface
|
||||
from frogfrobber import utils
|
||||
|
||||
class FrogFrobber(FrobInterface):
|
||||
"""
|
||||
Takes a frogputer science approach to frobbing.
|
||||
"""
|
||||
def defrob(self, frobbed_obj):
|
||||
return utils.frog_defrob(frobbed_obj)
|
||||
|
||||
def frob(self, normal_obj):
|
||||
return utils.frog_frob(normal_obj)
|
||||
|
||||
hooks = {
|
||||
FrobInterface: lambda: return FrogFrobber}
|
||||
|
@ -12,9 +12,12 @@
|
||||
<http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
|
||||
|
||||
========
|
||||
Database
|
||||
========
|
||||
.. _plugin-database-chapter:
|
||||
|
||||
|
||||
===========================
|
||||
Database models for plugins
|
||||
===========================
|
||||
|
||||
|
||||
Accessing Existing Data
|
||||
|
@ -178,8 +178,10 @@ That's it for the quick start!
|
||||
Where to go from here
|
||||
=====================
|
||||
|
||||
See the documentation on the plugin API for code samples and other
|
||||
things you can use when building your plugin.
|
||||
See the documentation on the :ref:`plugin-api-chapter` for code
|
||||
samples and other things you can use when building your plugin. If
|
||||
your plugin needs its own database models, see
|
||||
:ref:`plugin-database-chapter`.
|
||||
|
||||
See `Hitchhiker's Guide to Packaging
|
||||
<http://guide.python-distribute.org/>`_ for more information on
|
||||
|
@ -11,6 +11,8 @@
|
||||
Dedication along with this software. If not, see
|
||||
<http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
|
||||
.. _release-notes:
|
||||
|
||||
=============
|
||||
Release Notes
|
||||
=============
|
||||
|
@ -134,7 +134,7 @@ spectrogram_fft_size = integer(default=4096)
|
||||
thumbnail_font = string(default=None)
|
||||
|
||||
[media_type:mediagoblin.media_types.pdf]
|
||||
pdf_js = boolean(default=False)
|
||||
pdf_js = boolean(default=True)
|
||||
|
||||
|
||||
[celery]
|
||||
|
@ -433,9 +433,12 @@ a.thumb_entry_title {
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.media_thumbnail img {
|
||||
max-height: 135px;
|
||||
}
|
||||
/* For now, this is commented out since our thumbnails are actually 180px high.
|
||||
*
|
||||
* .media_thumbnail img {
|
||||
* max-height: 135px;
|
||||
* }
|
||||
*/
|
||||
|
||||
.thumb_entry_last {
|
||||
margin-right: 0px;
|
||||
|
@ -27,3 +27,20 @@
|
||||
{{ super() }}
|
||||
{% template_hook("image_sideinfo") %}
|
||||
{% endblock %}
|
||||
|
||||
{% block mediagoblin_after_added_sidebar %}
|
||||
{% if app_config['original_date_visible'] %}
|
||||
{% set original_date = media.media_manager.get_original_date() %}
|
||||
|
||||
{% if original_date %}
|
||||
<h3>{% trans %}Created{% endtrans %}</h3>
|
||||
|
||||
<p><span title="{{ original_date.strftime("%I:%M%p %Y-%m-%d") }}">
|
||||
{%- trans formatted_time=timesince(original_date) -%}
|
||||
{{ formatted_time }} ago
|
||||
{%- endtrans -%}
|
||||
</span></p>
|
||||
{%- endif %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
@ -154,19 +154,8 @@
|
||||
{%- endtrans -%}
|
||||
</span></p>
|
||||
|
||||
{% if app_config['original_date_visible'] %}
|
||||
{% set original_date = media.media_manager.get_original_date() %}
|
||||
|
||||
{% if original_date %}
|
||||
<h3>{% trans %}Created{% endtrans %}</h3>
|
||||
|
||||
<p><span title="{{ original_date.strftime("%I:%M%p %Y-%m-%d") }}">
|
||||
{%- trans formatted_time=timesince(original_date) -%}
|
||||
{{ formatted_time }} ago
|
||||
{%- endtrans -%}
|
||||
</span></p>
|
||||
{%- endif %}
|
||||
{% endif %}
|
||||
{% block mediagoblin_after_added_sidebar %}
|
||||
{% endblock %}
|
||||
|
||||
{% if media.tags %}
|
||||
{% include "mediagoblin/utils/tags.html" %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user