Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncrispyfy DeviceGroupForm in seeddb #2994

Merged
merged 5 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

@hmpf hmpf Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When crispy is gone we will no longer need "no_crsipy" for choosing which form to show. It is still useful to hold extra form attributes though, like with the filter forms.

Copy link
Contributor Author

@podliashanyk podliashanyk Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can remove no_crispy = True completely once all edit/add forms i seeddb are converted. Because then we can safely remove the {% if form.no_crispy %}-block from the seeddb/edit.html that was added in this PR and render {% include "seeddb/_form_fields.html" %} by default there


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 %}"
podliashanyk marked this conversation as resolved.
Show resolved Hide resolved
>
<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.

Loading