@@ -99,6 +99,7 @@ NOSE_ARGS = [
|
||||
]
|
||||
|
||||
MIDDLEWARE_CLASSES = [
|
||||
'sikweb.middleware.ForceDefaultLanguageMiddleware',
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.locale.LocaleMiddleware',
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class ForceDefaultLanguageMiddleware(object):
|
||||
"""
|
||||
Ignore Accept-Language HTTP headers
|
||||
|
||||
This will force the I18N machinery to always choose settings.LANGUAGE_CODE
|
||||
as the default initial language, unless another one is set via sessions or cookies
|
||||
|
||||
Should be installed *before* any middleware that checks request.META['HTTP_ACCEPT_LANGUAGE'],
|
||||
namely django.middleware.locale.LocaleMiddleware
|
||||
"""
|
||||
def process_request(self, request):
|
||||
if 'HTTP_ACCEPT_LANGUAGE' in request.META:
|
||||
del request.META['HTTP_ACCEPT_LANGUAGE']
|
||||
+18
-2
@@ -8,6 +8,19 @@ from webapp.models import CustomKaehmyRole, PresetKaehmyRole, BaseRole
|
||||
from webapp.models import OhlhafvChallenge, KaehmyForm, KaehmyMessage
|
||||
|
||||
|
||||
class KaehmyCheckboxSelectMultiple(forms.widgets.CheckboxSelectMultiple):
|
||||
option_template_name = 'kaehmy_checkbox_option.html'
|
||||
|
||||
def create_option(self, name, value, label, selected, index, subindex=None, attrs=None):
|
||||
dic = super(KaehmyCheckboxSelectMultiple, self).create_option(name, value, label, selected, index, subindex, attrs)
|
||||
description = PresetKaehmyRole.objects.get(id=value).description
|
||||
dic['description'] = description
|
||||
return dic
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(KaehmyCheckboxSelectMultiple, self).__init__(*args, **kwargs)
|
||||
|
||||
|
||||
class KaehmyForm_Form(forms.ModelForm):
|
||||
"""Class representing Kaehmy form."""
|
||||
|
||||
@@ -26,7 +39,7 @@ class KaehmyForm_Form(forms.ModelForm):
|
||||
self.fields["phone_number"].label = _('Phone number (not public)')
|
||||
|
||||
custom_roles_exist = CustomKaehmyRole.objects.all().exists()
|
||||
self.fields["custom_roles"].widget = forms.widgets.CheckboxSelectMultiple() if custom_roles_exist else forms.HiddenInput()
|
||||
self.fields["custom_roles"].widget = forms.widgets.CheckboxSelectMultiple if custom_roles_exist else forms.HiddenInput()
|
||||
self.fields["custom_roles"].help_text = ""
|
||||
self.fields["custom_roles"].label = _('Custom roles')
|
||||
self.fields["custom_roles"].queryset = CustomKaehmyRole.objects.all()
|
||||
@@ -35,7 +48,10 @@ class KaehmyForm_Form(forms.ModelForm):
|
||||
key = 'preset_roles_{}'.format(cat_id)
|
||||
qset = PresetKaehmyRole.objects.filter(category=cat_id).order_by('category', '-is_board')
|
||||
self.fields[key] = forms.ModelMultipleChoiceField(qset)
|
||||
self.fields[key].widget = forms.widgets.CheckboxSelectMultiple(attrs={'title': _('Preset roles'), 'name': 'preset_roles'})
|
||||
self.fields[key].widget = KaehmyCheckboxSelectMultiple(attrs={
|
||||
'title': _('Preset roles'),
|
||||
'name': 'preset_roles',
|
||||
})
|
||||
self.fields[key].help_text = ""
|
||||
self.fields[key].queryset = qset
|
||||
self.fields[key].label = _(category)
|
||||
|
||||
@@ -18,7 +18,14 @@
|
||||
<script src="{% static "js/lib/jquery-3.1.0.min.js" %}"></script>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous">
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
|
||||
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
|
||||
<script src="{% static "js/lib/underscore-min.js" %}"></script>
|
||||
|
||||
<script>
|
||||
$(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip()
|
||||
})
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
{{ preset_field.label }}
|
||||
</div>
|
||||
<div class="card-block">
|
||||
{% bootstrap_field preset_field show_label=False %}
|
||||
{% bootstrap_field preset_field show_label=False %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{% if wrap_label %}
|
||||
<label{% if widget.attrs.id %} for="{{ widget.attrs.id }}"{% endif %}>{% endif %}
|
||||
{% include "django/forms/widgets/input.html" %}
|
||||
{% if wrap_label %} {{ widget.label }}</label>{% endif %}
|
||||
<span class="fa fa-info-circle" data-toggle="tooltip" data-placement="right" title="{{ widget.description }}"></span>
|
||||
Reference in New Issue
Block a user