-
-
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 2 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 _ | ||
|
||
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 += _(' - 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).count() > 0: | ||
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. Use 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. Thanks. I feel like I do this all the time. |
||
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), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ | |
from django.views.generic import ListView, TemplateView, View | ||
from formtools.wizard.views import SessionWizardView | ||
from vanilla import CreateView, DeleteView, DetailView, GenericView, UpdateView | ||
|
||
from readthedocs.builds.constants import STABLE, LATEST | ||
from readthedocs.builds.forms import AliasForm, VersionForm | ||
from readthedocs.builds.models import Version, VersionAlias | ||
from readthedocs.core.mixins import ListViewWithForm, LoginRequiredMixin | ||
|
@@ -154,6 +156,12 @@ def project_version_detail(request, project_slug, version_slug): | |
if request.method == 'POST' and form.is_valid(): | ||
version = form.save() | ||
if form.has_changed(): | ||
if (version.active and 'slug' in form.changed_data and | ||
version.slug not in (STABLE, LATEST)): | ||
# Latest and Stable appear "changed" because they are disabled on the form | ||
log.info('Triggering a build of the moved version') | ||
trigger_build(version.project, version) | ||
|
||
if 'active' in form.changed_data and version.active is False: | ||
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. What would happen if we Since this is triggering async task something weird may happen. Not sure yet, though. 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. I'll check this edge case. |
||
log.info('Removing files for version %s', version.slug) | ||
broadcast( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,16 @@ | |
{% block content-header %}<h1>{% blocktrans with version.name as version_name %}{{ version_name }}{% endblocktrans %}</h1>{% endblock %} | ||
|
||
{% block content %} | ||
<h2> Editing {{ version.slug }} </h2> | ||
<h2>{% blocktrans with version_name=version.verbose_name %}Editing version {{ version_name }}{% endblocktrans %}</h2> | ||
|
||
<form method="post" action="."> | ||
{% csrf_token %} | ||
|
||
<p> | ||
<label>Version control identifier:</label> | ||
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. blocktrans here too? 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. Probably just regular |
||
<strong style="color: black">{{ version.identifier }}</strong> | ||
</p> | ||
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. The close tag is not at the same level |
||
|
||
{{ form.as_p }} | ||
<p> | ||
<input style="display: inline;" type="submit" value="{% trans "Save" %}"> | ||
|
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 :)