mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-25 16:33:47 +00:00
Permet de reprendre la même ip quand on édite une interface
This commit is contained in:
parent
883258d079
commit
df360ddea7
2 changed files with 10 additions and 2 deletions
|
@ -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([ \
|
||||
|
|
Loading…
Reference in a new issue