forked from DGNum/gestioCOF
Group permissions select multiple -> checkboxes
- Add handler for CheckboxSelectMultiple in form_field_snippet.html. - Add template filter "widget_type" to get widget class name. - Group permissions selection becomes easier.
This commit is contained in:
parent
e9073e2265
commit
ae27065626
5 changed files with 44 additions and 17 deletions
|
@ -8,7 +8,7 @@ from django.core.exceptions import ValidationError
|
||||||
from django.core.validators import MinLengthValidator
|
from django.core.validators import MinLengthValidator
|
||||||
from django.contrib.auth.models import User, Group, Permission
|
from django.contrib.auth.models import User, Group, Permission
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.forms import modelformset_factory
|
from django.forms import modelformset_factory, widgets
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from djconfig.forms import ConfigForm
|
from djconfig.forms import ConfigForm
|
||||||
|
@ -151,10 +151,25 @@ class UserGroupForm(forms.ModelForm):
|
||||||
model = User
|
model = User
|
||||||
fields = ['groups']
|
fields = ['groups']
|
||||||
|
|
||||||
|
|
||||||
|
class KFetPermissionsField(forms.ModelMultipleChoiceField):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
queryset = Permission.objects.filter(
|
||||||
|
content_type__in=ContentType.objects.filter(app_label="kfet"),
|
||||||
|
)
|
||||||
|
super().__init__(
|
||||||
|
queryset=queryset,
|
||||||
|
widget=widgets.CheckboxSelectMultiple,
|
||||||
|
*args, **kwargs
|
||||||
|
)
|
||||||
|
|
||||||
|
def label_from_instance(self, obj):
|
||||||
|
return obj.name
|
||||||
|
|
||||||
|
|
||||||
class GroupForm(forms.ModelForm):
|
class GroupForm(forms.ModelForm):
|
||||||
permissions = forms.ModelMultipleChoiceField(
|
permissions = KFetPermissionsField()
|
||||||
queryset= Permission.objects.filter(content_type__in=
|
|
||||||
ContentType.objects.filter(app_label='kfet')))
|
|
||||||
|
|
||||||
def clean_name(self):
|
def clean_name(self):
|
||||||
name = self.cleaned_data['name']
|
name = self.cleaned_data['name']
|
||||||
|
|
|
@ -608,3 +608,10 @@ thead .tooltip {
|
||||||
.ms-choice > div {
|
.ms-choice > div {
|
||||||
top: 4px !important;
|
top: 4px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Checkbox select multiple */
|
||||||
|
|
||||||
|
.checkbox-select-multiple label {
|
||||||
|
font-weight: normal;
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
|
@ -42,16 +42,6 @@
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
let perms_input = $("#id_permissions");
|
|
||||||
perms_input.removeClass("form-control");
|
|
||||||
perms_input.multipleSelect({
|
|
||||||
width: "100%",
|
|
||||||
filter: true,
|
|
||||||
allSelected: "Tou-te-s",
|
|
||||||
selectAllText: "Tou-te-s",
|
|
||||||
countSelected: "# sur %"
|
|
||||||
});
|
|
||||||
|
|
||||||
let $name_input = $("#id_name");
|
let $name_input = $("#id_name");
|
||||||
let raw_name = $name_input.val();
|
let raw_name = $name_input.val();
|
||||||
let prefix = "K-Fêt ";
|
let prefix = "K-Fêt ";
|
||||||
|
|
|
@ -3,7 +3,19 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="{{ field.id_for_label }}" class="col-sm-2 control-label">{{ field.label }}</label>
|
<label for="{{ field.id_for_label }}" class="col-sm-2 control-label">{{ field.label }}</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
{{ field|add_class:'form-control' }}
|
{% if field|widget_type == "checkboxselectmultiple" %}
|
||||||
|
<ul class="list-unstyled checkbox-select-multiple">
|
||||||
|
{% for choice in form.permissions %}
|
||||||
|
<li class="col-sm-6 col-lg-4">
|
||||||
|
<label for="{{ choice.id_for_label }}">
|
||||||
|
{{ choice.tag }} {{ choice.choice_label }}
|
||||||
|
</label>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
{{ field|add_class:'form-control' }}
|
||||||
|
{% endif %}
|
||||||
{% if field.errors %}
|
{% if field.errors %}
|
||||||
<span class="help-block">{{field.errors}}</span>
|
<span class="help-block">{{field.errors}}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -28,7 +28,6 @@ def highlight_user(user, q):
|
||||||
return highlight_text(text, q)
|
return highlight_text(text, q)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@register.filter(is_safe=True)
|
@register.filter(is_safe=True)
|
||||||
def highlight_clipper(clipper, q):
|
def highlight_clipper(clipper, q):
|
||||||
if clipper.fullname:
|
if clipper.fullname:
|
||||||
|
@ -38,8 +37,12 @@ def highlight_clipper(clipper, q):
|
||||||
return highlight_text(text, q)
|
return highlight_text(text, q)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@register.filter()
|
@register.filter()
|
||||||
def ukf(balance, is_cof):
|
def ukf(balance, is_cof):
|
||||||
grant = is_cof and (1 + kfet_config.subvention_cof / 100) or 1
|
grant = is_cof and (1 + kfet_config.subvention_cof / 100) or 1
|
||||||
return floor(balance * 10 * grant)
|
return floor(balance * 10 * grant)
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter()
|
||||||
|
def widget_type(field):
|
||||||
|
return field.field.widget.__class__.__name__
|
||||||
|
|
Loading…
Reference in a new issue