From c3cd2db384d3e19f2b4702121d1a8544064e3396 Mon Sep 17 00:00:00 2001 From: muzaffaryousaf Date: Thu, 31 Mar 2016 16:02:24 +0500 Subject: [PATCH] Moving choices to admin form instead of models. TNL-4296 --- common/djangoapps/third_party_auth/admin.py | 18 +++++++++++++- .../migrations/0002_auto_20160325_0407.py | 24 ------------------- common/djangoapps/third_party_auth/models.py | 4 ++-- 3 files changed, 19 insertions(+), 27 deletions(-) delete mode 100644 common/djangoapps/third_party_auth/migrations/0002_auto_20160325_0407.py diff --git a/common/djangoapps/third_party_auth/admin.py b/common/djangoapps/third_party_auth/admin.py index 3491be6eee..5d29c08246 100644 --- a/common/djangoapps/third_party_auth/admin.py +++ b/common/djangoapps/third_party_auth/admin.py @@ -13,14 +13,23 @@ from .models import ( SAMLConfiguration, SAMLProviderData, LTIProviderConfig, - ProviderApiPermissions + ProviderApiPermissions, + _PSA_OAUTH2_BACKENDS, + _PSA_SAML_BACKENDS ) from .tasks import fetch_saml_metadata from third_party_auth.provider import Registry +class OAuth2ProviderConfigForm(forms.ModelForm): + """ Django Admin form class for OAuth2ProviderConfig """ + backend_name = forms.ChoiceField(choices=((name, name) for name in _PSA_OAUTH2_BACKENDS)) + + class OAuth2ProviderConfigAdmin(KeyedConfigurationModelAdmin): """ Django Admin class for OAuth2ProviderConfig """ + form = OAuth2ProviderConfigForm + def get_list_display(self, request): """ Don't show every single field in the admin change list """ return ( @@ -31,8 +40,15 @@ class OAuth2ProviderConfigAdmin(KeyedConfigurationModelAdmin): admin.site.register(OAuth2ProviderConfig, OAuth2ProviderConfigAdmin) +class SAMLProviderConfigForm(forms.ModelForm): + """ Django Admin form class for SAMLProviderConfig """ + backend_name = forms.ChoiceField(choices=((name, name) for name in _PSA_SAML_BACKENDS)) + + class SAMLProviderConfigAdmin(KeyedConfigurationModelAdmin): """ Django Admin class for SAMLProviderConfig """ + form = SAMLProviderConfigForm + def get_list_display(self, request): """ Don't show every single field in the admin change list """ return ( diff --git a/common/djangoapps/third_party_auth/migrations/0002_auto_20160325_0407.py b/common/djangoapps/third_party_auth/migrations/0002_auto_20160325_0407.py deleted file mode 100644 index d697b75126..0000000000 --- a/common/djangoapps/third_party_auth/migrations/0002_auto_20160325_0407.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('third_party_auth', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='oauth2providerconfig', - name='backend_name', - field=models.CharField(help_text=b'Which python-social-auth OAuth2 provider backend to use. The list of backend choices is determined by the THIRD_PARTY_AUTH_BACKENDS setting.', max_length=50, db_index=True, choices=[(b'google-oauth2', b'google-oauth2'), (b'linkedin-oauth2', b'linkedin-oauth2'), (b'facebook', b'facebook'), (b'twitter', b'twitter'), (b'dummy', b'dummy')]), - ), - migrations.AlterField( - model_name='samlproviderconfig', - name='backend_name', - field=models.CharField(default=b'tpa-saml', help_text=b"Which python-social-auth provider backend to use. 'tpa-saml' is the standard edX SAML backend.", max_length=50, choices=[(b'tpa-saml', b'tpa-saml')]), - ), - ] diff --git a/common/djangoapps/third_party_auth/models.py b/common/djangoapps/third_party_auth/models.py index 5200a92b71..ce76ef20c5 100644 --- a/common/djangoapps/third_party_auth/models.py +++ b/common/djangoapps/third_party_auth/models.py @@ -212,7 +212,7 @@ class OAuth2ProviderConfig(ProviderConfig): prefix = 'oa2' KEY_FIELDS = ('backend_name', ) # Backend name is unique backend_name = models.CharField( - max_length=50, choices=[(name, name) for name in _PSA_OAUTH2_BACKENDS], blank=False, db_index=True, + max_length=50, blank=False, db_index=True, help_text=( "Which python-social-auth OAuth2 provider backend to use. " "The list of backend choices is determined by the THIRD_PARTY_AUTH_BACKENDS setting." @@ -265,7 +265,7 @@ class SAMLProviderConfig(ProviderConfig): prefix = 'saml' KEY_FIELDS = ('idp_slug', ) backend_name = models.CharField( - max_length=50, default='tpa-saml', choices=[(name, name) for name in _PSA_SAML_BACKENDS], blank=False, + max_length=50, default='tpa-saml', blank=False, help_text="Which python-social-auth provider backend to use. 'tpa-saml' is the standard edX SAML backend.") idp_slug = models.SlugField( max_length=30, db_index=True,