Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow extend Translation and Subproject form logic from corporate #3937

Merged
merged 2 commits into from
Apr 12, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from __future__ import (
absolute_import, division, print_function, unicode_literals)

from builtins import object
from random import choice

from builtins import object
from django import forms
from django.conf import settings
from django.contrib.auth.models import User
Expand All @@ -19,6 +19,7 @@

from readthedocs.builds.constants import TAG
from readthedocs.core.utils import slugify, trigger_build
from readthedocs.core.utils.extend import SettingsOverrideObject
from readthedocs.integrations.models import Integration
from readthedocs.oauth.models import RemoteRepository
from readthedocs.projects import constants
Expand Down Expand Up @@ -230,7 +231,7 @@ class Meta(object):
)


class ProjectRelationshipForm(forms.ModelForm):
class ProjectRelationshipBaseForm(forms.ModelForm):

"""Form to add/update project relationships."""

Expand All @@ -243,7 +244,7 @@ class Meta(object):
def __init__(self, *args, **kwargs):
self.project = kwargs.pop('project')
self.user = kwargs.pop('user')
super(ProjectRelationshipForm, self).__init__(*args, **kwargs)
super(ProjectRelationshipBaseForm, self).__init__(*args, **kwargs)
# Don't display the update form with an editable child, as it will be
# filtered out from the queryset anyways.
if hasattr(self, 'instance') and self.instance.pk is not None:
Expand Down Expand Up @@ -281,6 +282,11 @@ def get_subproject_queryset(self):
return queryset


class ProjectRelationshipForm(SettingsOverrideObject):
_default_class = ProjectRelationshipBaseForm
_override_setting = 'PROJECT_RELATIONSHIP_FORM'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use individual settings anymore, this is legacy. See the override classes setting instead.



class DualCheckboxWidget(forms.CheckboxInput):

"""Checkbox with link to the version's built documentation."""
Expand Down Expand Up @@ -481,7 +487,7 @@ def save(self):
return self.project


class TranslationForm(forms.Form):
class TranslationBaseForm(forms.Form):

"""Project translation form."""

Expand All @@ -490,7 +496,7 @@ class TranslationForm(forms.Form):
def __init__(self, *args, **kwargs):
self.parent = kwargs.pop('parent', None)
self.user = kwargs.pop('user')
super(TranslationForm, self).__init__(*args, **kwargs)
super(TranslationBaseForm, self).__init__(*args, **kwargs)
self.fields['project'].choices = self.get_choices()

def get_choices(self):
Expand Down Expand Up @@ -563,6 +569,11 @@ def save(self):
return project


class TranslationForm(SettingsOverrideObject):
_default_class = TranslationBaseForm
_override_setting = 'PROJECT_TRANSLATION_FORM'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here



class RedirectForm(forms.ModelForm):

"""Form for project redirects."""
Expand Down