From 8ea3b620168d3a937745dc931485a257c161fff1 Mon Sep 17 00:00:00 2001 From: Clinton Blackburn Date: Tue, 31 May 2016 18:22:18 -0400 Subject: [PATCH] Added admin for UserAttribute model (#12596) ECOM-4502 --- common/djangoapps/student/admin.py | 28 +++++++++++-------- .../migrations/0005_auto_20160531_1653.py | 19 +++++++++++++ common/djangoapps/student/models.py | 4 +-- 3 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 common/djangoapps/student/migrations/0005_auto_20160531_1653.py diff --git a/common/djangoapps/student/admin.py b/common/djangoapps/student/admin.py index eea1daa72f..46dd3fa03e 100644 --- a/common/djangoapps/student/admin.py +++ b/common/djangoapps/student/admin.py @@ -11,7 +11,7 @@ from xmodule.modulestore.django import modulestore from config_models.admin import ConfigurationModelAdmin from student.models import ( UserProfile, UserTestGroup, CourseEnrollmentAllowed, DashboardConfiguration, CourseEnrollment, Registration, - PendingNameChange, CourseAccessRole, LinkedInAddToProfileConfiguration + PendingNameChange, CourseAccessRole, LinkedInAddToProfileConfiguration, UserAttribute ) from student.roles import REGISTERED_ACCESS_ROLES @@ -103,6 +103,7 @@ class CourseAccessRoleForm(forms.ModelForm): self.fields['email'].initial = self.instance.user.email +@admin.register(CourseAccessRole) class CourseAccessRoleAdmin(admin.ModelAdmin): """Admin panel for the Course Access Role. """ form = CourseAccessRoleForm @@ -127,6 +128,7 @@ class CourseAccessRoleAdmin(admin.ModelAdmin): super(CourseAccessRoleAdmin, self).save_model(request, obj, form, change) +@admin.register(LinkedInAddToProfileConfiguration) class LinkedInAddToProfileConfigurationAdmin(admin.ModelAdmin): """Admin interface for the LinkedIn Add to Profile configuration. """ @@ -137,6 +139,7 @@ class LinkedInAddToProfileConfigurationAdmin(admin.ModelAdmin): exclude = ('dashboard_tracking_code',) +@admin.register(CourseEnrollment) class CourseEnrollmentAdmin(admin.ModelAdmin): """ Admin interface for the CourseEnrollment model. """ list_display = ('id', 'course_id', 'mode', 'user', 'is_active',) @@ -163,20 +166,23 @@ class UserAdmin(BaseUserAdmin): inlines = (UserProfileInline,) +@admin.register(UserAttribute) +class UserAttributeAdmin(admin.ModelAdmin): + """ Admin interface for the UserAttribute model. """ + list_display = ('user', 'name', 'value',) + list_filter = ('name',) + raw_id_fields = ('user',) + search_fields = ('name', 'value', 'user__username',) + + class Meta(object): + model = UserAttribute + + admin.site.register(UserTestGroup) - admin.site.register(CourseEnrollmentAllowed) - admin.site.register(Registration) - admin.site.register(PendingNameChange) - -admin.site.register(CourseAccessRole, CourseAccessRoleAdmin) - admin.site.register(DashboardConfiguration, ConfigurationModelAdmin) -admin.site.register(LinkedInAddToProfileConfiguration, LinkedInAddToProfileConfigurationAdmin) - -admin.site.register(CourseEnrollment, CourseEnrollmentAdmin) - +# We must first un-register the User model since it may also be registered by the auth app. admin.site.register(User, UserAdmin) diff --git a/common/djangoapps/student/migrations/0005_auto_20160531_1653.py b/common/djangoapps/student/migrations/0005_auto_20160531_1653.py new file mode 100644 index 0000000000..0ad3e17360 --- /dev/null +++ b/common/djangoapps/student/migrations/0005_auto_20160531_1653.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('student', '0004_auto_20160531_1422'), + ] + + operations = [ + migrations.AlterField( + model_name='userattribute', + name='name', + field=models.CharField(help_text='Name of this user attribute.', max_length=255, db_index=True), + ), + ] diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index 80d3c535c1..556f987824 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -2164,10 +2164,10 @@ class UserAttribute(TimeStampedModel): class Meta(object): # Ensure that at most one value exists for a given user/name. - unique_together = (('user', 'name')) + unique_together = (('user', 'name',), ) user = models.ForeignKey(User, related_name='attributes') - name = models.CharField(max_length=255, help_text=_("Name of this user attribute.")) + name = models.CharField(max_length=255, help_text=_("Name of this user attribute."), db_index=True) value = models.CharField(max_length=255, help_text=_("Value of this user attribute.")) def __unicode__(self):