Skip to content
Snippets Groups Projects
Commit d66fc9e5 authored by Dan Braghis's avatar Dan Braghis Committed by Todd Dembrey
Browse files

Add user full name field and include in admin forms

parent a1befb99
No related branches found
No related tags found
No related merge requests found
from django import forms
from django.utils.translation import ugettext_lazy as _
from wagtail.wagtailusers.forms import UserEditForm, UserCreationForm
class CustomUserEditForm(UserEditForm):
full_name = forms.CharField(label=_("Full name"), required=False, help_text=_("Leave blank to generate from First and Last name values."))
class CustomUserCreationForm(UserCreationForm):
full_name = forms.CharField(label=_("Full name"), required=False, help_text=_("Leave blank to generate from First and Last name values."))
# -*- coding: utf-8 -*-
# Generated by Django 1.11.8 on 2018-01-24 17:21
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0002_initial_data'),
]
operations = [
migrations.AddField(
model_name='user',
name='full_name',
field=models.CharField(blank=True, max_length=255, verbose_name='Full name'),
),
]
from django.db import models
from django.contrib.auth.models import AbstractUser from django.contrib.auth.models import AbstractUser
class User(AbstractUser): class User(AbstractUser):
pass full_name = models.CharField(verbose_name='Full name', max_length=255, blank=True)
def get_full_name(self):
"""
Returns the first_name plus the last_name, with a space in between.
"""
if self.full_name:
return self.full_name.strip()
return super().get_full_name()
{% extends "wagtailusers/users/create.html" %}
{% block extra_fields %}
{% include "wagtailadmin/shared/field_as_li.html" with field=form.full_name %}
{% endblock extra_fields %}
{% extends "wagtailusers/users/edit.html" %}
{% block extra_fields %}
{% include "wagtailadmin/shared/field_as_li.html" with field=form.full_name %}
{% endblock extra_fields %}
...@@ -193,6 +193,10 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'media') ...@@ -193,6 +193,10 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/' MEDIA_URL = '/media/'
AUTH_USER_MODEL = 'users.User' AUTH_USER_MODEL = 'users.User'
WAGTAIL_USER_ADD_FORM = 'opentech.apply.users.forms.CustomUserCreationForm'
WAGTAIL_USER_EDIT_FORM = 'opentech.apply.users.forms.CustomUserEditForm'
WAGTAIL_USER_CUSTOM_FIELDS = ['full_name']
# TODO populate me with the dashboard URL when ready # TODO populate me with the dashboard URL when ready
LOGIN_URL = 'users:login' LOGIN_URL = 'users:login'
LOGIN_REDIRECT_URL = '/' LOGIN_REDIRECT_URL = '/'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment