浏览代码

Clarify fallback order for job result URLs in plugin docs; strengthen unresolvable model test

Jeremy Stretch 2 天之前
父节点
当前提交
6079179192
共有 2 个文件被更改,包括 4 次插入 和 2 次删除
  1. 2 2
      docs/plugins/development/background-jobs.md
  2. 2 0
      netbox/core/tests/test_utils.py

+ 2 - 2
docs/plugins/development/background-jobs.md

@@ -95,9 +95,9 @@ class MyModel(JobsMixin, NetBoxModel):
 
 
 ### Result URLs
 ### Result URLs
 
 
-By default, links to a job (such as those in the jobs list and in job completion notifications) lead to its generic view. A plugin which provides its own page for presenting the results of jobs associated with one of its models can register a function which returns the URL of that page, using the `register_job_result_url()` decorator from `core.utils`. The function accepts a Job instance and returns either a URL, or `None` to fall back to the generic view.
+By default, links to a job (such as those in the jobs list and in job completion notifications) lead to its generic view. A plugin which provides its own page for presenting the results of jobs associated with one of its models can register a function which returns the URL of that page, using the `register_job_result_url()` decorator from `core.utils`. The function accepts a Job instance and returns either a URL, or `None` to decline.
 
 
-Optionally, a job name may be specified to restrict the function to jobs having that name. A function registered for a specific job name takes precedence over one registered for the model alone. Only one function may be registered for each combination of model and job name.
+Optionally, a job name may be specified to restrict the function to jobs having that name. A function registered for a specific job name takes precedence over one registered for the model alone, which is consulted if the former returns `None`. The generic view is used if no function returns a URL. Only one function may be registered for each combination of model and job name.
 
 
 #### Example
 #### Example
 
 

+ 2 - 0
netbox/core/tests/test_utils.py

@@ -79,6 +79,8 @@ class JobResultURLTestCase(TestCase):
             self.assertEqual(self.get_job(DataSource).get_absolute_url(), reverse('core:job', args=[123]))
             self.assertEqual(self.get_job(DataSource).get_absolute_url(), reverse('core:job', args=[123]))
 
 
     def test_unresolvable_model(self):
     def test_unresolvable_model(self):
+        register_job_result_url(DataSource)(lambda job: '/foo/')
+
         # e.g. a model belonging to a plugin which has been uninstalled
         # e.g. a model belonging to a plugin which has been uninstalled
         object_type = ContentType.objects.create(app_label='uninstalled_plugin', model='foo')
         object_type = ContentType.objects.create(app_label='uninstalled_plugin', model='foo')
         job = Job(pk=123, name='Test Job', object_type=object_type, object_id=1)
         job = Job(pk=123, name='Test Job', object_type=object_type, object_id=1)