mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-09-12 01:03:09 +00:00
Met l'ip actuelle et la bonne value dans le form d'edition d'interface
This commit is contained in:
parent
75ed68df1b
commit
57dda68710
2 changed files with 12 additions and 8 deletions
|
@ -65,7 +65,7 @@ class EditInterfaceForm(ModelForm):
|
|||
self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4"
|
||||
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True).annotate(mtype_id=F('ip_type__machinetype__id'))
|
||||
# Add it's own address
|
||||
self.fields['ipv4'].queryset |= IpList.objects.filter(id=self.instance.id).annotate(mtype_id=F('ip_type__machinetype__id'))
|
||||
self.fields['ipv4'].queryset |= IpList.objects.filter(interface=self.instance).annotate(mtype_id=F('ip_type__machinetype__id'))
|
||||
if "machine" in self.fields:
|
||||
self.fields['machine'].queryset = Machine.objects.all().select_related('user')
|
||||
|
||||
|
@ -99,10 +99,10 @@ class BaseEditInterfaceForm(EditInterfaceForm):
|
|||
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)).annotate(mtype_id=F('ip_type__machinetype__id'))
|
||||
# Add it's own address
|
||||
self.fields['ipv4'].queryset |= IpList.objects.filter(id=self.instance.id).annotate(mtype_id=F('ip_type__machinetype__id'))
|
||||
self.fields['ipv4'].queryset |= IpList.objects.filter(interface=self.instance).annotate(mtype_id=F('ip_type__machinetype__id'))
|
||||
else:
|
||||
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True).annotate(mtype_id=F('ip_type__machinetype__id'))
|
||||
self.fields['ipv4'].queryset |= IpList.objects.filter(id=self.instance.id).annotate(mtype_id=F('ip_type__machinetype__id'))
|
||||
self.fields['ipv4'].queryset |= IpList.objects.filter(interface=self.instance).annotate(mtype_id=F('ip_type__machinetype__id'))
|
||||
|
||||
class AliasForm(ModelForm):
|
||||
class Meta:
|
||||
|
|
|
@ -180,6 +180,7 @@ def bootstrap_form_typeahead(django_form, typeahead_fields, *args, **kwargs):
|
|||
typeahead_js(
|
||||
f_name,
|
||||
f_value,
|
||||
f_bound,
|
||||
t_choices,
|
||||
t_engine,
|
||||
t_match_func,
|
||||
|
@ -215,7 +216,7 @@ def hidden_tag( f_bound, f_name ):
|
|||
}
|
||||
)
|
||||
|
||||
def typeahead_js( f_name, f_value,
|
||||
def typeahead_js( f_name, f_value, f_bound,
|
||||
t_choices, t_engine, t_match_func, t_update_on ) :
|
||||
""" The whole script to use """
|
||||
|
||||
|
@ -239,7 +240,7 @@ def typeahead_js( f_name, f_value,
|
|||
'$("#'+input_id(f_name) + '").typeahead(\n' + \
|
||||
default_datasets( f_name, match_func ) + '\n' + \
|
||||
');\n' + \
|
||||
reset_input( f_name, f_value ) + '\n' + \
|
||||
reset_input( f_name, f_bound ) + '\n' + \
|
||||
'};\n' + \
|
||||
'$("#'+input_id(f_name) + '").bind(\n' + \
|
||||
'"typeahead:select", ' + \
|
||||
|
@ -254,10 +255,13 @@ def typeahead_js( f_name, f_value,
|
|||
|
||||
return render_tag( 'script', content=mark_safe( js_content ) )
|
||||
|
||||
def reset_input( f_name, f_value ) :
|
||||
def reset_input( f_name, f_bound ) :
|
||||
""" The JS script to reset the fields values """
|
||||
return '$("#'+input_id(f_name)+'").typeahead("val","");\n' \
|
||||
'$("#'+hidden_id(f_name)+'").val("");'
|
||||
return '$("#'+input_id(f_name)+'").typeahead(' \
|
||||
'"val", ' \
|
||||
'engine_'+f_name+'.get('+str(f_bound.value())+')[0].value' \
|
||||
');\n' \
|
||||
'$("#'+hidden_id(f_name)+'").val('+str(f_bound.value())+');'
|
||||
|
||||
def default_choices( f_value ) :
|
||||
""" The JS script creating the variable choices_<fieldname> """
|
||||
|
|
Loading…
Reference in a new issue