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

Dropdown to select Advanced Settings #4710

Merged
merged 19 commits into from
Oct 23, 2018
Merged

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Oct 3, 2018

PR on top of #3676

Closes #3610

Still wip (needs tests and validate the revert case)

@stsewd stsewd added the PR: work in progress Pull request is not ready for full review label Oct 3, 2018
@stsewd
Copy link
Member Author

stsewd commented Oct 3, 2018

Just pointing to previous comments in the another PR/issue

#3676 (comment)

We can't do that, because the original field is a charfield type.

Do form validation on fields and choices for active versions and existing branches

Not sure if that is necessary, I think it only adds complexity, for example: when the project is created for first time, we don't have all the versions.

Cleaning our branch list periodically, it's append only for now

Actually, we do deletions too (when syncing the versions)

The reverse case, where you try to deactivate a version that set as your default version. Maybe just add validation and throw an error here

We definitely can do this, I don't think there are weird corner cases, I'll implement that tomorrow.

default_choice = (None, '-' * 9)
versions = self.instance.versions.values_list('slug', 'verbose_name')
self.fields['default_branch'].widget = forms.Select(
choices=[default_choice] + list(versions)
Copy link
Member Author

Choose a reason for hiding this comment

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

For default branch we need to list ALL versions (branches and tags, active and inactive ones)

'slug', 'verbose_name'
)
self.fields['default_version'].widget = forms.Select(
choices=versions
Copy link
Member Author

Choose a reason for hiding this comment

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

Here we only need the active ones

Copy link
Contributor

@agjohnson agjohnson left a comment

Choose a reason for hiding this comment

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

Some of the logic around project privacy is going to fall down on our commercial hosting, so I'm hesitant to include anything like that in the queries.

raise forms.ValidationError(
_(msg.format(self.instance.verbose_name))
)
return privacy_level
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic doesn't hold up on our commercial hosting. If private repositories are allowed on the instance, then we should allow any value here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just fixed the test that was failing because of the privacy restrictions 😢


versions = (
self.instance.all_active_versions()
.filter(privacy_level=PUBLIC)
Copy link
Contributor

Choose a reason for hiding this comment

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

This also doesn't hold up on our commercial hosting. It might be best to leave this sort of logic out of a query entirely, but at very least, it should only be checking this conditionally, if private privacy is not allowed.

@stsewd
Copy link
Member Author

stsewd commented Oct 3, 2018

This is ready, I also tested it locally.

screenshot_2018-10-03 edit advanced project settings read the docs

screenshot_2018-10-03 stable - kong read the docs

@stsewd stsewd removed the PR: work in progress Pull request is not ready for full review label Oct 3, 2018
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.

Changes look good!

I left some comments to be considered.

choices=[default_choice] + list(versions)
)

versions = self.instance.all_active_versions().values_list(
Copy link
Member

Choose a reason for hiding this comment

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

instead of reusing the versions variable name, use active_versions for easy reading.

def __init__(self, *args, **kwargs):
super(ProjectAdvancedForm, self).__init__(*args, **kwargs)

default_choice = (None, '-' * 9)
Copy link
Member

Choose a reason for hiding this comment

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

I Pythonic way to do this would be to use something like empty_value: https://docs.djangoproject.com/en/2.1/ref/forms/fields/#django.forms.TypedChoiceField.empty_value

I'm not 100% sure that this is possible here, but I think it should be.

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 are just replacing the widget (Select), so it's not possible https://docs.djangoproject.com/en/2.1/ref/forms/widgets/#django.forms.Select

'it should be active.'
)
raise forms.ValidationError(
_(msg.format(self.instance.verbose_name))
Copy link
Member

Choose a reason for hiding this comment

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

The message should be first translated and after that, formatted.

So, the _ function has to be added in the line 46 when the text is created.

@humitos humitos requested a review from agjohnson October 17, 2018 10:05
@stsewd
Copy link
Member Author

stsewd commented Oct 17, 2018

@humitos done, thanks for the review!

@humitos
Copy link
Member

humitos commented Oct 17, 2018

This is read to merge from my point of view. Let's wait for the @agjohnson 👍, though.

@agjohnson
Copy link
Contributor

Changes look great to me!

@agjohnson agjohnson merged commit 7fb4b18 into readthedocs:master Oct 23, 2018
@stsewd stsewd deleted the dropdown-menu branch October 23, 2018 16:55
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.

4 participants