Skip to content

Add functionality to refresh tag form definitions#2

Merged
Kani999 merged 3 commits intomasterfrom
reloading_tags
Jun 9, 2025
Merged

Add functionality to refresh tag form definitions#2
Kani999 merged 3 commits intomasterfrom
reloading_tags

Conversation

@Kani999
Copy link
Collaborator

@Kani999 Kani999 commented Jun 9, 2025

  • Updated NetboxPluginReloaderConfig in __init__.py to refresh tag form definitions alongside custom field definitions.

This update ensures better integration of plugin models with NetBox's feature system.

Summary by CodeRabbit

  • Documentation

    • Updated README to clarify that both custom field and tag form definitions are refreshed, expanded compatibility details, and improved formatting.
  • Refactor

    • Simplified and generalized internal logic for registering plugin models and refreshing form fields.
  • Chores

    • Updated version to 4.3.1.
    • Removed Python 3.9 support from setup configuration.

…initions

- Updated `NetboxPluginReloaderConfig` in `__init__.py` to refresh tag form definitions alongside custom field definitions.
- Simplified `_refresh_form_field` method to handle both features dynamically.
- Enhanced docstrings for better clarity and documentation.
- Updated `README.md` to reflect changes, including the ability to reload custom field choices and tag choices.
- Improved compatibility matrix format in `README.md`.
- Updated `setup.py` metadata to ensure compatibility with Python 3.10+ and Django 5.0.

This update ensures better integration of plugin models with NetBox's feature system.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 9, 2025

"""

Walkthrough

The updates include a refactor of the plugin's initialization logic to generalize and simplify model registration and form field refreshing, extending support for tag forms alongside custom fields. Documentation was updated to reflect these changes and clarify version compatibility. The plugin version was incremented, and Python 3.9 support was removed from the setup configuration.

Changes

File(s) Change Summary
README.md Updated documentation to clarify plugin behavior, version compatibility, and minor formatting.
netbox_plugin_reloader/init.py Refactored plugin config: generalized model registration and form field refreshing, added tag support, simplified methods.
netbox_plugin_reloader/version.py Updated version from 4.3.0 to 4.3.1.
setup.py Removed Python 3.9 classifier from setup configuration.

Sequence Diagram(s)

sequenceDiagram
    participant NetBox
    participant PluginReloader
    participant PluginRegistry
    participant FormClass

    NetBox->>PluginReloader: Initialize (ready)
    PluginReloader->>PluginRegistry: Register missing plugin models
    PluginReloader->>FormClass: Refresh custom field form definitions
    PluginReloader->>FormClass: Refresh tag form definitions
Loading

Poem

In the garden of plugins, new seeds were sown,
With tags and fields, the forms have grown.
Version bumped, support refined,
Python 3.9 left behind.
A rabbit hops with code so neat—
Fresh docs and logic, can't be beat!
🐇✨
"""

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
README.md (1)

79-79: Format the URL as a proper markdown link.

The static analysis tool correctly identified a bare URL that should be formatted as a proper markdown link.

