Admin: add rule admin

This commit is contained in:
Jens Langhammer
2018-11-26 22:08:48 +01:00
parent 2aa12801a8
commit caf6580ccb
6 changed files with 166 additions and 5 deletions

View File

@ -0,0 +1,20 @@
"""passbook rule forms"""
from django import forms
from passbook.core.models import FieldMatcherRule
class FieldMatcherRuleForm(forms.ModelForm):
"""FieldMatcherRule Form"""
class Meta:
model = FieldMatcherRule
fields = ['name', 'action', 'negate', 'order',
'user_field', 'match_action', 'value', ]
widgets = {
'name': forms.TextInput(),
'user_field': forms.TextInput(),
'value': forms.TextInput(),
}

View File

@ -5,6 +5,7 @@ from logging import getLogger
import reversion
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils.translation import gettext as _
from model_utils.managers import InheritanceManager
from passbook.lib.models import CreatedUpdatedModel, UUIDModel
@ -128,17 +129,19 @@ class FieldMatcherRule(Rule):
MATCH_REGEXP = 'regexp'
MATCH_EXACT = 'exact'
MATCHES = (
(MATCH_STARTSWITH, MATCH_STARTSWITH),
(MATCH_ENDSWITH, MATCH_ENDSWITH),
(MATCH_ENDSWITH, MATCH_CONTAINS),
(MATCH_REGEXP, MATCH_REGEXP),
(MATCH_EXACT, MATCH_EXACT),
(MATCH_STARTSWITH, _('Starts with')),
(MATCH_ENDSWITH, _('Ends with')),
(MATCH_ENDSWITH, _('Contains')),
(MATCH_REGEXP, _('Regexp')),
(MATCH_EXACT, _('Exact')),
)
user_field = models.TextField()
match_action = models.CharField(max_length=50, choices=MATCHES)
value = models.TextField()
form = 'passbook.core.forms.rules.FieldMatcherRuleForm'
def __str__(self):
description = "%s, user.%s %s '%s'" % (self.name, self.user_field,
self.match_action, self.value)
@ -167,3 +170,8 @@ class FieldMatcherRule(Rule):
passes = not passes
LOGGER.debug("User got '%r'", passes)
return passes
class Meta:
verbose_name = _('Field matcher Rule')
verbose_name_plural = _('Field matcher Rules')