Git Product home page Git Product logo

django-easy-validator's People

Contributors

youngershen avatar youngershen32 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

django-easy-validator's Issues

Extra rules overlapping default rules

Hey guys, in validator file has an overlapping extra_rules. Look this case:

New rule:
`class UniqueCityCacheScheduler(BaseRule):
name = 'unique_city_cache_scheduler'
message = 'this city already scheduled, to change data delete or update then'
description = 'check if already exist city in cache_agendamentos_booking_table'

def check_value(self):
    self.status = True if self.field_value == 'test' else False

def check_null(self):
    pass`

Validator class (I have and adapter):
`class HotelCacheCreateScheduleRequest(RequestValidatorAdapter):

def __init__(self):
    self.request_json: HotelCacheCreateScheduleRequestData = None
    extra_rules = { UniqueCityCacheScheduler.get_name(): UniqueCityCacheScheduler}
    super().__init__(data=None, messages={}, interface=HotelCacheCreateScheduleRequestData,
                     extra_rules=extra_rules)

"""'
consts structure validators rules
"""
city = "required|max_length:255"
city_id = "unique_city_cache_scheduler"
checkin_range = city_id
checkout_range = checkin_range
update_minutes_interval = checkin_range`

In function _get_origin_rule of file validators.py:1183
def _get_origin_rule(self, name): # here code will not get default rules not seted rule = self.extra_rules.get(name, None) if self.extra_rules else default_rules.get(name, None) if not rule: raise RuleNotFoundError(name) else: return rule

Suggestion:
def _get_origin_rule(self, name): # here code will not get default rules not seted rule = self.extra_rules.get(name, None) if self.extra_rules.get(name, None) else default_rules.get(name, None) if not rule: raise RuleNotFoundError(name) else: return rule

Use of | in regex

When using regex syntax with | as separator brakes. For example on such regex ^\d+(,\d+)*(\|\d+(,\d+)*)*$. I'm forced to use "advanced" rule and implement my own regex rule:

class GroupedIds(BaseRule):
    name = 'grouped_ids'
    regex = r'^\d+(,\d+)*(\|\d+(,\d+)*)*$'
    message = _('{FIELD} is not a grouped integers. '
                'Example group: 1,2,3|4,5|99, where 1, 2 and 3 are in the first group')
    description = _('Check if current value is a group of integers separated by comma inside groups. '
                    'Groups are separated with  | ')

    def check_null(self):
        pass

    def check_value(self):
        self.status = True if re.match(self.regex, self.field_value) else False

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.