diff --git a/python/nav/web/templates/useradmin/account_detail.html b/python/nav/web/templates/useradmin/account_detail.html
index 07a425f71e..a82ed3d587 100644
--- a/python/nav/web/templates/useradmin/account_detail.html
+++ b/python/nav/web/templates/useradmin/account_detail.html
@@ -1,5 +1,4 @@
{% extends "useradmin/base.html" %}
-{% load crispy_forms_tags %}
{% block content %}
@@ -63,7 +62,7 @@
{% comment %} ACCOUNT FORM {% endcomment %}
{% if account_form %}
- {% crispy account_form %}
+ {% include 'custom_crispy_templates/flat_form.html' with form=account_form %}
{% endif %}
diff --git a/python/nav/web/useradmin/forms.py b/python/nav/web/useradmin/forms.py
index 2ce2c6bd40..56d0222527 100644
--- a/python/nav/web/useradmin/forms.py
+++ b/python/nav/web/useradmin/forms.py
@@ -21,13 +21,6 @@
from django import forms
from django.utils.encoding import force_str
-from crispy_forms.helper import FormHelper
-from crispy_forms_foundation.layout import (
- Layout,
- Fieldset,
- Submit,
- HTML,
-)
from nav.web.crispyforms import (
set_flat_form_attributes,
FlatFieldset,
@@ -94,31 +87,33 @@ class AccountForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(AccountForm, self).__init__(*args, **kwargs)
account = kwargs.get('instance', False)
- self.helper = FormHelper()
- self.helper.form_action = ''
- self.helper.form_method = 'POST'
if account:
self.fields['password1'].required = False
- submit_value = 'Save changes'
if kwargs["instance"].id == Account.DEFAULT_ACCOUNT:
# We don't want to enable significant changes to the anonymous account
self.fields["password1"].widget.attrs["readonly"] = True
self.fields["password2"].widget.attrs["readonly"] = True
self.fields["login"].widget.attrs["readonly"] = True
- else:
- submit_value = 'Create account'
-
- self.helper.layout = Layout(
- Fieldset(
- 'Account',
- 'login',
- 'name',
- 'password1',
- 'password2',
- Submit('submit_account', submit_value, css_class='small'),
- )
+
+ submit_value = "Save changes" if account else "Create account"
+
+ self.attrs = set_flat_form_attributes(
+ form_fields=[
+ FlatFieldset(
+ legend="Account",
+ fields=[
+ self["login"],
+ self["name"],
+ self["password1"],
+ self["password2"],
+ SubmitField(
+ "submit_account", submit_value, css_classes="small"
+ ),
+ ],
+ )
+ ],
)
def clean_password1(self):
@@ -150,29 +145,27 @@ class ExternalAccountForm(AccountForm):
def __init__(self, *args, **kwargs):
super(AccountForm, self).__init__(*args, **kwargs)
- self.helper = FormHelper()
- self.helper.form_action = ''
- self.helper.form_method = 'POST'
-
- if kwargs['instance'].ext_sync:
- # We don't want to enable local password editing for accounts that are
- # managed externally.
- authenticator = (
- "External authenticator: %s
"
- % kwargs["instance"].ext_sync
- )
- del self.fields['password1']
- del self.fields['password2']
- self.fields['login'].widget.attrs['readonly'] = True
-
- self.helper.layout = Layout(
- Fieldset(
- 'Account',
- 'login',
- 'name',
- HTML(authenticator),
- Submit('submit_account', 'Save changes', css_class='small'),
- )
+
+ # We don't want to enable local password editing for accounts that are
+ # managed externally.
+ del self.fields['password1']
+ del self.fields['password2']
+ self.fields['login'].widget.attrs['readonly'] = True
+
+ self.attrs = set_flat_form_attributes(
+ form_fields=[
+ FlatFieldset(
+ legend="Account",
+ fields=[
+ self["login"],
+ self["name"],
+ SubmitField(
+ "submit_account", "Save changes", css_classes="small"
+ ),
+ ],
+ template="useradmin/frag-external-account-fieldset.html",
+ )
+ ],
)