diff --git a/conntrackt/forms.py b/conntrackt/forms.py --- a/conntrackt/forms.py +++ b/conntrackt/forms.py @@ -3,7 +3,7 @@ from django.forms import ModelForm from django.forms.models import inlineformset_factory # Application imports. -from .models import Entity, Interface +from .models import Entity, Interface, Communication class EntityForm(ModelForm): @@ -56,3 +56,28 @@ class InterfaceForm(ModelForm): self.fields["description"].widget.attrs["placeholder"] = "Interface description" self.fields["address"].widget.attrs["placeholder"] = "IP address of interface" self.fields["netmask"].widget.attrs["placeholder"] = "IP address netmask" + + +class CommunicationForm(ModelForm): + """ + Implements a custom model form for communications with some styling changes. + """ + + class Meta: + model = Communication + + def __init__(self, *args, **kwargs): + """ + Initialises the form instance. Sets-up some bootstrap CSS classes for + widgets. + """ + + super(CommunicationForm, self).__init__(*args, **kwargs) + + # Update the widgets to be wider. + for field_name, field in self.fields.iteritems(): + field.widget.attrs["class"] = "span6" + + # Set-up some placeholders. + self.fields["port"].widget.attrs["placeholder"] = "Port used for communication" + self.fields["description"].widget.attrs["placeholder"] = "Communication description"