Skip to content

Commit 919d10a

Browse files
committed
Addons: update form to show all the options
Add all the configuration options to the `AddonsConfigForm` so the user is able to enable/disable each of the addons independently. Closes readthedocs/ext-theme#211
1 parent 8f4d111 commit 919d10a

File tree

2 files changed

+86
-15
lines changed

2 files changed

+86
-15
lines changed

readthedocs/projects/forms.py

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,17 @@ class AddonsConfigForm(forms.ModelForm):
529529

530530
class Meta:
531531
model = AddonsConfig
532-
fields = ("enabled", "project")
532+
fields = (
533+
"enabled",
534+
"project",
535+
"analytics_enabled",
536+
"doc_diff_enabled",
537+
"external_version_warning_enabled",
538+
"flyout_enabled",
539+
"hotkeys_enabled",
540+
"search_enabled",
541+
"stable_latest_version_warning_enabled",
542+
)
533543

534544
def __init__(self, *args, **kwargs):
535545
self.project = kwargs.pop("project", None)
@@ -541,6 +551,72 @@ def __init__(self, *args, **kwargs):
541551
except AddonsConfig.DoesNotExist:
542552
self.fields["enabled"].initial = False
543553

554+
fieldsets = [
555+
Fieldset(
556+
_("Global"),
557+
"enabled",
558+
),
559+
Fieldset(
560+
_("Analytics"),
561+
HTML(
562+
"<p>Analytics addon allows you to store traffic analytics in your project.</p>"
563+
),
564+
*[field for field in self.fields if field.startswith("analytics_")],
565+
),
566+
Fieldset(
567+
_("DocDiff"),
568+
HTML(
569+
"<p>DocDicc addon helps you to review changes from PR by visually showing the differences.</p>"
570+
),
571+
*[field for field in self.fields if field.startswith("doc_diff_")],
572+
),
573+
Fieldset(
574+
_("Flyout"),
575+
HTML(
576+
"<p>Flyout addon shows a small menu at bottom-right of each page with useful links to switch between versions and translations.</p>"
577+
),
578+
*[field for field in self.fields if field.startswith("flyout_")],
579+
),
580+
Fieldset(
581+
_("Hotkeys"),
582+
HTML(
583+
"<p>Hotkeys addon enables keyboard shortcuts to access other addons quickly.</p>"
584+
),
585+
*[field for field in self.fields if field.startswith("hotkeys_")],
586+
),
587+
Fieldset(
588+
_("Search"),
589+
HTML(
590+
"<p>Search addon improves your search experience with the search-as-you-type feature.</p>"
591+
),
592+
*[field for field in self.fields if field.startswith("search_")],
593+
),
594+
Fieldset(
595+
_("Warning on PR previews"),
596+
HTML("<p>Shows a warning notification on PR previews.</p>"),
597+
*[
598+
field
599+
for field in self.fields
600+
if field.startswith("external_version_warning_")
601+
],
602+
),
603+
Fieldset(
604+
_("Warning on non-stable/latest versions"),
605+
HTML(
606+
"<p>Shows a warning notification stable and latest versions letting the user know they may be reading an outdated page or a non-released one.</p>"
607+
),
608+
*[
609+
field
610+
for field in self.fields
611+
if field.startswith("stable_latest_version_warning_")
612+
],
613+
),
614+
]
615+
616+
self.helper = FormHelper()
617+
self.helper.layout = Layout(*fieldsets)
618+
self.helper.add_input(Submit("save", _("Save")))
619+
544620
def clean_project(self):
545621
return self.project
546622

readthedocs/proxito/views/hosting.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from readthedocs.core.resolver import Resolver
2424
from readthedocs.core.unresolver import UnresolverError, unresolver
2525
from readthedocs.core.utils.extend import SettingsOverrideObject
26-
from readthedocs.projects.models import Feature, Project
26+
from readthedocs.projects.models import Project
2727

2828
log = structlog.get_logger(__name__) # noqa
2929

@@ -320,24 +320,21 @@ def _v0(self, project, version, build, filename, url, user):
320320
# serializer than the keys ``project``, ``version`` and ``build`` from the top level.
321321
"addons": {
322322
"analytics": {
323-
"enabled": Feature.ADDONS_ANALYTICS_DISABLED
324-
not in project_features,
323+
"enabled": project.addons.analytics_enabled,
325324
# TODO: consider adding this field into the ProjectSerializer itself.
326325
# NOTE: it seems we are removing this feature,
327326
# so we may not need the ``code`` attribute here
328327
# https://github.com/readthedocs/readthedocs.org/issues/9530
329328
"code": project.analytics_code,
330329
},
331330
"external_version_warning": {
332-
"enabled": Feature.ADDONS_EXTERNAL_VERSION_WARNING_DISABLED
333-
not in project_features,
331+
"enabled": project.addons.external_version_warning_enabled,
334332
# NOTE: I think we are moving away from these selectors
335333
# since we are doing floating noticications now.
336334
# "query_selector": "[role=main]",
337335
},
338336
"non_latest_version_warning": {
339-
"enabled": Feature.ADDONS_NON_LATEST_VERSION_WARNING_DISABLED
340-
not in project_features,
337+
"enabled": project.addons.stable_latest_version_warning_enabled,
341338
# NOTE: I think we are moving away from these selectors
342339
# since we are doing floating noticications now.
343340
# "query_selector": "[role=main]",
@@ -346,7 +343,7 @@ def _v0(self, project, version, build, filename, url, user):
346343
),
347344
},
348345
"flyout": {
349-
"enabled": Feature.ADDONS_FLYOUT_DISABLED not in project_features,
346+
"enabled": project.addons.flyout_enabled,
350347
"translations": [
351348
{
352349
# TODO: name this field "display_name"
@@ -398,7 +395,7 @@ def _v0(self, project, version, build, filename, url, user):
398395
# },
399396
},
400397
"search": {
401-
"enabled": Feature.ADDONS_SEARCH_DISABLED not in project_features,
398+
"enabled": project.addons.search_enabled,
402399
"project": project.slug,
403400
"version": version.slug if version else None,
404401
"api_endpoint": "/_/api/v3/search/",
@@ -416,7 +413,7 @@ def _v0(self, project, version, build, filename, url, user):
416413
else None,
417414
},
418415
"hotkeys": {
419-
"enabled": Feature.ADDONS_HOTKEYS_DISABLED not in project_features,
416+
"enabled": project.addons.hotkeys_enabled,
420417
"doc_diff": {
421418
"enabled": True,
422419
"trigger": "KeyD", # Could be something like "Ctrl + D"
@@ -437,8 +434,7 @@ def _v0(self, project, version, build, filename, url, user):
437434
data["addons"].update(
438435
{
439436
"doc_diff": {
440-
"enabled": Feature.ADDONS_DOC_DIFF_DISABLED
441-
not in project_features,
437+
"enabled": project.addons.doc_diff_enabled,
442438
# "http://test-builds-local.devthedocs.org/en/latest/index.html"
443439
"base_url": resolver.resolve(
444440
project=project,
@@ -478,8 +474,7 @@ def _v0(self, project, version, build, filename, url, user):
478474
data["addons"].update(
479475
{
480476
"ethicalads": {
481-
"enabled": Feature.ADDONS_ETHICALADS_DISABLED
482-
not in project_features,
477+
"enabled": project.addons.ethicalads_enabled,
483478
# NOTE: this endpoint is not authenticated, the user checks are done over an annonymous user for now
484479
#
485480
# NOTE: it requires ``settings.USE_PROMOS=True`` to return ``ad_free=false`` here

0 commit comments

Comments
 (0)