refactor: Refactor LiaisonForm without BetterModelForm

This commit is contained in:
Jennifer Richards 2023-05-10 17:03:31 -03:00
parent a75dbd4f40
commit 85d0934ba0
No known key found for this signature in database
GPG key ID: 9B2BF5C5ADDA6A6E
2 changed files with 32 additions and 23 deletions

View file

@ -9,7 +9,6 @@ import operator
from typing import Union # pyflakes:ignore
from email.utils import parseaddr
from form_utils.forms import BetterModelForm
from django import forms
from django.conf import settings
@ -213,7 +212,7 @@ class CustomModelMultipleChoiceField(forms.ModelMultipleChoiceField):
return super(CustomModelMultipleChoiceField, self).prepare_value(value)
class LiaisonModelForm(BetterModelForm):
class LiaisonModelForm(forms.ModelForm):
'''Specify fields which require a custom widget or that are not part of the model.
'''
from_groups = forms.ModelMultipleChoiceField(queryset=Group.objects.all(),label='Groups',required=False)
@ -238,13 +237,6 @@ class LiaisonModelForm(BetterModelForm):
class Meta:
model = LiaisonStatement
exclude = ('attachments','state','from_name','to_name')
fieldsets = [('From', {'fields': ['from_groups','from_contact', 'response_contacts'], 'legend': ''}),
('To', {'fields': ['to_groups','to_contacts'], 'legend': ''}),
('Other email addresses', {'fields': ['technical_contacts','action_holder_contacts','cc_contacts'], 'legend': ''}),
('Purpose', {'fields':['purpose', 'deadline'], 'legend': ''}),
('Reference', {'fields': ['other_identifiers','related_to'], 'legend': ''}),
('Liaison Statement', {'fields': ['title', 'submitted_date', 'body', 'attachments'], 'legend': ''}),
('Add attachment', {'fields': ['attach_title', 'attach_file', 'attach_button'], 'legend': ''})]
def __init__(self, user, *args, **kwargs):
super(LiaisonModelForm, self).__init__(*args, **kwargs)

View file

@ -47,21 +47,38 @@
method="post"
enctype="multipart/form-data"
data-edit-form="{{ form.edit }}"
data-ajax-info-url="{% url "ietf.liaisons.views.ajax_get_liaison_info" %}">
data-ajax-info-url="{% url 'ietf.liaisons.views.ajax_get_liaison_info' %}">
{% csrf_token %}
{% for fieldset in form.fieldsets %}
<h2>{{ fieldset.name }}</h2>
{% for field in fieldset %}
{% if field.id_for_label != "id_attachments" %}
{% bootstrap_field field layout="horizontal" %}
{% else %}
<div class="row mb-3">
<p class="col-md-2 fw-bold col-form-label">{{ field.label }}</p>
<div class="col-md-10">{{ field }}</div>
</div>
{% endif %}
{% endfor %}
{% endfor %}
<h2>From</h2>
{% bootstrap_field form.from_groups layout="horizontal" %}
{% bootstrap_field form.from_contact layout="horizontal" %}
{% bootstrap_field form.response_contacts layout="horizontal" %}
<h2>To</h2>
{% bootstrap_field form.to_groups layout="horizontal" %}
{% bootstrap_field form.to_contacts layout="horizontal" %}
<h2>Other email addresses</h2>
{% bootstrap_field form.technical_contacts layout="horizontal" %}
{% bootstrap_field form.action_holder_contacts layout="horizontal" %}
{% bootstrap_field form.cc_contacts layout="horizontal" %}
<h2>Purpose</h2>
{% bootstrap_field form.purpose layout="horizontal" %}
{% bootstrap_field form.deadline layout="horizontal" %}
<h2>Reference</h2>
{% bootstrap_field form.other_identifiers layout="horizontal" %}
{% bootstrap_field form.related_to layout="horizontal" %}
<h2>Liaison Statement</h2>
{% bootstrap_field form.title layout="horizontal" %}
{% bootstrap_field form.submitted_date layout="horizontal" %}
{% bootstrap_field form.body layout="horizontal" %}
<div class="row mb-3">
<p class="col-md-2 fw-bold col-form-label">{{ form.attachments.label }}</p>
<div class="col-md-10">{{ form.attachments }}</div>
</div>
<h2>Add attachment</h2>
{% bootstrap_field form.attach_title layout="horizontal" %}
{% bootstrap_field form.attach_file layout="horizontal" %}
{% bootstrap_field form.attach_button layout="horizontal" %}
<a class="btn btn-danger float-end"
href="{% if liaison %}{% url 'ietf.liaisons.views.liaison_detail' object_id=liaison.pk %}{% else %}{% url 'ietf.liaisons.views.liaison_list' %}{% endif %}">
Cancel