Commit a1560102 authored by Pierre Cadart's avatar Pierre Cadart

Permet de reprendre la même ip quand on édite une interface

parent 36a0a437
......@@ -60,6 +60,8 @@ class EditInterfaceForm(ModelForm):
if "ipv4" in self.fields:
self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4"
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True)
# Add it's own address
self.fields['ipv4'].queryset |= IpList.objects.filter(id=self.fields['ipv4'].get_bound_field(self, 'ipv4').value())
if "machine" in self.fields:
self.fields['machine'].queryset = Machine.objects.all().select_related('user')
......@@ -92,6 +94,8 @@ class BaseEditInterfaceForm(EditInterfaceForm):
if not infra:
self.fields['type'].queryset = MachineType.objects.filter(ip_type__in=IpType.objects.filter(need_infra=False))
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True).filter(ip_type__in=IpType.objects.filter(need_infra=False))
# Add it's own address
self.fields['ipv4'].queryset |= IpList.objects.filter(id=self.fields['ipv4'].get_bound_field(self, 'ipv4').value())
else:
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True)
......
......@@ -102,20 +102,21 @@ def input_id( f_name ) :
def hidden_id( f_name ):
return 'typeahead_hidden_'+f_name
def hidden_tag( f_name ):
def hidden_tag( f_bound, f_name ):
return render_tag(
'input',
attrs={
'id': hidden_id(f_name),
'name': f_name,
'type': 'hidden',
'value': ''
'value': f_bound.value()
}
)
def typeahead_full_script( f_name, f_value ) :
js_content = \
'$("#'+input_id(f_name)+'").ready( function() {\n' + \
reset_input( f_name, f_value ) + '\n' + \
typeahead_choices( f_value ) + '\n' + \
typeahead_engine () + '\n' + \
'$("#'+input_id(f_name) + '").typeahead(\n' + \
......@@ -128,6 +129,9 @@ def typeahead_full_script( f_name, f_value ) :
return render_tag( 'script', content=mark_safe( js_content ) )
def reset_input( f_name, f_value ) :
return '$("#'+input_id(f_name)+'").val("'+f_value.empty_label+'");'
def typeahead_choices( f_value ) :
return 'var choices = [' + \
', '.join([ \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment