Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_changelog_url Method to Objects that Support Changelogs #2049

Merged
merged 2 commits into from
Jul 15, 2022

Conversation

bryanculver
Copy link
Member

Closes: #DNE

What's Changed

In working with @smk4664 on #1984 it was discovered that more than just the model object is needed to be passed down in context to render the tabs.

Just like we have the get_absolute_url method on objects in aiding to reverse resolve the URL to the object, this adds the get_changelog_url method to objects that inherit from ChangeLoggedModel.

This will eventually eliminate the need for changelog_url to be passed down in the view context but is kept for now for backwards compatibility. It is no longer used in the views as the template itself has been updated to reference object.get_changelog_url. Existing methods are also kept for the time being.

CustomField models must override this as they key on the name of the Custom Field instead of pk or slug all other models use (cough lets move that to slug cough).

TODO

  • Explanation of Change(s)
  • NA Attached Screenshots, Payload Example
  • Unit, Integration Tests
  • [?] Documentation Updates (when adding/changing features)
  • [?] Example Plugin Updates (when adding/changing features)
  • Outline Remaining Work, Constraints from Design

nautobot/extras/models/customfields.py Outdated Show resolved Hide resolved
nautobot/extras/views.py Outdated Show resolved Hide resolved
@@ -123,7 +126,7 @@ def get(self, request, *args, **kwargs):
"object": instance,
"verbose_name": self.queryset.model._meta.verbose_name,
"verbose_name_plural": self.queryset.model._meta.verbose_name_plural,
"changelog_url": self.get_changelog_url(instance),
"changelog_url": instance.get_changelog_url(), # TODO: Remove in 2.0. This information can be retrieved from the object itself now.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is going to blow up if instance doesn't have a get_changelog_url method.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is probably what's causing CI to fail. This was quick and I wanted to get eyes out there. I'm going to do some proper validation.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

Comment on lines -347 to -351
def get_changelog_url(self, instance):
"""Return the changelog URL."""
route = "extras:customfield_changelog"
return reverse(route, kwargs={"name": getattr(instance, "name")})

Copy link
Member Author

Choose a reason for hiding this comment

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

Since it's not likely something is subclassing CustomFieldView this should be safe to remove but I'm OK with leaving it and restoring the # TODO: Remove... note.

@bryanculver bryanculver merged commit 23ff79f into next Jul 15, 2022
bryanculver added a commit that referenced this pull request Jul 15, 2022
@bryanculver bryanculver deleted the bsc-get_changelog_url-on-object branch July 27, 2022 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants