Skip to content

Commit 83f1617

Browse files
authored
Addons: default to semver for sorting versions (#11686)
1 parent 2ed3727 commit 83f1617

File tree

4 files changed

+97
-7
lines changed

4 files changed

+97
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Generated by Django 4.2.16 on 2024-10-15 16:07
2+
from django.db import migrations, models
3+
from django_safemigrate import Safe
4+
5+
6+
class Migration(migrations.Migration):
7+
safe = Safe.always
8+
dependencies = [
9+
("projects", "0126_alter_remote_repository_description"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="addonsconfig",
15+
name="flyout_sorting",
16+
field=models.CharField(
17+
choices=[
18+
("alphabetically", "Alphabetically"),
19+
("semver-readthedocs-compatible", "SemVer (Read the Docs)"),
20+
("python-packaging", "Python Packaging (PEP 440 and PEP 425)"),
21+
("calver", "CalVer (YYYY.0M.0M)"),
22+
("custom-pattern", "Define your own pattern"),
23+
],
24+
default="semver-readthedocs-compatible",
25+
max_length=64,
26+
verbose_name="Sorting of versions",
27+
),
28+
),
29+
migrations.AlterField(
30+
model_name="addonsconfig",
31+
name="flyout_sorting_custom_pattern",
32+
field=models.CharField(
33+
blank=True,
34+
default=None,
35+
help_text='Sorting pattern supported by BumpVer (<a href="https://github.com/mbarkhau/bumpver#pattern-examples">See examples</a>)',
36+
max_length=32,
37+
null=True,
38+
verbose_name="Custom version sorting pattern",
39+
),
40+
),
41+
migrations.AlterField(
42+
model_name="addonsconfig",
43+
name="flyout_sorting_latest_stable_at_beginning",
44+
field=models.BooleanField(
45+
default=True,
46+
verbose_name="Show <code>latest</code> and <code>stable</code> at the beginning",
47+
),
48+
),
49+
migrations.AlterField(
50+
model_name="historicaladdonsconfig",
51+
name="flyout_sorting",
52+
field=models.CharField(
53+
choices=[
54+
("alphabetically", "Alphabetically"),
55+
("semver-readthedocs-compatible", "SemVer (Read the Docs)"),
56+
("python-packaging", "Python Packaging (PEP 440 and PEP 425)"),
57+
("calver", "CalVer (YYYY.0M.0M)"),
58+
("custom-pattern", "Define your own pattern"),
59+
],
60+
default="semver-readthedocs-compatible",
61+
max_length=64,
62+
verbose_name="Sorting of versions",
63+
),
64+
),
65+
migrations.AlterField(
66+
model_name="historicaladdonsconfig",
67+
name="flyout_sorting_custom_pattern",
68+
field=models.CharField(
69+
blank=True,
70+
default=None,
71+
help_text='Sorting pattern supported by BumpVer (<a href="https://github.com/mbarkhau/bumpver#pattern-examples">See examples</a>)',
72+
max_length=32,
73+
null=True,
74+
verbose_name="Custom version sorting pattern",
75+
),
76+
),
77+
migrations.AlterField(
78+
model_name="historicaladdonsconfig",
79+
name="flyout_sorting_latest_stable_at_beginning",
80+
field=models.BooleanField(
81+
default=True,
82+
verbose_name="Show <code>latest</code> and <code>stable</code> at the beginning",
83+
),
84+
),
85+
]

readthedocs/projects/models.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
from readthedocs.vcs_support.backends import backend_cls
6363

6464
from .constants import (
65-
ADDONS_FLYOUT_SORTING_ALPHABETICALLY,
6665
ADDONS_FLYOUT_SORTING_CHOICES,
66+
ADDONS_FLYOUT_SORTING_SEMVER_READTHEDOCS_COMPATIBLE,
6767
DOWNLOADABLE_MEDIA_TYPES,
6868
MEDIA_TYPES,
6969
MULTIPLE_VERSIONS_WITH_TRANSLATIONS,
@@ -187,21 +187,25 @@ class AddonsConfig(TimeStampedModel):
187187
# Flyout
188188
flyout_enabled = models.BooleanField(default=True)
189189
flyout_sorting = models.CharField(
190+
verbose_name=_("Sorting of versions"),
190191
choices=ADDONS_FLYOUT_SORTING_CHOICES,
191-
default=ADDONS_FLYOUT_SORTING_ALPHABETICALLY,
192+
default=ADDONS_FLYOUT_SORTING_SEMVER_READTHEDOCS_COMPATIBLE,
192193
max_length=64,
193194
)
194195
flyout_sorting_custom_pattern = models.CharField(
195196
max_length=32,
196197
default=None,
197198
null=True,
198199
blank=True,
200+
verbose_name=_("Custom version sorting pattern"),
199201
help_text="Sorting pattern supported by BumpVer "
200202
'(<a href="https://github.com/mbarkhau/bumpver#pattern-examples">See examples</a>)',
201203
)
202204
flyout_sorting_latest_stable_at_beginning = models.BooleanField(
205+
verbose_name=_(
206+
"Show <code>latest</code> and <code>stable</code> at the beginning"
207+
),
203208
default=True,
204-
help_text="Show <code>latest</code> and <code>stable</code> at the beginning",
205209
)
206210

207211
# Hotkeys

readthedocs/proxito/tests/test_hosting.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -575,15 +575,15 @@ def test_flyout_subproject_urls(self):
575575
r.json()["versions"]["active"][0]["urls"]["documentation"]
576576
== "https://project.dev.readthedocs.io/projects/subproject/en/latest/"
577577
)
578-
assert r.json()["versions"]["active"][1]["slug"] == "v1"
578+
assert r.json()["versions"]["active"][1]["slug"] == "v2.3"
579579
assert (
580580
r.json()["versions"]["active"][1]["urls"]["documentation"]
581-
== "https://project.dev.readthedocs.io/projects/subproject/en/v1/"
581+
== "https://project.dev.readthedocs.io/projects/subproject/en/v2.3/"
582582
)
583-
assert r.json()["versions"]["active"][2]["slug"] == "v2.3"
583+
assert r.json()["versions"]["active"][2]["slug"] == "v1"
584584
assert (
585585
r.json()["versions"]["active"][2]["urls"]["documentation"]
586-
== "https://project.dev.readthedocs.io/projects/subproject/en/v2.3/"
586+
== "https://project.dev.readthedocs.io/projects/subproject/en/v1/"
587587
)
588588

589589
assert len(r.json()["projects"]["translations"]) == 1

readthedocs/proxito/views/hosting.py

+1
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ def _v1(self, project, version, build, filename, url, request):
350350
version.verbose_name,
351351
repo_type=project.repo_type,
352352
),
353+
reverse=True,
353354
)
354355
elif (
355356
project.addons.flyout_sorting == ADDONS_FLYOUT_SORTING_PYTHON_PACKAGING

0 commit comments

Comments
 (0)