mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 19:33:11 +00:00
Renomme bft en mfb (massive_bootstrap_form)
Plus adapté aux nouvelles fonctions incoming
This commit is contained in:
parent
210fa28d74
commit
db30643c13
9 changed files with 93 additions and 86 deletions
|
@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
{% load bootstrap3 %}
|
||||
{% load staticfiles%}
|
||||
{% load bootstrap_form_typeahead %}
|
||||
{% load massive_bootstrap_form %}
|
||||
|
||||
{% block title %}Création et modification de factures{% endblock %}
|
||||
|
||||
|
@ -35,7 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
<h3>Editer la facture</h3>
|
||||
{% bootstrap_form_typeahead factureform 'user' %}
|
||||
{% massive_bootstrap_form factureform 'user' %}
|
||||
{{ venteform.management_form }}
|
||||
<h3>Articles de la facture</h3>
|
||||
<table class="table table-striped">
|
||||
|
|
|
@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
{% endcomment %}
|
||||
|
||||
{% load bootstrap3 %}
|
||||
{% load bootstrap_form_typeahead %}
|
||||
{% load massive_bootstrap_form %}
|
||||
|
||||
{% block title %}Création et modification de machines{% endblock %}
|
||||
|
||||
|
@ -78,10 +78,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
{% endif %}
|
||||
{% if interfaceform %}
|
||||
<h3>Interface</h3>
|
||||
{% if i_bft_param %}
|
||||
{% bootstrap_form_typeahead interfaceform 'ipv4,machine' bft_param=i_bft_param %}
|
||||
{% if i_mbf_param %}
|
||||
{% massive_bootstrap_form interfaceform 'ipv4,machine' mbf_param=i_mbf_param %}
|
||||
{% else %}
|
||||
{% bootstrap_form_typeahead interfaceform 'ipv4,machine' %}
|
||||
{% massive_bootstrap_form interfaceform 'ipv4,machine' %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if domainform %}
|
||||
|
@ -98,15 +98,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
{% endif %}
|
||||
{% if extensionform %}
|
||||
<h3>Extension</h3>
|
||||
{% bootstrap_form_typeahead extensionform 'origin' %}
|
||||
{% massive_bootstrap_form extensionform 'origin' %}
|
||||
{% endif %}
|
||||
{% if mxform %}
|
||||
<h3>Enregistrement MX</h3>
|
||||
{% bootstrap_form_typeahead mxform 'name' %}
|
||||
{% massive_bootstrap_form mxform 'name' %}
|
||||
{% endif %}
|
||||
{% if nsform %}
|
||||
<h3>Enregistrement NS</h3>
|
||||
{% bootstrap_form_typeahead nsform 'ns' %}
|
||||
{% massive_bootstrap_form nsform 'ns' %}
|
||||
{% endif %}
|
||||
{% if txtform %}
|
||||
<h3>Enregistrement TXT</h3>
|
||||
|
|
|
@ -55,7 +55,7 @@ from .models import IpType, Machine, Interface, IpList, MachineType, Extension,
|
|||
from users.models import User
|
||||
from users.models import all_has_access
|
||||
from preferences.models import GeneralOption, OptionalMachine
|
||||
from re2o.templatetags.bootstrap_form_typeahead import hidden_id, input_id
|
||||
from re2o.templatetags.massive_bootstrap_form import hidden_id, input_id
|
||||
|
||||
def all_active_interfaces():
|
||||
"""Renvoie l'ensemble des machines autorisées à sortir sur internet """
|
||||
|
@ -85,7 +85,7 @@ def f_type_id( is_type_tt ):
|
|||
return 'id_Interface-type_hidden' if is_type_tt else 'id_Interface-type'
|
||||
|
||||
def generate_ipv4_choices( form ) :
|
||||
""" Generate the parameter choices for the bootstrap_form_typeahead tag
|
||||
""" Generate the parameter choices for the massive_bootstrap_form tag
|
||||
"""
|
||||
f_ipv4 = form.fields['ipv4']
|
||||
used_mtype_id = []
|
||||
|
@ -112,7 +112,7 @@ def generate_ipv4_choices( form ) :
|
|||
return choices
|
||||
|
||||
def generate_ipv4_engine( is_type_tt ) :
|
||||
""" Generate the parameter engine for the bootstrap_form_typeahead tag
|
||||
""" Generate the parameter engine for the massive_bootstrap_form tag
|
||||
"""
|
||||
return (
|
||||
'new Bloodhound( {{'
|
||||
|
@ -126,7 +126,7 @@ def generate_ipv4_engine( is_type_tt ) :
|
|||
)
|
||||
|
||||
def generate_ipv4_match_func( is_type_tt ) :
|
||||
""" Generate the parameter match_func for the bootstrap_form_typeahead tag
|
||||
""" Generate the parameter match_func for the massive_bootstrap_form tag
|
||||
"""
|
||||
return (
|
||||
'function(q, sync) {{'
|
||||
|
@ -142,20 +142,20 @@ def generate_ipv4_match_func( is_type_tt ) :
|
|||
type_id = f_type_id( is_type_tt )
|
||||
)
|
||||
|
||||
def generate_ipv4_bft_param( form, is_type_tt ):
|
||||
""" Generate all the parameters to use with the bootstrap_form_typeahead
|
||||
def generate_ipv4_mbf_param( form, is_type_tt ):
|
||||
""" Generate all the parameters to use with the massive_bootstrap_form
|
||||
tag """
|
||||
i_choices = { 'ipv4': generate_ipv4_choices( form ) }
|
||||
i_engine = { 'ipv4': generate_ipv4_engine( is_type_tt ) }
|
||||
i_match_func = { 'ipv4': generate_ipv4_match_func( is_type_tt ) }
|
||||
i_update_on = { 'ipv4': [f_type_id( is_type_tt )] }
|
||||
i_bft_param = {
|
||||
i_mbf_param = {
|
||||
'choices': i_choices,
|
||||
'engine': i_engine,
|
||||
'match_func': i_match_func,
|
||||
'update_on': i_update_on
|
||||
}
|
||||
return i_bft_param
|
||||
return i_mbf_param
|
||||
|
||||
@login_required
|
||||
def new_machine(request, userid):
|
||||
|
@ -203,8 +203,8 @@ def new_machine(request, userid):
|
|||
reversion.set_comment("Création")
|
||||
messages.success(request, "La machine a été créée")
|
||||
return redirect("/users/profil/" + str(user.id))
|
||||
i_bft_param = generate_ipv4_bft_param( interface, False )
|
||||
return form({'machineform': machine, 'interfaceform': interface, 'domainform': domain, 'i_bft_param': i_bft_param}, 'machines/machine.html', request)
|
||||
i_mbf_param = generate_ipv4_mbf_param( interface, False )
|
||||
return form({'machineform': machine, 'interfaceform': interface, 'domainform': domain, 'i_mbf_param': i_mbf_param}, 'machines/machine.html', request)
|
||||
|
||||
@login_required
|
||||
def edit_interface(request, interfaceid):
|
||||
|
@ -243,8 +243,8 @@ def edit_interface(request, interfaceid):
|
|||
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in domain_form.changed_data))
|
||||
messages.success(request, "La machine a été modifiée")
|
||||
return redirect("/users/profil/" + str(interface.machine.user.id))
|
||||
i_bft_param = generate_ipv4_bft_param( interface_form, False )
|
||||
return form({'machineform': machine_form, 'interfaceform': interface_form, 'domainform': domain_form, 'i_bft_param': i_bft_param}, 'machines/machine.html', request)
|
||||
i_mbf_param = generate_ipv4_mbf_param( interface_form, False )
|
||||
return form({'machineform': machine_form, 'interfaceform': interface_form, 'domainform': domain_form, 'i_mbf_param': i_mbf_param}, 'machines/machine.html', request)
|
||||
|
||||
@login_required
|
||||
def del_machine(request, machineid):
|
||||
|
@ -302,8 +302,8 @@ def new_interface(request, machineid):
|
|||
reversion.set_comment("Création")
|
||||
messages.success(request, "L'interface a été ajoutée")
|
||||
return redirect("/users/profil/" + str(machine.user.id))
|
||||
i_bft_param = generate_ipv4_bft_param( interface_form, False )
|
||||
return form({'interfaceform': interface_form, 'domainform': domain_form, 'i_bft_param': i_bft_param}, 'machines/machine.html', request)
|
||||
i_mbf_param = generate_ipv4_mbf_param( interface_form, False )
|
||||
return form({'interfaceform': interface_form, 'domainform': domain_form, 'i_mbf_param': i_mbf_param}, 'machines/machine.html', request)
|
||||
|
||||
@login_required
|
||||
def del_interface(request, interfaceid):
|
||||
|
|
|
@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
{% endcomment %}
|
||||
|
||||
{% load bootstrap3 %}
|
||||
{% load bootstrap_form_typeahead %}
|
||||
{% load massive_bootstrap_form %}
|
||||
|
||||
{% block title %}Création et modification des préférences{% endblock %}
|
||||
|
||||
|
@ -35,7 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form_typeahead options 'utilisateur_asso' %}
|
||||
{% massive_bootstrap_form options 'utilisateur_asso' %}
|
||||
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
|
||||
</form>
|
||||
<br />
|
||||
|
|
|
@ -29,32 +29,40 @@ from bootstrap3.forms import render_field
|
|||
register = template.Library()
|
||||
|
||||
@register.simple_tag
|
||||
def bootstrap_form_typeahead(django_form, typeahead_fields, *args, **kwargs):
|
||||
def massive_bootstrap_form(form, mbf_fields, *args, **kwargs):
|
||||
"""
|
||||
Render a form where some specific fields are rendered using Typeahead.
|
||||
Using Typeahead really improves the performance, the speed and UX when
|
||||
dealing with very large datasets (select with 50k+ elts for instance).
|
||||
Render a form where some specific fields are rendered using Twitter
|
||||
Typeahead and/or splitree's Bootstrap Tokenfield to improve the performance, the
|
||||
speed and UX when dealing with very large datasets (select with 50k+ elts
|
||||
for instance).
|
||||
When the fields specified should normally be rendered as a select with
|
||||
single selectable option, Twitter Typeahead is used for a better display
|
||||
and the matching query engine. When dealing with multiple selectable
|
||||
options, sliptree's Bootstrap Tokenfield in addition with Typeahead.
|
||||
For convenience, it accepts the same parameters as a standard bootstrap
|
||||
can accept.
|
||||
|
||||
**Tag name**::
|
||||
|
||||
bootstrap_form_typeahead
|
||||
massive_bootstrap_form
|
||||
|
||||
**Parameters**:
|
||||
|
||||
form
|
||||
form (required)
|
||||
The form that is to be rendered
|
||||
|
||||
typeahead_fields
|
||||
mbf_fields (optional)
|
||||
A list of field names (comma separated) that should be rendered
|
||||
with typeahead instead of the default bootstrap renderer.
|
||||
with Typeahead/Tokenfield instead of the default bootstrap
|
||||
renderer.
|
||||
If not specified, all fields will be rendered as a normal bootstrap
|
||||
field.
|
||||
|
||||
bft_param
|
||||
A dict of parameters for the bootstrap_form_typeahead tag. The
|
||||
mbf_param (optional)
|
||||
A dict of parameters for the massive_bootstrap_form tag. The
|
||||
possible parameters are the following.
|
||||
|
||||
choices
|
||||
choices (optional)
|
||||
A dict of strings representing the choices in JS. The keys of
|
||||
the dict are the names of the concerned fields. The choices
|
||||
must be an array of objects. Each of those objects must at
|
||||
|
@ -71,7 +79,7 @@ def bootstrap_form_typeahead(django_form, typeahead_fields, *args, **kwargs):
|
|||
...
|
||||
}
|
||||
|
||||
engine
|
||||
engine (optional)
|
||||
A dict of strings representating the engine used for matching
|
||||
queries and possible values with typeahead. The keys of the
|
||||
dict are the names of the concerned fields. The string is valid
|
||||
|
@ -81,7 +89,7 @@ def bootstrap_form_typeahead(django_form, typeahead_fields, *args, **kwargs):
|
|||
Example :
|
||||
'engine' : {'field_A': 'new Bloodhound()', 'field_B': ..., ...}
|
||||
|
||||
match_func
|
||||
match_func (optional)
|
||||
A dict of strings representing a valid JS function used in the
|
||||
dataset to overload the matching engine. The keys of the dict
|
||||
are the names of the concerned fields. This function is used
|
||||
|
@ -100,7 +108,7 @@ def bootstrap_form_typeahead(django_form, typeahead_fields, *args, **kwargs):
|
|||
...
|
||||
}
|
||||
|
||||
update_on
|
||||
update_on (optional)
|
||||
A dict of list of ids that the values depends on. The engine
|
||||
and the typeahead properties are recalculated and reapplied.
|
||||
Example :
|
||||
|
@ -114,10 +122,10 @@ def bootstrap_form_typeahead(django_form, typeahead_fields, *args, **kwargs):
|
|||
|
||||
**Usage**::
|
||||
|
||||
{% bootstrap_form_typeahead
|
||||
{% massive_bootstrap_form
|
||||
form
|
||||
[ '<field1>[,<field2>[,...]]' ]
|
||||
[ {
|
||||
[ mbf_param = {
|
||||
[ 'choices': {
|
||||
[ '<field1>': '<choices1>'
|
||||
[, '<field2>': '<choices2>'
|
||||
|
@ -144,56 +152,55 @@ def bootstrap_form_typeahead(django_form, typeahead_fields, *args, **kwargs):
|
|||
|
||||
**Example**:
|
||||
|
||||
{% bootstrap_form_typeahead form 'ipv4' choices='[...]' %}
|
||||
{% massive_bootstrap_form form 'ipv4' choices='[...]' %}
|
||||
"""
|
||||
|
||||
t_fields = typeahead_fields.split(',')
|
||||
params = kwargs.get('bft_param', {})
|
||||
exclude = params.get('exclude', None)
|
||||
exclude = exclude.split(',') if exclude else []
|
||||
t_choices = params.get('choices', {})
|
||||
t_engine = params.get('engine', {})
|
||||
t_match_func = params.get('match_func', {})
|
||||
t_update_on = params.get('update_on', {})
|
||||
hidden = [h.name for h in django_form.hidden_fields()]
|
||||
fields = mbf_fields.split(',')
|
||||
param = kwargs.pop('mbf_param', {})
|
||||
exclude = param.get('exclude', '').split(',')
|
||||
choices = param.get('choices', {})
|
||||
engine = param.get('engine', {})
|
||||
match_func = param.get('match_func', {})
|
||||
update_on = param.get('update_on', {})
|
||||
hidden_fields = [h.name for h in form.hidden_fields()]
|
||||
|
||||
form = ''
|
||||
for f_name, f_value in django_form.fields.items() :
|
||||
html = ''
|
||||
for f_name, f_value in form.fields.items() :
|
||||
if not f_name in exclude :
|
||||
if f_name in t_fields and not f_name in hidden :
|
||||
f_bound = f_value.get_bound_field( django_form, f_name )
|
||||
if f_name in fields and not f_name in hidden_fields :
|
||||
f_bound = f_value.get_bound_field( form, f_name )
|
||||
f_value.widget = TextInput(
|
||||
attrs={
|
||||
'name': 'typeahead_'+f_name,
|
||||
'name': 'mbf_'+f_name,
|
||||
'placeholder': f_value.empty_label
|
||||
}
|
||||
)
|
||||
form += render_field(
|
||||
f_value.get_bound_field( django_form, f_name ),
|
||||
html += render_field(
|
||||
f_value.get_bound_field( form, f_name ),
|
||||
*args,
|
||||
**kwargs
|
||||
)
|
||||
form += render_tag(
|
||||
html += render_tag(
|
||||
'div',
|
||||
content = hidden_tag( f_bound, f_name ) +
|
||||
typeahead_js(
|
||||
mbf_js(
|
||||
f_name,
|
||||
f_value,
|
||||
f_bound,
|
||||
t_choices,
|
||||
t_engine,
|
||||
t_match_func,
|
||||
t_update_on
|
||||
choices,
|
||||
engine,
|
||||
match_func,
|
||||
update_on
|
||||
)
|
||||
)
|
||||
else:
|
||||
form += render_field(
|
||||
f_value.get_bound_field(django_form, f_name),
|
||||
html += render_field(
|
||||
f_value.get_bound_field( form, f_name ),
|
||||
*args,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
return mark_safe( form )
|
||||
return mark_safe( html )
|
||||
|
||||
def input_id( f_bound ) :
|
||||
""" The id of the HTML input element """
|
||||
|
@ -215,20 +222,20 @@ def hidden_tag( f_bound, f_name ):
|
|||
}
|
||||
)
|
||||
|
||||
def typeahead_js( f_name, f_value, f_bound,
|
||||
t_choices, t_engine, t_match_func, t_update_on ) :
|
||||
def mbf_js( f_name, f_value, f_bound,
|
||||
choices_, engine_, match_func_, update_on_ ) :
|
||||
""" The whole script to use """
|
||||
|
||||
choices = mark_safe( t_choices[f_name] ) if f_name in t_choices.keys() \
|
||||
choices = mark_safe( choices_[f_name] ) if f_name in choices_.keys() \
|
||||
else default_choices( f_value )
|
||||
|
||||
engine = mark_safe( t_engine[f_name] ) if f_name in t_engine.keys() \
|
||||
engine = mark_safe( engine_[f_name] ) if f_name in engine_.keys() \
|
||||
else default_engine ( f_name )
|
||||
|
||||
match_func = mark_safe(t_match_func[f_name]) \
|
||||
if f_name in t_match_func.keys() else default_match_func( f_name )
|
||||
match_func = mark_safe( match_func_[f_name] ) \
|
||||
if f_name in match_func_.keys() else default_match_func( f_name )
|
||||
|
||||
update_on = t_update_on[f_name] if f_name in t_update_on.keys() else []
|
||||
update_on = update_on_[f_name] if f_name in update_on_.keys() else []
|
||||
|
||||
js_content = (
|
||||
'var choices_{f_name} = {choices};'
|
|
@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
{% endcomment %}
|
||||
|
||||
{% load bootstrap3 %}
|
||||
{% load bootstrap_form_typeahead %}
|
||||
{% load massive_bootstrap_form %}
|
||||
|
||||
{% block title %}Création et modification d'un switch{% endblock %}
|
||||
|
||||
|
@ -47,16 +47,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% if topoform %}
|
||||
{% bootstrap_form_typeahead topoform 'switch_interface' %}
|
||||
{% massive_bootstrap_form topoform 'switch_interface' %}
|
||||
{% endif %}
|
||||
{% if machineform %}
|
||||
{% bootstrap_form_typeahead machineform 'user' %}
|
||||
{% massive_bootstrap_form machineform 'user' %}
|
||||
{% endif %}
|
||||
{% if interfaceform %}
|
||||
{% if i_bft_param %}
|
||||
{% bootstrap_form_typeahead interfaceform 'ipv4,machine' bft_param=i_bft_param %}
|
||||
{% massive_bootstrap_form interfaceform 'ipv4,machine' mbf_param=i_bft_param %}
|
||||
{% else %}
|
||||
{% bootstrap_form_typeahead interfaceform 'ipv4,machine' %}
|
||||
{% massive_bootstrap_form interfaceform 'ipv4,machine' %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if domainform %}
|
||||
|
|
|
@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
{% endcomment %}
|
||||
|
||||
{% load bootstrap3 %}
|
||||
{% load bootstrap_form_typeahead %}
|
||||
{% load massive_bootstrap_form %}
|
||||
|
||||
{% block title %}Création et modificationd 'utilisateur{% endblock %}
|
||||
|
||||
|
@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form_typeahead topoform 'room,related,machine_interface' %}
|
||||
{% massive_bootstrap_form topoform 'room,related,machine_interface' %}
|
||||
{%bootstrap_button "Créer ou modifier" button_type="submit" icon="ok" %}
|
||||
</form>
|
||||
<br />
|
||||
|
|
|
@ -51,7 +51,7 @@ from topologie.forms import AddPortForm, EditRoomForm, StackForm
|
|||
from users.views import form
|
||||
|
||||
from machines.forms import AliasForm, NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm
|
||||
from machines.views import generate_ipv4_bft_param
|
||||
from machines.views import generate_ipv4_mbf_param
|
||||
from preferences.models import AssoOption, GeneralOption
|
||||
|
||||
|
||||
|
@ -381,7 +381,7 @@ def new_switch(request):
|
|||
reversion.set_comment("Création")
|
||||
messages.success(request, "Le switch a été créé")
|
||||
return redirect("/topologie/")
|
||||
i_bft_param = generate_ipv4_bft_param( interface, False )
|
||||
i_bft_param = generate_ipv4_mbf_param( interface, False )
|
||||
return form({'topoform':switch, 'machineform': machine, 'interfaceform': interface, 'domainform': domain, 'i_bft_param': i_bft_param}, 'topologie/switch.html', request)
|
||||
|
||||
@login_required
|
||||
|
@ -442,7 +442,7 @@ def edit_switch(request, switch_id):
|
|||
)
|
||||
messages.success(request, "Le switch a bien été modifié")
|
||||
return redirect("/topologie/")
|
||||
i_bft_param = generate_ipv4_bft_param( interface_form, False )
|
||||
i_bft_param = generate_ipv4_mbf_param( interface_form, False )
|
||||
return form({'topoform':switch_form, 'machineform': machine_form, 'interfaceform': interface_form, 'domainform': domain_form, 'i_bft_param': i_bft_param}, 'topologie/switch.html', request)
|
||||
|
||||
@login_required
|
||||
|
|
|
@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
{% endcomment %}
|
||||
|
||||
{% load bootstrap3 %}
|
||||
{% load bootstrap_form_typeahead %}
|
||||
{% load massive_bootstrap_form %}
|
||||
|
||||
{% block title %}Création et modification d'utilisateur{% endblock %}
|
||||
|
||||
|
@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form_typeahead userform 'room' %}
|
||||
{% massive_bootstrap_form userform 'room' %}
|
||||
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
|
||||
</form>
|
||||
<br />
|
||||
|
|
Loading…
Reference in a new issue