Skip to content

Commit

Permalink
Merge pull request #5489 from stsewd/use-crispy-forms-advanced-settings
Browse files Browse the repository at this point in the history
Regroup advanced settings
  • Loading branch information
stsewd authored Mar 22, 2019
2 parents 5b8320b + 746fd52 commit 44951fb
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 18 deletions.
44 changes: 27 additions & 17 deletions readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand All @@ -32,6 +30,7 @@
ProjectRelationship,
WebHook,
)
from readthedocs.projects.templatetags.projects_tags import sort_version_aware
from readthedocs.redirects.models import Redirect


Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down
1 change: 1 addition & 0 deletions readthedocs/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def INSTALLED_APPS(self): # noqa
'textclassifier',
'annoying',
'django_extensions',
'crispy_forms',
'messages_extends',
'django_elasticsearch_dsl',

Expand Down
3 changes: 2 additions & 1 deletion readthedocs/templates/projects/project_advanced.html
Original file line number Diff line number Diff line change
@@ -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 %}
Expand All @@ -13,7 +14,7 @@

{% block project_edit_content %}
<form method="post" action=".">{% csrf_token %}
{{ form.as_p }}
{% crispy form %}
<p>
<input style="display: inline;" type="submit" value="{% trans "Save" %}">
</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% load i18n %}
<p class="empty">
{% blocktrans trimmed with config_file_link="https://docs.readthedocs.io/page/config-file/v2.html" %}
These settings can be configured using a
<a href="{{ config_file_link }}">configuration file</a>.
That's the recommended way to set up your project.
Settings in the configuration
file override the settings listed here.
{% endblocktrans %}
</p>
1 change: 1 addition & 0 deletions requirements/pip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 44951fb

Please sign in to comment.