├── custom_reg_form ├── __init__.py ├── migrations │ ├── __init__.py │ └── 0001_initial.py ├── tests.py ├── admin.py ├── forms.py └── models.py ├── .gitignore ├── README.md └── setup.py /custom_reg_form/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /custom_reg_form/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | custom_form_app.egg-info/* 2 | *.pyc 3 | -------------------------------------------------------------------------------- /custom_reg_form/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /custom_reg_form/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import ExtraInfo 3 | 4 | admin.site.register(ExtraInfo) 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # To Use: 2 | 3 | 1. Install with `pip install -e .` within this folder within the edx platform virtual environment. 4 | 2. Add "custom_reg_form" to the "ADDL_INSTALLED_APPS" array in `lms.env.json` (you may have to create it if it doesn't exist.) 5 | 3. Set "REGISTRATION_EXTENSION_FORM" to "custom_reg_form.forms.ExtraInfoForm" in `lms.env.json`. 6 | 4. Run migrations. 7 | 5. Start/restart the LMS. 8 | -------------------------------------------------------------------------------- /custom_reg_form/forms.py: -------------------------------------------------------------------------------- 1 | from .models import ExtraInfo 2 | from django.forms import ModelForm 3 | 4 | class ExtraInfoForm(ModelForm): 5 | """ 6 | The fields on this form are derived from the ExtraInfo model in models.py. 7 | """ 8 | def __init__(self, *args, **kwargs): 9 | super(ExtraInfoForm, self).__init__(*args, **kwargs) 10 | self.fields['favorite_movie'].error_messages = { 11 | "required": u"Please tell us your favorite movie.", 12 | "invalid": u"We're pretty sure you made that movie up.", 13 | } 14 | 15 | class Meta(object): 16 | model = ExtraInfo 17 | fields = ('favorite_editor', 'favorite_movie') 18 | -------------------------------------------------------------------------------- /custom_reg_form/models.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | from django.db import models 3 | 4 | # Backwards compatible settings.AUTH_USER_MODEL 5 | USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User') 6 | 7 | 8 | class ExtraInfo(models.Model): 9 | """ 10 | This model contains two extra fields that will be saved when a user registers. 11 | The form that wraps this model is in the forms.py file. 12 | """ 13 | user = models.OneToOneField(USER_MODEL, null=True) 14 | FAVORITE_EDITOR = ( 15 | ('vim', 'Vim'), 16 | ('emacs', 'Emacs'), 17 | ('np', 'Notepad'), 18 | ('cat', 'cat > filename'), 19 | ) 20 | 21 | favorite_movie = models.CharField( 22 | verbose_name="Fav Flick", 23 | max_length=100, 24 | ) 25 | favorite_editor = models.CharField( 26 | verbose_name="Favorite Editor", 27 | choices=FAVORITE_EDITOR, 28 | blank=True, 29 | max_length=5, 30 | ) 31 | -------------------------------------------------------------------------------- /custom_reg_form/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | 4 | from django.db import migrations, models 5 | from django.conf import settings 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | migrations.swappable_dependency(settings.AUTH_USER_MODEL), 12 | ] 13 | 14 | operations = [ 15 | migrations.CreateModel( 16 | name='ExtraInfo', 17 | fields=[ 18 | ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), 19 | ('favorite_movie', models.CharField(max_length=100, verbose_name=b'Fav Flick', error_messages={b'required': 'Please tell us your favorite movie.', b'invalid': "We're pretty sure you made that movie up."})), 20 | ('favorite_editor', models.CharField(blank=True, max_length=5, verbose_name=b'Favorite Editor', choices=[(b'vim', b'Vim'), (b'emacs', b'Emacs'), (b'np', b'Notepad'), (b'cat', b'cat > filename')])), 21 | ('user', models.OneToOneField(null=True, to=settings.AUTH_USER_MODEL)), 22 | ], 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Copyright (c) 2014-2015 Harvard, edX & OpenCraft 4 | # 5 | # This software's license gives you freedom; you can copy, convey, 6 | # propagate, redistribute and/or modify this program under the terms of 7 | # the GNU Affero General Public License (AGPL) as published by the Free 8 | # Software Foundation (FSF), either version 3 of the License, or (at your 9 | # option) any later version of the AGPL published by the FSF. 10 | # 11 | # This program is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Affero General Public License 17 | # along with this program in a file in the toplevel directory called 18 | # "AGPLv3". If not, see . 19 | # 20 | 21 | # Imports ########################################################### 22 | 23 | import os 24 | from setuptools import setup 25 | 26 | 27 | # Main ############################################################## 28 | 29 | setup( 30 | name='custom-form-app', 31 | version='1.0', 32 | description='LMS - Custom Registration Extension Form', 33 | packages=['custom_reg_form'], 34 | install_requires=[ 35 | 'Django', 36 | ], 37 | ) 38 | 39 | --------------------------------------------------------------------------------