def __init__(self, user, item_type, *args, **kwargs):

        self.item_type = item_type
        if 'instance' in kwargs:
            self.instance = kwargs['instance']
            values = self.instance.itemvalue_set.all()
            del kwargs['instance']

        super(ItemForm, self).__init__(*args, **kwargs)

        if 'files' in kwargs:
            self.files = kwargs['files']

        # Model fields
        self.fields['name'] = forms.CharField(max_length=512,
                                              widget=forms.TextInput(attrs={'size': '50'}))
        self.fields['name'].label = _("Name")
        self.fields['parent'] = forms.ModelChoiceField(
            label=_('Parent'), queryset=[], required=False)
        self.fields['status'] = forms.ModelChoiceField(
            label=_('Status'), queryset=[], required=True)
        self.fields['manufacturer'] = forms.ModelChoiceField(label=_('Manufacturer'),
                                                             queryset=[], required=False)
        self.fields['supplier'] = forms.ModelChoiceField(
            label=_('Supplier'), queryset=[], required=False)
        self.fields['owner'] = forms.ModelChoiceField(
            label=_('Owner'), queryset=[], required=False)
        self.fields['location'] = forms.ModelChoiceField(
            label=_('Location'), queryset=[], required=False)
        self.fields['asset'] = forms.ModelChoiceField(label=_('Asset Record'),
                                                      queryset=[], required=False)

        self.fields['parent'].queryset = Object.filter_permitted(
            user, Item.objects, mode='x')
        self.fields['status'].queryset = Object.filter_permitted(
            user, ItemStatus.objects, mode='x')
        self.fields['manufacturer'].queryset = Object.filter_permitted(
            user, Contact.objects, mode='x')
        self.fields['supplier'].queryset = Object.filter_permitted(
            user, Contact.objects, mode='x')
        self.fields['owner'].queryset = Object.filter_permitted(
            user, Contact.objects, mode='x')
        self.fields['location'].queryset = Object.filter_permitted(
            user, Location.objects, mode='x')
        self.fields['asset'].queryset = Object.filter_permitted(
            user, Asset.objects, mode='x')

        self.fields['manufacturer'].widget.attrs.update({'class': 'autocomplete',
                                                         'callback': reverse('identities_ajax_contact_lookup')})
        self.fields['manufacturer'].widget.attrs.update(
            {'popuplink': reverse('identities_contact_add')})
        self.fields['supplier'].widget.attrs.update({'class': 'autocomplete',
                                                     'callback': reverse('identities_ajax_contact_lookup')})
        self.fields['supplier'].widget.attrs.update(
            {'popuplink': reverse('identities_contact_add')})
        self.fields['owner'].widget.attrs.update({'class': 'autocomplete',
                                                  'callback': reverse('identities_ajax_contact_lookup')})
        self.fields['owner'].widget.attrs.update(
            {'popuplink': reverse('identities_contact_add')})
        #self.fields['asset'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('finance_ajax_asset_lookup')})

        self.fields['location'].widget.attrs.update(
            {'popuplink': reverse('infrastructure_location_add')})
        self.fields['location'].widget.attrs.update({'class': 'autocomplete',
                                                     'callback': reverse('identities_ajax_location_lookup')})
        self.fields['asset'].widget.attrs.update(
            {'popuplink': reverse('finance_asset_add')})

        try:
            conf = ModuleSetting.get_for_module(
                'treeio.infrastructure', 'default_item_status')[0]
            default_item_status = ItemStatus.objects.get(
                pk=long(conf.value), trash=False)
            self.fields['status'].initial = default_item_status.id
        except Exception:
            pass

        if self.instance:
            self.fields['name'].initial = self.instance.name
            self.fields['status'].initial = self.instance.status_id
            self.fields['parent'].initial = self.instance.parent_id
            self.fields['manufacturer'].initial = self.instance.manufacturer_id
            self.fields['supplier'].initial = self.instance.supplier_id
            self.fields['owner'].initial = self.instance.owner_id
            self.fields['location'].initial = self.instance.location_id
            self.fields['asset'].initial = self.instance.asset_id

        # AssetField <-> AssetValue fields
        for field in item_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)
Returns a slash-formatted string from the given XML representation.
dataset/ETHPy150Open treeio/treeio/treeio/infrastructure/forms.py/ItemForm.__init__--crossover with--dataset/ETHPy150Open markuskiller/textblob-de/textblob_de/ext/_pattern/text/tree.py/parse_string