'Populates form with fields from given ContactType'

def __init__(self, contact_type, instance=None, *args, **kwargs):

    if instance:
        self.instance = instance
        values = instance.contactvalue_set.all()
    super(ContactForm, self).__init__(*args, **kwargs)
    self.fields['name'].label = _('Name')
    if ('files' in kwargs):
        self.files = kwargs['files']
    for field in contact_type.fields.all():
        if self.instance:
            initial_field_name = self._get_free_field_name(field)
            self.fields[initial_field_name] = self._get_form_field(field)
            for value in values:
                if (value.field == field):
                    field_name = self._get_free_field_name(field)
                    self.fields[field_name] = self._get_form_field(field, value)
                    if (initial_field_name in self.fields):
                        del self.fields[initial_field_name]
        else:
            field_name = self._get_free_field_name(field)
            self.fields[field_name] = self._get_form_field(field)
    if self.instance:
        self.fields['name'].initial = self.instance.name
