Skip to content

setting stable version manually #3723

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,22 @@ def save(self):
self.project.default_version = default_version
self.project.save()

stable_version_identifier = self.cleaned_data.get('stable-version', None)
if stable_version_identifier:
old_stable_version = self.project.get_stable_version()
if old_stable_version:
if old_stable_version.identifier != stable_version_identifier:
old_stable_version.identifier = stable_version_identifier
old_stable_version.save()
trigger_build(project=self.project, version=old_stable_version)
else:
new_stable = self.project.versions.filter(identifier=stable_version_identifier)
stable_version = self.project.versions.create_stable(
type=new_stable.type,
identifier=new_stable.identifier)
trigger_build(project=self.project, version=stable_version)


Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this blank line !

def save_version(self, version):
"""Save version if there has been a change, trigger a rebuild."""
new_value = self.cleaned_data.get(
Expand All @@ -347,7 +363,6 @@ def save_version(self, version):
if version.active and not version.built and not version.uploaded:
trigger_build(project=self.project, version=version)


Copy link
Contributor

Choose a reason for hiding this comment

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

Undo this !

def build_versions_form(project):
"""Versions form with a list of versions and version privacy levels."""
attrs = {
Expand All @@ -356,6 +371,11 @@ def build_versions_form(project):
versions_qs = project.versions.all() # Admin page, so show all versions
active = versions_qs.filter(active=True)
if active.exists():
attrs['stable-version'] = forms.ChoiceField(
label=_('Stable Version'),
choices=project.get_stable_version_choice(),
initial=project.get_default_version(),
)
choices = [(version.slug, version.verbose_name) for version in active]
attrs['default-version'] = forms.ChoiceField(
label=_('Default Version'),
Expand Down
13 changes: 11 additions & 2 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
RelatedProjectQuerySet)
from readthedocs.projects.templatetags.projects_tags import sort_version_aware
from readthedocs.projects.version_handling import (
determine_stable_version, version_windows)
determine_stable_version, version_windows, sort_versions)
from readthedocs.restapi.client import api
from readthedocs.vcs_support.backends import backend_cls
from readthedocs.vcs_support.utils import Lock, NonBlockingLock
Expand Down Expand Up @@ -724,11 +724,20 @@ def supported_versions(self):
def get_stable_version(self):
return self.versions.filter(slug=STABLE).first()

def get_stable_version_choice(self):
version_list = self.versions.all()
stable_version_choice = sort_versions(version_list)
stable_version_choice = [(version_obj.identifier, version_obj.verbose_name)
for version_obj, comparable in stable_version_choice
Copy link
Contributor

Choose a reason for hiding this comment

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

Indent this by only 4 spaces !

if (not comparable.is_prerelease and version_obj.active)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto !

return stable_version_choice


Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this blank line !

def update_stable_version(self):
"""
Returns the version that was promoted to be the new stable version.

Return ``None`` if no update was mode or if there is no version on the
Return ``None`` if no update was made or if there is no version on the
project that can be considered stable.
"""
versions = self.versions.all()
Expand Down
1 change: 1 addition & 0 deletions readthedocs/restapi/views/model_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def sync_versions(self, request, **kwargs): # noqa: D205
)

promoted_version = project.update_stable_version()
# promoted version will be none if no update was found.
if promoted_version:
new_stable = project.get_stable_version()
log.info(
Expand Down
9 changes: 6 additions & 3 deletions readthedocs/templates/projects/project_versions.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@
{% for field in form %}

{% if forloop.first %}
{# This is a custom form listing the possible active versions, to make 1 the default #}
{# This is a custom form listing possible active versions, to select default, stable #}
<h2> {{ field.label }} </h2>
{{ field }}

{% elif forloop.counter0 == 1 %}
<h2> {{ field.label }} </h2>
{{ field }}
<p>
{% trans "Choose the version that / will redirect to." %}
</p>

{% else %}

{% if forloop.counter0 == 1 %}
{% if forloop.counter0 == 2 %}
<h2> {% trans "Choose Active Versions" %} </h2>
<p>
{% trans "Active versions below will show up on the site." %}
Expand Down