-
Notifications
You must be signed in to change notification settings - Fork 288
PootlePlugin
Allan Nordhøy edited this page Apr 18, 2018
·
17 revisions
- 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)
- 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)
- Emit to all handlers
- Uses Django signals
####pootle_plugin.getters.extracted_path
:
If a part of a path is significant to a plugin it can extract the relevant parts
-
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
-
instance
- the object for which the cache has been expired
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
-
priority
- the priority of the unit
-
instance
- the object for which the cache has been expired
pootle_store.models.Unit
@provider(extracted_path, sender=TPTranslateView)
def extracted_path_provider(sender, **kwargs):
instance = kwargs["instance"]
####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"]