diff --git a/readthedocs/projects/forms.py b/readthedocs/projects/forms.py index 74ee3d15f5d..21e567f275a 100644 --- a/readthedocs/projects/forms.py +++ b/readthedocs/projects/forms.py @@ -1,11 +1,10 @@ -# -*- coding: utf-8 -*- - """Project forms.""" - from random import choice from re import fullmatch from urllib.parse import urlparse +from crispy_forms.helper import FormHelper +from crispy_forms.layout import Fieldset, Layout, HTML from django import forms from django.conf import settings from django.contrib.auth.models import User @@ -22,7 +21,6 @@ from readthedocs.oauth.models import RemoteRepository from readthedocs.projects import constants from readthedocs.projects.exceptions import ProjectSpamError -from readthedocs.projects.templatetags.projects_tags import sort_version_aware from readthedocs.projects.models import ( Domain, EmailHook, @@ -32,6 +30,7 @@ ProjectRelationship, WebHook, ) +from readthedocs.projects.templatetags.projects_tags import sort_version_aware from readthedocs.redirects.models import Redirect @@ -196,27 +195,18 @@ class ProjectAdvancedForm(ProjectTriggerBuildMixin, ProjectForm): """Advanced project option form.""" - python_interpreter = forms.ChoiceField( - choices=constants.PYTHON_CHOICES, - initial='python', - help_text=_( - 'The Python interpreter used to create the virtual ' - 'environment.', - ), - ) - class Meta: model = Project - fields = ( - # Global settings. + per_project_settings = ( 'default_version', 'default_branch', 'privacy_level', 'analytics_code', 'show_version_warning', 'single_version', - - # Options that can be set per-version using a config file. + ) + # These that can be set per-version using a config file. + per_version_settings = ( 'documentation_type', 'requirements_file', 'python_interpreter', @@ -226,10 +216,30 @@ class Meta: 'enable_pdf_build', 'enable_epub_build', ) + fields = ( + *per_project_settings, + *per_version_settings, + ) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + self.helper = FormHelper() + help_text = render_to_string( + 'projects/project_advanced_settings_helptext.html' + ) + self.helper.layout = Layout( + Fieldset( + _("Global settings"), + *self.Meta.per_project_settings, + ), + Fieldset( + _("Default settings"), + HTML(help_text), + *self.Meta.per_version_settings, + ), + ) + default_choice = (None, '-' * 9) all_versions = self.instance.versions.values_list( 'identifier', diff --git a/readthedocs/settings/base.py b/readthedocs/settings/base.py index 6dfab8020c0..3cf62523d59 100644 --- a/readthedocs/settings/base.py +++ b/readthedocs/settings/base.py @@ -84,6 +84,7 @@ def INSTALLED_APPS(self): # noqa 'textclassifier', 'annoying', 'django_extensions', + 'crispy_forms', 'messages_extends', 'django_elasticsearch_dsl', diff --git a/readthedocs/templates/projects/project_advanced.html b/readthedocs/templates/projects/project_advanced.html index 2ac96549e9d..2c946fdbed3 100644 --- a/readthedocs/templates/projects/project_advanced.html +++ b/readthedocs/templates/projects/project_advanced.html @@ -1,5 +1,6 @@ {% extends "projects/project_edit_base.html" %} {% load i18n %} +{% load crispy_forms_tags %} {% block project-advanced-active %}active{% endblock %} {% block nav-dashboard %} class="active"{% endblock %} @@ -13,7 +14,7 @@ {% block project_edit_content %}
{% csrf_token %} - {{ form.as_p }} + {% crispy form %}

diff --git a/readthedocs/templates/projects/project_advanced_settings_helptext.html b/readthedocs/templates/projects/project_advanced_settings_helptext.html new file mode 100644 index 00000000000..d5d7909ca03 --- /dev/null +++ b/readthedocs/templates/projects/project_advanced_settings_helptext.html @@ -0,0 +1,10 @@ +{% load i18n %} +

+ {% blocktrans trimmed with config_file_link="https://docs.readthedocs.io/page/config-file/v2.html" %} + These settings can be configured using a + configuration file. + That's the recommended way to set up your project. + Settings in the configuration + file override the settings listed here. + {% endblocktrans %} +

diff --git a/requirements/pip.txt b/requirements/pip.txt index 8c43c0528aa..2dd4f2f1603 100644 --- a/requirements/pip.txt +++ b/requirements/pip.txt @@ -73,6 +73,7 @@ stripe==2.22.0 git+https://github.com/mozilla/unicode-slugify@b696c37#egg=unicode-slugify django-formtools==2.1 +django-crispy-forms==1.7.2 # docker is pinned to 3.1.3 because we found some strange behavior # related to timeouts on EXEC with 3.2.1 and 3.3.0 that's not present