-- Based on https://github.com/netbox-community/netbox/discussions/17836
+- Based on [NetBox Community Discussion](https://github.com/netbox-community/netbox/discussions/17836)
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

79-79: Bare URL used
null

(MD034, no-bare-urls)

netbox_plugin_reloader/__init__.py (3)

48-50: Consider using keyword arguments for better readability.

The method signature has 6 parameters using positional arguments, which reduces readability and maintainability. Consider using keyword arguments for some parameters.

-    def _register_missing_plugin_models(
-        self, plugin_list, app_registry, netbox_registry, feature_mixins_map, model_register_function
-    ):
+    def _register_missing_plugin_models(
+        self, plugin_list, *, app_registry, netbox_registry, feature_mixins_map, model_register_function
+    ):

And update the call site accordingly:

-        self._register_missing_plugin_models(settings.PLUGINS, apps, registry, FEATURES_MAP, register_models)
+        self._register_missing_plugin_models(
+            settings.PLUGINS,
+            app_registry=apps,
+            netbox_registry=registry,
+            feature_mixins_map=FEATURES_MAP,
+            model_register_function=register_models
+        )
🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 48-48: Too many arguments (6/5)

(R0913)


[refactor] 48-48: Too many positional arguments (6/5)

(R0917)


73-77: Remove unnecessary .keys() call.

The static analysis tool correctly identified that checking key in dict.keys() is less efficient than key in dict.

-        return any(
-            app_label in registry["model_features"][feature_name]
-            and model_name in registry["model_features"][feature_name][app_label]
-            for feature_name in feature_mixins_map.keys()
-        )
+        return any(
+            app_label in registry["model_features"][feature_name]
+            and model_name in registry["model_features"][feature_name][app_label]
+            for feature_name in feature_mixins_map
+        )
🧰 Tools
🪛 Ruff (0.11.9)

76-76: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)


79-94: LGTM! Excellent refactoring that eliminates code duplication.

The generic _refresh_form_field method is well-designed and successfully eliminates code duplication while supporting multiple form types. The implementation correctly handles both custom fields and tags with appropriate labels and help text.

However, consider reducing the number of parameters to improve maintainability:

-    def _refresh_form_field(self, form_class, feature_name, object_type_class, field_class, translation_function):
+    def _refresh_form_field(self, form_class, feature_name):

And move the dependencies inside the method:

+        from core.models import ObjectType
+        from django.utils.translation import gettext_lazy as _
+        from utilities.forms.fields import ContentTypeMultipleChoiceField
+        
         field_labels = {
             "custom_fields": ("Object types", "The type(s) of object that have this custom field"),
             "tags": ("Object types", "The type(s) of object that can have this tag"),
         }

         label, help_text = field_labels[feature_name]

-        object_types_field = field_class(
-            label=translation_function(label),
-            queryset=object_type_class.objects.with_feature(feature_name),
-            help_text=translation_function(help_text),
+        object_types_field = ContentTypeMultipleChoiceField(
+            label=_(label),
+            queryset=ObjectType.objects.with_feature(feature_name),
+            help_text=_(help_text),
         )
🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 79-79: Too many arguments (6/5)

(R0913)


[refactor] 79-79: Too many positional arguments (6/5)

(R0917)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 940b24b and c181cb4.

📒 Files selected for processing (4)
  • README.md (4 hunks)
  • netbox_plugin_reloader/__init__.py (2 hunks)
  • netbox_plugin_reloader/version.py (1 hunks)
  • setup.py (0 hunks)
💤 Files with no reviewable changes (1)
  • setup.py
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
README.md

79-79: Bare URL used
null

(MD034, no-bare-urls)

🪛 Ruff (0.11.9)
netbox_plugin_reloader/__init__.py

76-76: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)

🪛 Pylint (3.3.7)
netbox_plugin_reloader/__init__.py

[refactor] 48-48: Too many arguments (6/5)

(R0913)


[refactor] 48-48: Too many positional arguments (6/5)

(R0917)


[refactor] 79-79: Too many arguments (6/5)

(R0913)


[refactor] 79-79: Too many positional arguments (6/5)

(R0917)

🔇 Additional comments (6)
netbox_plugin_reloader/version.py (1)

3-3: LGTM! Appropriate version bump for the feature enhancement.

The version increment from 4.3.0 to 4.3.1 correctly reflects the addition of tag form definition refresh functionality.

README.md (3)

9-9: LGTM! Documentation accurately reflects the enhanced functionality.

The addition of tag form definitions refresh is properly documented and aligns with the PR objectives.


18-19: LGTM! Compatibility matrix correctly updated.

The version mapping for NetBox 4.3.x with plugin version 4.3.x is accurate and follows the established pattern.


61-64: LGTM! Clear explanation of the enhanced functionality.

The updated description accurately explains that the plugin now refreshes both custom field and tag form definitions.

