-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Redirects: allow update #9593
Conversation
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 |
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.
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.
$('#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() | ||
} |
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.
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.
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.
I didn't fully check this Javascript code, but looks good!
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.
Looks good!
$('#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() | ||
} |
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.
I didn't fully check this Javascript code, but looks good!
Co-authored-by: Manuel Kaufmann <[email protected]>
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 📚
docs
): https://docs--9593.org.readthedocs.build/en/9593/dev
): https://dev--9593.org.readthedocs.build/en/9593/