from wtforms.validators import StopValidation
from app.models import User


class UniqueUsername(object):

    def __init__(self, message=None):
        self.message = message

    def __call__(self, form, field):
        user = User.query.filter_by(username=field.data).first()
        if user is not None:
            if self.message is None:
                message = field.gettext('Username must be unique.')
            else:
                message = self.message
            field.errors[:] = []
            raise StopValidation(message)

66807ecabe06961bb18d2baee9f17957a5e553d5
<mask token>


class UniqueUsername(object):
    <mask token>
    <mask token>

<mask token>


class UniqueUsername(object):
    <mask token>

    def __call__(self, form, field):
        user = User.query.filter_by(username=field.data).first()
        if user is not None:
            if self.message is None:
                message = field.gettext('Username must be unique.')
            else:
                message = self.message
            field.errors[:] = []
            raise StopValidation(message)

<mask token>


class UniqueUsername(object):

    def __init__(self, message=None):
        self.message = message

    def __call__(self, form, field):
        user = User.query.filter_by(username=field.data).first()
        if user is not None:
            if self.message is None:
                message = field.gettext('Username must be unique.')
            else:
                message = self.message
            field.errors[:] = []
            raise StopValidation(message)

from wtforms.validators import StopValidation
from app.models import User


class UniqueUsername(object):

    def __init__(self, message=None):
        self.message = message

    def __call__(self, form, field):
        user = User.query.filter_by(username=field.data).first()
        if user is not None:
            if self.message is None:
                message = field.gettext('Username must be unique.')
            else:
                message = self.message
            field.errors[:] = []
            raise StopValidation(message)
