Skip to content

Commit

Permalink
Addons: default to semver for sorting versions (#11686)
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd authored Oct 15, 2024
1 parent 2ed3727 commit 83f1617
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 7 deletions.
85 changes: 85 additions & 0 deletions readthedocs/projects/migrations/0127_default_to_semver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Generated by Django 4.2.16 on 2024-10-15 16:07
from django.db import migrations, models
from django_safemigrate import Safe


class Migration(migrations.Migration):
safe = Safe.always
dependencies = [
("projects", "0126_alter_remote_repository_description"),
]

operations = [
migrations.AlterField(
model_name="addonsconfig",
name="flyout_sorting",
field=models.CharField(
choices=[
("alphabetically", "Alphabetically"),
("semver-readthedocs-compatible", "SemVer (Read the Docs)"),
("python-packaging", "Python Packaging (PEP 440 and PEP 425)"),
("calver", "CalVer (YYYY.0M.0M)"),
("custom-pattern", "Define your own pattern"),
],
default="semver-readthedocs-compatible",
max_length=64,
verbose_name="Sorting of versions",
),
),
migrations.AlterField(
model_name="addonsconfig",
name="flyout_sorting_custom_pattern",
field=models.CharField(
blank=True,
default=None,
help_text='Sorting pattern supported by BumpVer (<a href="https://github.com/mbarkhau/bumpver#pattern-examples">See examples</a>)',
max_length=32,
null=True,
verbose_name="Custom version sorting pattern",
),
),
migrations.AlterField(
model_name="addonsconfig",
name="flyout_sorting_latest_stable_at_beginning",
field=models.BooleanField(
default=True,
verbose_name="Show <code>latest</code> and <code>stable</code> at the beginning",
),
),
migrations.AlterField(
model_name="historicaladdonsconfig",
name="flyout_sorting",
field=models.CharField(
choices=[
("alphabetically", "Alphabetically"),
("semver-readthedocs-compatible", "SemVer (Read the Docs)"),
("python-packaging", "Python Packaging (PEP 440 and PEP 425)"),
("calver", "CalVer (YYYY.0M.0M)"),
("custom-pattern", "Define your own pattern"),
],
default="semver-readthedocs-compatible",
max_length=64,
verbose_name="Sorting of versions",
),
),
migrations.AlterField(
model_name="historicaladdonsconfig",
name="flyout_sorting_custom_pattern",
field=models.CharField(
blank=True,
default=None,
help_text='Sorting pattern supported by BumpVer (<a href="https://github.com/mbarkhau/bumpver#pattern-examples">See examples</a>)',
max_length=32,
null=True,
verbose_name="Custom version sorting pattern",
),
),
migrations.AlterField(
model_name="historicaladdonsconfig",
name="flyout_sorting_latest_stable_at_beginning",
field=models.BooleanField(
default=True,
verbose_name="Show <code>latest</code> and <code>stable</code> at the beginning",
),
),
]
10 changes: 7 additions & 3 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
from readthedocs.vcs_support.backends import backend_cls

from .constants import (
ADDONS_FLYOUT_SORTING_ALPHABETICALLY,
ADDONS_FLYOUT_SORTING_CHOICES,
ADDONS_FLYOUT_SORTING_SEMVER_READTHEDOCS_COMPATIBLE,
DOWNLOADABLE_MEDIA_TYPES,
MEDIA_TYPES,
MULTIPLE_VERSIONS_WITH_TRANSLATIONS,
Expand Down Expand Up @@ -187,21 +187,25 @@ class AddonsConfig(TimeStampedModel):
# Flyout
flyout_enabled = models.BooleanField(default=True)
flyout_sorting = models.CharField(
verbose_name=_("Sorting of versions"),
choices=ADDONS_FLYOUT_SORTING_CHOICES,
default=ADDONS_FLYOUT_SORTING_ALPHABETICALLY,
default=ADDONS_FLYOUT_SORTING_SEMVER_READTHEDOCS_COMPATIBLE,
max_length=64,
)
flyout_sorting_custom_pattern = models.CharField(
max_length=32,
default=None,
null=True,
blank=True,
verbose_name=_("Custom version sorting pattern"),
help_text="Sorting pattern supported by BumpVer "
'(<a href="https://github.com/mbarkhau/bumpver#pattern-examples">See examples</a>)',
)
flyout_sorting_latest_stable_at_beginning = models.BooleanField(
verbose_name=_(
"Show <code>latest</code> and <code>stable</code> at the beginning"
),
default=True,
help_text="Show <code>latest</code> and <code>stable</code> at the beginning",
)

# Hotkeys
Expand Down
8 changes: 4 additions & 4 deletions readthedocs/proxito/tests/test_hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,15 +575,15 @@ def test_flyout_subproject_urls(self):
r.json()["versions"]["active"][0]["urls"]["documentation"]
== "https://project.dev.readthedocs.io/projects/subproject/en/latest/"
)
assert r.json()["versions"]["active"][1]["slug"] == "v1"
assert r.json()["versions"]["active"][1]["slug"] == "v2.3"
assert (
r.json()["versions"]["active"][1]["urls"]["documentation"]
== "https://project.dev.readthedocs.io/projects/subproject/en/v1/"
== "https://project.dev.readthedocs.io/projects/subproject/en/v2.3/"
)
assert r.json()["versions"]["active"][2]["slug"] == "v2.3"
assert r.json()["versions"]["active"][2]["slug"] == "v1"
assert (
r.json()["versions"]["active"][2]["urls"]["documentation"]
== "https://project.dev.readthedocs.io/projects/subproject/en/v2.3/"
== "https://project.dev.readthedocs.io/projects/subproject/en/v1/"
)

assert len(r.json()["projects"]["translations"]) == 1
Expand Down
1 change: 1 addition & 0 deletions readthedocs/proxito/views/hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ def _v1(self, project, version, build, filename, url, request):
version.verbose_name,
repo_type=project.repo_type,
),
reverse=True,
)
elif (
project.addons.flyout_sorting == ADDONS_FLYOUT_SORTING_PYTHON_PACKAGING
Expand Down

0 comments on commit 83f1617

Please sign in to comment.