netbox_plugin_reloader/__init__.py (2)

36-36: LGTM! Correct import for tag form functionality.

The TagForm import is necessary for the enhanced functionality to refresh tag form definitions.


42-46: LGTM! Enhanced functionality successfully implements PR objectives.

The refactored code now refreshes both custom field and tag form definitions, which aligns perfectly with the PR objectives. The generic approach reduces code duplication.

Docstrings generation was requested by @Kani999.

* #2 (comment)

The following files were modified:

* `netbox_plugin_reloader/__init__.py`
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 9, 2025

Note

Generated docstrings for this pull request at #3

…Y3nix25i3

📝 Add docstrings to `reloading_tags`
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
netbox_plugin_reloader/__init__.py (3)

51-51: Consider refactoring to reduce parameter count.

The signature change to positional arguments is consistent with the call site. However, the method now has 6 parameters, which may impact readability and maintainability.

Consider grouping related parameters into a configuration object or using dependency injection to reduce the parameter count.


84-88: Improve performance by removing unnecessary .keys() call.

The refactoring to use any() is excellent and more pythonic. However, the .keys() call is unnecessary and impacts performance.

Apply this diff to remove the unnecessary .keys() call:

 return any(
     app_label in registry["model_features"][feature_name]
     and model_name in registry["model_features"][feature_name][app_label]
-    for feature_name in feature_mixins_map.keys()
+    for feature_name in feature_mixins_map
 )
🧰 Tools
🪛 Ruff (0.11.9)

87-87: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)


90-114: Excellent generalization with room for future improvement.

The new method effectively generalizes form field refreshing for multiple features. The implementation is clean and the hardcoded labels dictionary is appropriate for the current scope.

Consider reducing the parameter count in future iterations by:

  1. Creating a configuration dataclass for the method parameters
  2. Using dependency injection for the classes
  3. Moving the field labels to a class-level constant

This would improve maintainability and make the method easier to test.

🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 90-90: Too many arguments (6/5)

(R0913)


[refactor] 90-90: Too many positional arguments (6/5)

(R0917)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c181cb4 and 26ed41c.

📒 Files selected for processing (1)
  • netbox_plugin_reloader/__init__.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
netbox_plugin_reloader/__init__.py

87-87: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)

🪛 Pylint (3.3.7)
netbox_plugin_reloader/__init__.py

[refactor] 50-50: Too many arguments (6/5)

(R0913)


[refactor] 50-50: Too many positional arguments (6/5)

(R0917)


[refactor] 90-90: Too many arguments (6/5)

(R0913)


[refactor] 90-90: Too many positional arguments (6/5)

(R0917)

🔇 Additional comments (5)
netbox_plugin_reloader/__init__.py (5)

28-30: LGTM! Clear documentation of expanded functionality.

The updated docstring accurately reflects the new capability to refresh both custom field and tag form definitions.


38-38: LGTM! Necessary import for tag form functionality.

The TagForm import is correctly added to support the new tag form refresh capability.


44-48: LGTM! Clean refactoring to generalized approach.

The replacement of the specific method with generalized calls for both CustomFieldForm and TagForm improves code maintainability and follows DRY principles.


54-56: LGTM! Clear and concise documentation.

The updated docstring effectively describes the method's functionality while being more concise.


26-114: Well-executed refactoring that achieves the PR objectives.

The changes successfully add tag form definition refresh capability while improving code maintainability through generalization. The refactoring maintains existing functionality and follows good coding practices.

🧰 Tools
🪛 Ruff (0.11.9)

87-87: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)

🪛 Pylint (3.3.7)

[refactor] 50-50: Too many arguments (6/5)

(R0913)


[refactor] 50-50: Too many positional arguments (6/5)

(R0917)


[refactor] 90-90: Too many arguments (6/5)

(R0913)


[refactor] 90-90: Too many positional arguments (6/5)

(R0917)

@Kani999 Kani999 merged commit 4e80f64 into master Jun 9, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant