-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Allow modifying version slugs #4505
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,11 @@ | |
from __future__ import absolute_import | ||
from builtins import object | ||
from django import forms | ||
from django.utils.translation import ugettext_lazy as _, ugettext | ||
|
||
from readthedocs.builds.models import VersionAlias, Version | ||
from .constants import STABLE, LATEST | ||
from .models import VersionAlias, Version | ||
from .version_slug import VERSION_SLUG_REGEX | ||
from readthedocs.projects.models import Project | ||
from readthedocs.core.utils import trigger_build | ||
|
||
|
@@ -29,9 +32,34 @@ def __init__(self, instance=None, *args, **kwargs): # noqa | |
|
||
class VersionForm(forms.ModelForm): | ||
|
||
slug = forms.RegexField( | ||
'^{pattern}$'.format(pattern=VERSION_SLUG_REGEX), | ||
max_length=255, | ||
help_text=_("Used in this version's URL"), | ||
) | ||
|
||
class Meta(object): | ||
model = Version | ||
fields = ['active', 'privacy_level', 'tags'] | ||
fields = ['slug', 'active', 'privacy_level', 'tags'] | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(VersionForm, self).__init__(*args, **kwargs) | ||
if self.instance and self.instance.slug in (LATEST, STABLE): | ||
self.fields['slug'].disabled = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Besides making the field gray in the UI, does this validates this field in the backend also? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. However, our CSS doesn't make the field grey. |
||
self.fields['slug'].help_text += ugettext(' - read only for special versions') | ||
|
||
def clean_slug(self): | ||
slug = self.cleaned_data['slug'] | ||
|
||
version = self.instance | ||
if version: | ||
if Version.objects.filter(project=version.project, slug=slug).exclude( | ||
pk=version.pk).exists(): | ||
raise forms.ValidationError( | ||
_('There is already a version for this project with that slug'), | ||
) | ||
|
||
return slug | ||
|
||
def save(self, commit=True): | ||
obj = super(VersionForm, self).save(commit=commit) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -394,7 +394,9 @@ def build_versions_form(project): | |
version.identifier[:8], | ||
) | ||
else: | ||
label = version.verbose_name | ||
label = version.slug | ||
if version.slug not in version.identifier: | ||
label += ' ({})'.format(version.identifier) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will show something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only occurs where a version is not a tag so generally no. Looking a few lines above might clear this up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will look like |
||
attrs[field_name] = forms.BooleanField( | ||
label=label, | ||
widget=DualCheckboxWidget(version), | ||
|
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 believe for DNS this can only contain 63 characters. We should probably enforce this on the model though: https://stackoverflow.com/questions/10552665/names-and-maximum-lengths-of-the-parts-of-a-url
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.
There is some discussion around that here #3464
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.
#3464 is about project slugs, not version slugs. Correct?
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.
The regexfield is built to match the model (https://github.com/rtfd/readthedocs.org/blob/8282885/readthedocs/builds/models.py#L78). I'm happy to change it if you think that's appropriate but the two should match in my opinion.
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.
Also, while I think a 255 character version slug is long, we don't use the version for anything related to DNS correct? We use project slugs for that but not versions, correct?
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.
yes! I was confused, project slugs are used as subdomains, versions I don't think so
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.
Ah, good call. Ignore me :)