Skip to content

Commit

Permalink
Merge pull request #2994 from Uninett/uncrispyfy/device-group-form
Browse files Browse the repository at this point in the history
Uncrispyfy DeviceGroupForm in seeddb
  • Loading branch information
podliashanyk authored Sep 20, 2024
2 parents 78b609d + 7fe2f74 commit 46c253f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
11 changes: 3 additions & 8 deletions python/nav/web/seeddb/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from django.utils.safestring import mark_safe

from crispy_forms.helper import FormHelper
from crispy_forms_foundation.layout import Layout, Field, Fieldset, Row, Column
from crispy_forms_foundation.layout import Layout, Fieldset, Row, Column

from nav.django.forms import HStoreField
from nav.web.crispyforms import LabelSubmit
Expand Down Expand Up @@ -372,6 +372,8 @@ class DeviceGroupForm(forms.ModelForm):
netboxes = forms.ModelMultipleChoiceField(
queryset=Netbox.objects.all(), required=False
)
netboxes.widget.attrs.update({"class": "select2"})
no_crispy = True

def __init__(self, *args, **kwargs):
# If the form is based on an existing model instance, populate the
Expand All @@ -380,13 +382,6 @@ def __init__(self, *args, **kwargs):
initial = kwargs.setdefault('initial', {})
initial['netboxes'] = [n.pk for n in kwargs['instance'].netboxes.all()]
forms.ModelForm.__init__(self, *args, **kwargs)
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.layout = Layout(
'id',
'description',
Field('netboxes', css_class='select2'),
)

class Meta(object):
model = NetboxGroup
Expand Down
1 change: 0 additions & 1 deletion python/nav/web/seeddb/page/netboxgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def netboxgroup_edit(request, netboxgroup_id=None):
DeviceGroupForm,
netboxgroup_id,
'seeddb-netboxgroup-edit',
template='seeddb/edit_device_group.html',
extra_context=extra_context,
)

Expand Down
18 changes: 18 additions & 0 deletions python/nav/web/templates/seeddb/_form_fields.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% for field in form %}
<div id="div_id_{{ field.name }}"
class="ctrlHolder{% if field.errors %} error{% endif %}"
>
<label for="id_{{ field.name }}"
class="{% if field.field.required %}requiredField{% endif %}"
>
{{ field.label.title }}
{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
{{ field }}
{% for error in field.errors %}
<small id="error_{{ forloop.counter }}_id_{{ field.name }}" class="error">
{{ error }}
</small>
{% endfor %}
</div>
{% endfor %}
12 changes: 9 additions & 3 deletions python/nav/web/templates/seeddb/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ <h4>{{ title }}
<form class="seeddb-edit" action="" method="post">
<fieldset>
<legend>Attributes</legend>
{% block crispyfields %}
{{ form|crispy }}
{% endblock %}
{% if form.no_crispy %}
{% block formfields %}
{% include "seeddb/_form_fields.html" %}
{% endblock %}
{% else %}
{% block crispyfields %}
{{ form|crispy }}
{% endblock %}
{% endif %}
</fieldset>
<input type="submit" name="submit" value="Save {{ verbose_name }}" class="submit button small left" id="submit-id-submit">
</form>
Expand Down
5 changes: 0 additions & 5 deletions python/nav/web/templates/seeddb/edit_device_group.html

This file was deleted.

0 comments on commit 46c253f

Please sign in to comment.