Skip to content

Conversation

@renatoalmeidaoliveira
Copy link
Contributor

Fixes: #16144 GetReturnURLMixin Support for Plugin Views

  • Check for Plugin model in queryset use case of GetReturnURLMixin

@renatoalmeidaoliveira renatoalmeidaoliveira requested review from a team and jeremystretch and removed request for a team March 25, 2025 01:22
Copy link
Member

@jeremystretch jeremystretch left a comment

Choose a reason for hiding this comment

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

Can we simplify the logic here to avoid duplicating the view name?

# Attempt to dynamically resolve the list view for the object
if hasattr(self, 'queryset'):
model_opts = self.queryset.model._meta
is_plugin = isinstance(self.queryset.model._meta.app_config, PluginConfig)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
is_plugin = isinstance(self.queryset.model._meta.app_config, PluginConfig)
prefix = 'plugins:' if isinstance(self.queryset.model._meta.app_config, PluginConfig) else ''

Comment on lines 155 to 158
if is_plugin:
return reverse(f'plugins:{model_opts.app_label}:{model_opts.model_name}_list')
else:
return reverse(f'{model_opts.app_label}:{model_opts.model_name}_list')
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if is_plugin:
return reverse(f'plugins:{model_opts.app_label}:{model_opts.model_name}_list')
else:
return reverse(f'{model_opts.app_label}:{model_opts.model_name}_list')
return reverse(f'{prefix}{model_opts.app_label}:{model_opts.model_name}_list')

@renatoalmeidaoliveira
Copy link
Contributor Author

@jeremystretch since get_viewname already implement that logic, I think that way is even cleaner and avoids repetitions.

@jeremystretch jeremystretch merged commit 7d80a45 into netbox-community:main Mar 27, 2025
3 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GetReturnURLMixin Support for Plugin Views

2 participants