From 49c77c9474fb3a5212495eb3cf78c27afc0a0253 Mon Sep 17 00:00:00 2001 From: bashmak Date: Thu, 18 May 2017 12:00:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=82=D0=B8=D0=BF=20=D0=B4=D0=BB=D1=8F=20=D0=B4=D0=B8=D0=BD?= =?UTF-8?q?=D0=B0=D0=BC=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abonapp/models.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/abonapp/models.py b/abonapp/models.py index a9433b2..0ac2a8e 100644 --- a/abonapp/models.py +++ b/abonapp/models.py @@ -9,11 +9,7 @@ from agent import Transmitter, AbonStruct, TariffStruct, NasFailedResult, NasNet from tariff_app.models import Tariff from accounts_app.models import UserProfile from .fields import MACAddressField -from mydefs import MyGenericIPAddressField, ip2int - - -class LogicError(Exception): - pass +from mydefs import MyGenericIPAddressField, ip2int, LogicError, ip_addr_regex class AbonGroup(models.Model): @@ -165,12 +161,24 @@ class ExtraFieldsModel(models.Model): DYNAMIC_FIELD_TYPES = ( ('int', _('Digital field')), ('str', _('Text field')), - ('dbl', _('Floating field')) + ('dbl', _('Floating field')), + ('ipa', _('Ip Address')) ) - field_type = models.CharField(max_length=3, choices=DYNAMIC_FIELD_TYPES) + title = models.CharField(max_length=16, default='no title') + field_type = models.CharField(max_length=3, choices=DYNAMIC_FIELD_TYPES, default='str') data = models.CharField(max_length=64, null=True, blank=True) + def get_regexp(self): + if self.field_type == 'int': + return r'^[+-]?\d+$' + elif self.field_type == 'dbl': + return r'^[-+]?\d+[,.]\d+$' + elif self.field_type == 'str': + return r'^[a-zA-ZА-Яа-я0-9]+$' + elif self.field_type == 'ipa': + return ip_addr_regex + def clean(self): d = self.data if self.field_type == 'int':