Просмотр исходного кода

Rename obj to object; clean up docstrings

Jeremy Stretch 5 лет назад
Родитель
Сommit
8a3ebf64bc
3 измененных файлов с 15 добавлено и 11 удалено
  1. 1 1
      docs/plugins/development.md
  2. 13 9
      netbox/extras/plugins/__init__.py
  3. 1 1
      netbox/extras/templatetags/plugins.py

+ 1 - 1
docs/plugins/development.md

@@ -329,7 +329,7 @@ Additionally, a `render()` method is available for convenience. This method acce
 
 
 When a PluginTemplateExtension is instantiated, context data is assigned to `self.context`. Available data include:
 When a PluginTemplateExtension is instantiated, context data is assigned to `self.context`. Available data include:
 
 
-* `obj` - The object being viewed
+* `object` - The object being viewed
 * `request` - The current request
 * `request` - The current request
 * `settings` - Global NetBox settings
 * `settings` - Global NetBox settings
 * `config` - Plugin-specific configuration parameters
 * `config` - Plugin-specific configuration parameters

+ 13 - 9
netbox/extras/plugins/__init__.py

@@ -75,29 +75,33 @@ class PluginConfig(AppConfig):
 
 
 class PluginTemplateExtension:
 class PluginTemplateExtension:
     """
     """
-    This class is used to register plugin content to be injected into core NetBox templates.
-    It contains methods that are overridden by plugin authors to return template content.
+    This class is used to register plugin content to be injected into core NetBox templates. It contains methods
+    that are overridden by plugin authors to return template content.
 
 
-    The `model` attribute on the class defines the which model detail page this class renders
-    content for. It should be set as a string in the form '<app_label>.<model_name>'.
+    The `model` attribute on the class defines the which model detail page this class renders content for. It
+    should be set as a string in the form '<app_label>.<model_name>'. render() provides the following context data:
+
+    * object - The object being viewed
+    * request - The current request
+    * settings - Global NetBox settings
+    * config - Plugin-specific configuration parameters
     """
     """
     model = None
     model = None
 
 
     def __init__(self, context):
     def __init__(self, context):
         self.context = context
         self.context = context
 
 
-    def render(self, template, extra_context=None):
+    def render(self, template_name, extra_context=None):
         """
         """
-        Convenience method for rendering the provided template name. The detail page object is automatically
-        passed into the template context as `obj` and the original detail page's context is available as
-        `obj_context`. An additional context dictionary may be passed as `extra_context`.
+        Convenience method for rendering the specified Django template using the default context data. An additional
+        context dictionary may be passed as `extra_context`.
         """
         """
         if extra_context is None:
         if extra_context is None:
             extra_context = {}
             extra_context = {}
         elif not isinstance(extra_context, dict):
         elif not isinstance(extra_context, dict):
             raise TypeError("extra_context must be a dictionary")
             raise TypeError("extra_context must be a dictionary")
 
 
-        return get_template(template).render({**self.context, **extra_context})
+        return get_template(template_name).render({**self.context, **extra_context})
 
 
     def left_page(self):
     def left_page(self):
         """
         """

+ 1 - 1
netbox/extras/templatetags/plugins.py

@@ -15,7 +15,7 @@ def _get_registered_content(obj, method, template_context):
     """
     """
     html = ''
     html = ''
     context = {
     context = {
-        'obj': obj,
+        'object': obj,
         'request': template_context['request'],
         'request': template_context['request'],
         'settings': template_context['settings'],
         'settings': template_context['settings'],
     }
     }