Skip to content

PootlePlugin

Allan Nordhøy edited this page Apr 18, 2018 · 17 revisions

3 types of delegation - get, gather, signal

get

  • Retrieve value(s) from first willing
  • Stop iterating further handlers if non-None is returned

Uses getter decorator for hooking up, e.g:

@getter(value_to_get, TPTranslateView)
def example_value_getter(sender, **kwargs):
    return "Foo"

You can retrieve values in the relevant view as follows:

delegated_value = value_to_get.get(sender=self.__class__, self)

Gather

  • Retrieve values from all willing handlers
  • (gather_context_data)
  • @provider / gather_context_data.gather()
@provider(value_to_gather, TPTranslateView)
def example_value_provider(sender, **kwargs):
    return "Foo"
delegated_value = value_to_gather.gather(sender=self.__class__, self)

Signal

  • Emit to all handlers
  • Uses Django signals

Pootle getters

####pootle_plugin.getters.extracted_path:

If a part of a path is significant to a plugin it can extract the relevant parts

Returns:
  • resource_path - this should be the resource_path of a Pootle object (ie dir_path/filename)
  • path_prefix - any additional path that should be placed between context path (i.e. /language0/project0) and resource_path
  • path_extra - a dictionary containing any objects that the plugin has extracted - eg a virtualfolder
Provides arguments:
  • instance - the object for which the cache has been expired
Senders:
  • str
  • pootle_translationproject.views.TPTranslateView
@provider(extracted_path, sender=TPTranslateView)
def extracted_path_provider(sender, **kwargs):
    instance = kwargs["instance"]

####pootle_plugin.getters.unit_priority:

Calculate the priority for a given unit

Returns:
  • priority - the priority of the unit
Provides arguments:
  • instance - the object for which the cache has been expired
Senders:
  • pootle_store.models.Unit
@provider(extracted_path, sender=TPTranslateView)
def extracted_path_provider(sender, **kwargs):
    instance = kwargs["instance"]

Pootle signals

####pootle.core.signals.object_obsoleted:

Emitted when any object is obsoleted

Provides arguments:

  • instance - the object being obsoleted

e.g. to listen for Projects becoming obsolete

@receiver(object_obsoleted, sender=Project)
def project_obsolete_handler(sender, **kwargs):
    instance = kwargs["instance"]

####cache_cleared:

Emitted when the cache is cleared for any object

Provides arguments:

  • instance - the object for which the cache has been expired
  • parent - True if parent objects have also had cache expired
  • children - True if child objects have also had cache expired

Senders:

  • Store
  • Directory
@receiver(cache_cleared, sender=Store)
def store_cache_cleared_handler(sender, **kwargs):
    instance = kwargs["instance"]
Clone this wiki locally