class Art17LocalRegisterForm(Art17RegisterFormBase, ConfirmRegisterForm): id = TextField('Username', validators=[ Required("User ID is required"), check_duplicate_with_local_db, check_duplicate_with_ldap ]) email = CustomEmailTextField('Email address', validators=[ Required("Email is required"), email_validator, unique_user_email ])
class Art17AdminEditUserForm(Art17RegisterFormBase, Form): active = BooleanField( 'Active', description='User is allowed to login and gain roles.') email = TextField('Email address', validators=[ Required("Email is required"), email_validator, custom_unique_user_email ])
class Art17RegisterFormBase(object): name = TextField('Full name', validators=[Required("Full name is required")]) institution = TextField('Institution', validators=[Optional()]) abbrev = TextField('Abbrev.') MS = TextField(widget=HiddenInput()) country_options = SelectField('Member State') other_country = TextField('Other country') qualification = TextField('Qualification', validators=[Optional()]) def __init__(self, *args, **kwargs): super(Art17RegisterFormBase, self).__init__(*args, **kwargs) dataset = (Dataset.query.order_by(Dataset.id.desc()).first()) countries = (DicCountryCode.query .with_entities(DicCountryCode.codeEU, DicCountryCode.name) .filter(DicCountryCode.dataset_id == dataset.id) .distinct() .order_by(DicCountryCode.name) .all()) self.country_options.choices = ( [('', '')] + countries + [('--', 'Choose another country ...')] ) self.obj = kwargs.get('obj', None)
class Art17LDAPRegisterForm(Art17RegisterFormBase, RegisterFormMixin, Form): email = TextField( 'Email address', validators=[Required("Email is required"), email_validator])
class BaseUserForm(Form): existing_email = HiddenField(u'Existing Email', default=None) def __init__(self, *args, **kwargs): super(BaseUserForm, self).__init__(*args, **kwargs) if self.existing_email.data is None: self.existing_email.data = self.email.data InviteForm = model_form(User, base_class=Form, only=['email'], field_args={ 'email': { 'validators': [Required(), Email(), unique_username] } }) UserForm = model_form(User, base_class=BaseUserForm, only=['email', 'username'], field_args={ 'email': { 'validators': [Required(), Email(), same_or_unique_username] }, 'username': { 'validators': [Required()]
class ExtendedRegisterForm(RegisterForm): username = TextField('Username', [Required(), unique_username])
from ..models import User class Subdomain(ValidatorMixin): valid_pattern = re.compile('^[\w_-]+$') def __init__(self, message=None): self.message = message def __call__(self, form, field): if not self.valid_pattern.match(field.data): raise ValidationError(self.message) subdomain_required = Required(message='SUBDOMAIN_NOT_PROVIDED') subdomain_validator = Subdomain(message='INVALID_SUBDOMAIN') def unique_user_subdomain(form, field): if User.query.filter_by(subdomain=field.data).first(): msg = get_message('SUBDOMAIN_ALREADY_ASSOCIATED', subdomain=field.data)[0] raise ValidationError(msg) class RegisterForm(ConfirmRegisterForm, NextFormMixin): subdomain = StringField('Subdomain', validators=[ subdomain_required, subdomain_validator, unique_user_subdomain