-
Notifications
You must be signed in to change notification settings - Fork 263
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
Conversation
nautobot/core/views/generic.py
Outdated
@@ -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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
…rperate feedback.
def get_changelog_url(self, instance): | ||
"""Return the changelog URL.""" | ||
route = "extras:customfield_changelog" | ||
return reverse(route, kwargs={"name": getattr(instance, "name")}) | ||
|
There was a problem hiding this comment.
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.
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 theget_changelog_url
method to objects that inherit fromChangeLoggedModel
.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 referenceobject.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 ofpk
orslug
all other models use (cough lets move that toslug
cough).TODO