Skip to content

Redirects: allow update #9593

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

Merged
merged 5 commits into from
Sep 14, 2022
Merged

Redirects: allow update #9593

merged 5 commits into from
Sep 14, 2022

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Sep 8, 2022

Looks like we already allow updating redirects via the API https://docs.readthedocs.io/en/stable/api/v3.html#redirect-update, so this allows updating redirects from the UI. I have moved the form to its own page as we do with more of our CRUD operations.

Closes #9418.


📚 Documentation previews 📚

Comment on lines -688 to -699
def save(self, **_): # pylint: disable=arguments-differ
# TODO this should respect the unused argument `commit`. It's not clear
# why this needs to be a call to `create`, instead of relying on the
# super `save()` call.
redirect = Redirect.objects.create(
project=self.project,
redirect_type=self.cleaned_data["redirect_type"],
from_url=self.cleaned_data["from_url"],
to_url=self.cleaned_data["to_url"],
force=self.cleaned_data.get("force", False),
)
return redirect
Copy link
Member Author

Choose a reason for hiding this comment

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

We were doing this override to allow passing the project, but by using the trick of listing the project field and always using the project we pass to form this isn't needed anymore.

Comment on lines -42 to -63
$('#id_from_url').parent().hide()
$('#id_to_url').parent().hide()
$('#dynamic-redirect').hide()

update_outcome();
$('#id_redirect_type').bind('change', function(ev) {
$('#id_from_url').val('');
$('#id_to_url').val('');
$('#id_from_url').parent().hide()
$('#id_to_url').parent().hide()

if (this.value == 'prefix') {
$('#id_from_url').parent().show()
$('#id_to_url').parent().hide()
}
else if (this.value == 'page') {
$('#id_from_url').parent().show()
$('#id_to_url').parent().show()
}
else if (this.value == 'exact') {
$('#id_from_url').parent().show()
$('#id_to_url').parent().show()
}
Copy link
Member Author

Choose a reason for hiding this comment

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

moved this logic to be inside the update_outcome function, this way it works when the form has pre-populated fields when editing an existing redirect.

Copy link
Member

Choose a reason for hiding this comment

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

I didn't fully check this Javascript code, but looks good!

@stsewd stsewd marked this pull request as ready for review September 8, 2022 19:44
@stsewd stsewd requested review from a team as code owners September 8, 2022 19:44
@stsewd stsewd requested review from agjohnson and humitos September 8, 2022 19:44
Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

Looks good!

Comment on lines -42 to -63
$('#id_from_url').parent().hide()
$('#id_to_url').parent().hide()
$('#dynamic-redirect').hide()

update_outcome();
$('#id_redirect_type').bind('change', function(ev) {
$('#id_from_url').val('');
$('#id_to_url').val('');
$('#id_from_url').parent().hide()
$('#id_to_url').parent().hide()

if (this.value == 'prefix') {
$('#id_from_url').parent().show()
$('#id_to_url').parent().hide()
}
else if (this.value == 'page') {
$('#id_from_url').parent().show()
$('#id_to_url').parent().show()
}
else if (this.value == 'exact') {
$('#id_from_url').parent().show()
$('#id_to_url').parent().show()
}
Copy link
Member

Choose a reason for hiding this comment

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

I didn't fully check this Javascript code, but looks good!

@stsewd stsewd merged commit 43ee207 into main Sep 14, 2022
@stsewd stsewd deleted the edit-redirect branch September 14, 2022 22:58
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.

Redirects: allow editing of redirects
2 participants