wip: per-domain policies

We new use a custom template to display the *content filter* tab.

see #260
This commit is contained in:
Antoine Nguyen
2012-06-25 10:37:03 +02:00
parent b3f70e130f
commit abd6ed08e1
5 changed files with 41 additions and 44 deletions
+2 -1
View File
@@ -190,7 +190,8 @@ def extra_domain_form(user, domain):
return []
return [
dict(
id="amavis", title=_("Content filter"), cls=DomainPolicyForm
id="amavis", title=_("Content filter"), cls=DomainPolicyForm,
formtpl="amavis/domain_content_filter.html"
)
]
+32 -5
View File
@@ -2,19 +2,46 @@
from django import forms
from models import Policy, Users
from modoboa.lib.formutils import InlineRadioSelect
from django.utils.translation import ugettext_lazy
def is_yes(v): return v == 'Y'
class CustomInputField(forms.CharField):
"""Custom <input> field
Most of the columns defined by amavis use the *char* type even if
they only support 2 values (Y/N). As we want to display them using
checkboxes, we need to make some modifications in order that
values are correctly interpreted.
"""
def validate(self, value):
value = "N" if not value else "Y"
super(CustomInputField, self).validate(value)
def clean(self, value):
value = "N" if not value else "Y"
return super(CustomInputField, self).clean(value)
class DomainPolicyForm(forms.ModelForm):
bypass_spam_checks = CustomInputField(label=ugettext_lazy("Spam filter"),
widget=forms.CheckboxInput(check_test=is_yes),
help_text=ugettext_lazy("enabled"))
bypass_virus_checks = CustomInputField(label=ugettext_lazy("Virus filter"),
widget=forms.CheckboxInput(check_test=is_yes),
help_text=ugettext_lazy("enabled"))
bypass_banned_checks = CustomInputField(label=ugettext_lazy("Banned filter"),
widget=forms.CheckboxInput(check_test=is_yes),
help_text=ugettext_lazy("enabled"))
spam_modifies_subj = CustomInputField(label=ugettext_lazy("Spam marker"),
widget=forms.CheckboxInput(check_test=is_yes),
help_text=ugettext_lazy("tag subject"))
class Meta:
model = Policy
fields = ('bypass_virus_checks', 'bypass_spam_checks',
'spam_tag2_level', 'spam_modifies_subj',
'spam_kill_level', 'bypass_banned_checks')
widgets = {
'bypass_spam_checks' : InlineRadioSelect(),
'bypass_virus_checks' : InlineRadioSelect(),
'bypass_banned_checks' : InlineRadioSelect(),
'spam_modifies_subj' : InlineRadioSelect(attrs={'class' : 'span1'}),
'spam_tag2_level' : forms.TextInput(attrs={'class' : 'span1'}),
'spam_kill_level' : forms.TextInput(attrs={'class' : 'span1'}),
}
+4 -16
View File
@@ -75,23 +75,11 @@ class Policy(models.Model):
spam_lover = models.CharField(max_length=3, blank=True)
banned_files_lover = models.CharField(max_length=3, blank=True)
bad_header_lover = models.CharField(max_length=3, blank=True)
bypass_virus_checks = models.CharField(
ugettext_lazy("Enable virus filter"), max_length=3,
choices=(('Y', 'yes'), ('N', 'no')), blank=False, default='Y'
)
bypass_spam_checks = models.CharField(
ugettext_lazy("Enable spam filter"), max_length=3,
choices=(('Y', 'yes'), ('N', 'no')), blank=False, default='Y'
)
bypass_banned_checks = models.CharField(
ugettext_lazy("Enable banned filter"), max_length=3,
choices=(('Y', 'yes'), ('N', 'no')), blank=False, default='Y'
)
bypass_virus_checks = models.CharField(max_length=3, blank=True)
bypass_spam_checks = models.CharField(max_length=3, blank=True)
bypass_banned_checks = models.CharField(max_length=3, blank=True)
bypass_header_checks = models.CharField(max_length=3, blank=True)
spam_modifies_subj = models.CharField(
ugettext_lazy("Indicate spam in subject"),
choices=(('Y', 'yes'), ('N', 'no')), max_length=3, blank=False, default='Y'
)
spam_modifies_subj = models.CharField(max_length=3, blank=True)
virus_quarantine_to = models.CharField(max_length=192, blank=True)
spam_quarantine_to = models.CharField(max_length=192, blank=True)
banned_quarantine_to = models.CharField(max_length=192, blank=True)
-20
View File
@@ -169,23 +169,3 @@ class DomainNameField(forms.CharField):
def clean(self, value):
value = self.to_python(value).strip()
return super(DomainNameField, self).clean(value)
class BootstrapRadioInput(forms.widgets.RadioInput):
def __unicode__(self):
if 'id' in self.attrs:
label_for = ' for="%s_%s"' % (self.attrs['id'], self.index)
else:
label_for = ''
choice_label = conditional_escape(force_unicode(self.choice_label))
return mark_safe(u'<label%s class="radio inline">%s %s</label>' % (label_for, self.tag(), choice_label))
class InlineRadioFieldRenderer(forms.widgets.RadioFieldRenderer):
def __iter__(self):
for i, choice in enumerate(self.choices):
yield BootstrapRadioInput(self.name, self.value, self.attrs.copy(), choice, i)
def render(self):
return mark_safe(u'\n%s\n' % u'\n'.join([u'%s' % force_unicode(w) for w in self]))
class InlineRadioSelect(forms.widgets.RadioSelect):
renderer = InlineRadioFieldRenderer
+3 -2
View File
@@ -1,7 +1,8 @@
{% load i18n %}
<div class="control-group {% if field.errors %}error{% endif %}"{% if hidden %}style="display: none"{% endif %}>
{% if field.label %}<label class="control-label" for="id_{{ field.html_name }}">{{ field.label }}</label>{% endif %}{% if field.help_text %}<a href="#" class="help pull-left" data-original-title="{% trans 'Help:' %} {{ field.label }}" data-content="{{ field.help_text }}" rel="popover">?</a>{% endif %}
{% if field.label %}<label class="control-label" for="id_{{ field.html_name }}">{{ field.label }}</label>{% endif %}{% if help_display_mode == "tooltip" and field.help_text %}<a href="#" class="help pull-left" data-original-title="{% trans 'Help:' %} {{ field.label }}" data-content="{{ field.help_text }}" rel="popover">?</a>{% endif %}
<div class="controls spaced">
{{ field }}{% if field.errors %}<p class="help-block">{% for error in field.errors %}{{ error|safe }}{% endfor %}</p>{% endif %}
{{ field }}{% if help_display_mode == "inline" and field.help_text %}<span class="help-inline">{{ field.help_text }}</span>{% endif %}
{% if field.errors %}<p class="help-block">{% for error in field.errors %}{{ error|safe }}{% endfor %}</p>{% endif %}
</div>
</div>