Skip to content

Commit e70cf31

Browse files
authored
Addons: allow to set a "Default" or a explicit position for flyout (#11891)
- Add a new `flyout_position` field to the `AddonsConfig` model - Show the field in the form - Return the field in the APIv3 to be consumed by the frontend ---- * Related readthedocs/addons#434
1 parent e7afae1 commit e70cf31

File tree

6 files changed

+65
-2
lines changed

6 files changed

+65
-2
lines changed

readthedocs/projects/constants.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,3 +443,15 @@
443443
(ADDONS_FLYOUT_SORTING_CALVER, _("CalVer (YYYY.0M.0M)")),
444444
(ADDONS_FLYOUT_SORTING_CUSTOM_PATTERN, _("Define your own pattern")),
445445
)
446+
447+
ADDONS_FLYOUT_POSITION_BOTTOM_LEFT = "bottom-left"
448+
ADDONS_FLYOUT_POSITION_BOTTOM_RIGHT = "bottom-right"
449+
ADDONS_FLYOUT_POSITION_TOP_LEFT = "top-left"
450+
ADDONS_FLYOUT_POSITION_TOP_RIGHT = "top-right"
451+
ADDONS_FLYOUT_POSITION_CHOICES = (
452+
(None, _("Default (from theme or Read the Docs)")),
453+
(ADDONS_FLYOUT_POSITION_BOTTOM_LEFT, _("Bottom left")),
454+
(ADDONS_FLYOUT_POSITION_BOTTOM_RIGHT, _("Bottom right")),
455+
(ADDONS_FLYOUT_POSITION_TOP_LEFT, _("Top left")),
456+
(ADDONS_FLYOUT_POSITION_TOP_RIGHT, _("Top right")),
457+
)

readthedocs/projects/forms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ class Meta:
657657
"flyout_sorting",
658658
"flyout_sorting_latest_stable_at_beginning",
659659
"flyout_sorting_custom_pattern",
660+
"flyout_position",
660661
"hotkeys_enabled",
661662
"search_enabled",
662663
"linkpreviews_enabled",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Generated by Django 4.2.17 on 2025-01-08 11:15
2+
3+
from django.db import migrations, models
4+
from django_safemigrate import Safe
5+
6+
7+
class Migration(migrations.Migration):
8+
safe = Safe.before_deploy
9+
10+
dependencies = [
11+
('projects', '0142_update_dj_simple_history'),
12+
]
13+
14+
operations = [
15+
migrations.AlterField(
16+
model_name='addonsconfig',
17+
name='flyout_enabled',
18+
field=models.BooleanField(default=True, verbose_name='Enabled'),
19+
),
20+
migrations.AddField(
21+
model_name='addonsconfig',
22+
name='flyout_position',
23+
field=models.CharField(blank=True, choices=[(None, 'Default (from theme or Read the Docs)'), ('bottom-left', 'Bottom left'), ('bottom-right', 'Bottom right'), ('top-left', 'Top left'), ('top-right', 'Top right')], default=None, max_length=64, null=True, verbose_name='Position'),
24+
),
25+
migrations.AlterField(
26+
model_name='historicaladdonsconfig',
27+
name='flyout_enabled',
28+
field=models.BooleanField(default=True, verbose_name='Enabled'),
29+
),
30+
migrations.AddField(
31+
model_name='historicaladdonsconfig',
32+
name='flyout_position',
33+
field=models.CharField(blank=True, choices=[(None, 'Default (from theme or Read the Docs)'), ('bottom-left', 'Bottom left'), ('bottom-right', 'Bottom right'), ('top-left', 'Top left'), ('top-right', 'Top right')], default=None, max_length=64, null=True, verbose_name='Position'),
34+
),
35+
]

readthedocs/projects/models.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
from readthedocs.vcs_support.backends import backend_cls
6262

6363
from .constants import (
64+
ADDONS_FLYOUT_POSITION_CHOICES,
6465
ADDONS_FLYOUT_SORTING_CHOICES,
6566
ADDONS_FLYOUT_SORTING_SEMVER_READTHEDOCS_COMPATIBLE,
6667
DOWNLOADABLE_MEDIA_TYPES,
@@ -194,7 +195,10 @@ class AddonsConfig(TimeStampedModel):
194195
filetreediff_enabled = models.BooleanField(default=False, null=True, blank=True)
195196

196197
# Flyout
197-
flyout_enabled = models.BooleanField(default=True)
198+
flyout_enabled = models.BooleanField(
199+
default=True,
200+
verbose_name=_("Enabled"),
201+
)
198202
flyout_sorting = models.CharField(
199203
verbose_name=_("Sorting of versions"),
200204
choices=ADDONS_FLYOUT_SORTING_CHOICES,
@@ -217,6 +221,15 @@ class AddonsConfig(TimeStampedModel):
217221
default=True,
218222
)
219223

224+
flyout_position = models.CharField(
225+
choices=ADDONS_FLYOUT_POSITION_CHOICES,
226+
max_length=64,
227+
default=None, # ``None`` means use the default (theme override if present or Read the Docs default)
228+
null=True,
229+
blank=True,
230+
verbose_name=_("Position"),
231+
)
232+
220233
# Hotkeys
221234
hotkeys_enabled = models.BooleanField(default=True)
222235

readthedocs/proxito/tests/responses/v1.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@
155155
"enabled": false
156156
},
157157
"flyout": {
158-
"enabled": true
158+
"enabled": true,
159+
"position": null
159160
},
160161
"search": {
161162
"enabled": true,

readthedocs/proxito/views/hosting.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ def _v1(self, project, version, build, filename, url, request):
493493
# "branch": version.identifier if version else None,
494494
# "filepath": "/docs/index.rst",
495495
# },
496+
"position": project.addons.flyout_position,
496497
},
497498
"customscript": {
498499
"enabled": project.addons.customscript_enabled,

0 commit comments

Comments
 (0)