mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-25 00:13:45 +00:00
Permet de reprendre la même ip quand on édite une interface
This commit is contained in:
parent
36a0a43710
commit
a156010262
2 changed files with 10 additions and 2 deletions
|
@ -60,6 +60,8 @@ class EditInterfaceForm(ModelForm):
|
||||||
if "ipv4" in self.fields:
|
if "ipv4" in self.fields:
|
||||||
self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4"
|
self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4"
|
||||||
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True)
|
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:
|
if "machine" in self.fields:
|
||||||
self.fields['machine'].queryset = Machine.objects.all().select_related('user')
|
self.fields['machine'].queryset = Machine.objects.all().select_related('user')
|
||||||
|
|
||||||
|
@ -92,6 +94,8 @@ class BaseEditInterfaceForm(EditInterfaceForm):
|
||||||
if not infra:
|
if not infra:
|
||||||
self.fields['type'].queryset = MachineType.objects.filter(ip_type__in=IpType.objects.filter(need_infra=False))
|
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))
|
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:
|
else:
|
||||||
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True)
|
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True)
|
||||||
|
|
||||||
|
|
|
@ -102,20 +102,21 @@ def input_id( f_name ) :
|
||||||
def hidden_id( f_name ):
|
def hidden_id( f_name ):
|
||||||
return 'typeahead_hidden_'+f_name
|
return 'typeahead_hidden_'+f_name
|
||||||
|
|
||||||
def hidden_tag( f_name ):
|
def hidden_tag( f_bound, f_name ):
|
||||||
return render_tag(
|
return render_tag(
|
||||||
'input',
|
'input',
|
||||||
attrs={
|
attrs={
|
||||||
'id': hidden_id(f_name),
|
'id': hidden_id(f_name),
|
||||||
'name': f_name,
|
'name': f_name,
|
||||||
'type': 'hidden',
|
'type': 'hidden',
|
||||||
'value': ''
|
'value': f_bound.value()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
def typeahead_full_script( f_name, f_value ) :
|
def typeahead_full_script( f_name, f_value ) :
|
||||||
js_content = \
|
js_content = \
|
||||||
'$("#'+input_id(f_name)+'").ready( function() {\n' + \
|
'$("#'+input_id(f_name)+'").ready( function() {\n' + \
|
||||||
|
reset_input( f_name, f_value ) + '\n' + \
|
||||||
typeahead_choices( f_value ) + '\n' + \
|
typeahead_choices( f_value ) + '\n' + \
|
||||||
typeahead_engine () + '\n' + \
|
typeahead_engine () + '\n' + \
|
||||||
'$("#'+input_id(f_name) + '").typeahead(\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 ) )
|
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 ) :
|
def typeahead_choices( f_value ) :
|
||||||
return 'var choices = [' + \
|
return 'var choices = [' + \
|
||||||
', '.join([ \
|
', '.join([ \
|
||||||
|
|
Loading…
Reference in a new issue