0001-manager-provide-a-simpler-ou-creation-form-66795.patch
src/authentic2/manager/forms.py | ||
---|---|---|
613 | 613 |
def __init__(self, *args, **kwargs): |
614 | 614 |
super().__init__(*args, **kwargs) |
615 | 615 |
self.fields['name'].label = _('label').title() |
616 |
self.fields['colour'].widget = forms.TextInput(attrs={'type': 'color'}) |
|
616 |
if 'colour' in self.fields: |
|
617 |
self.fields['colour'].widget = forms.TextInput(attrs={'type': 'color'}) |
|
617 | 618 | |
618 | 619 |
class Meta: |
619 | 620 |
model = OrganizationalUnit |
src/authentic2/manager/ou_views.py | ||
---|---|---|
47 | 47 |
permissions = ['a2_rbac.add_organizationalunit'] |
48 | 48 |
form_class = forms.OUEditForm |
49 | 49 |
title = _('Add organizational unit') |
50 |
exclude_fields = ('slug',) |
|
51 | ||
52 |
def get_fields(self): |
|
53 |
return [x for x in self.form_class.base_fields.keys() if x not in self.exclude_fields] |
|
50 |
fields = ('name', 'default') |
|
54 | 51 | |
55 | 52 |
def get_success_url(self): |
56 | 53 |
return '..' |
tests/test_manager.py | ||
---|---|---|
63 | 63 |
ou_add = login(app, superuser_or_admin, path=reverse('a2-manager-ou-add')) |
64 | 64 |
form = ou_add.form |
65 | 65 |
assert 'name' in form.fields |
66 |
assert 'slug' not in form.fields |
|
66 |
assert 'default' in form.fields |
|
67 |
excluded_fields = ( |
|
68 |
'slug', |
|
69 |
'username_is_unique', |
|
70 |
'email_is_unique', |
|
71 |
'validate_emails', |
|
72 |
'show_username', |
|
73 |
'check_required_on_login_attributes', |
|
74 |
'user_can_reset_password', |
|
75 |
'user_add_password_policy', |
|
76 |
'clean_unused_accounts_alert', |
|
77 |
'clean_unused_accounts_deletion', |
|
78 |
'home_url', |
|
79 |
'logo', |
|
80 |
'colour', |
|
81 |
) |
|
82 |
for field in excluded_fields: |
|
83 |
assert field not in form.fields |
|
84 | ||
67 | 85 |
form.set('name', 'New OU') |
68 | 86 |
response = form.submit().follow() |
69 | 87 |
assert 'New OU' in response |
70 |
- |