class EditProfileSchema(CSRFSchema): display_name = colander.SchemaNode( colander.String(), missing=None, validator=validators.Length(max=DISPLAY_NAME_MAX_LENGTH), title=_('Display name')) description = colander.SchemaNode(colander.String(), missing=None, validator=validators.Length(max=250), widget=deform.widget.TextAreaWidget( max_length=250, rows=4, ), title=_('Description')) location = colander.SchemaNode(colander.String(), missing=None, validator=validators.Length(max=100), title=_('Location')) link = colander.SchemaNode(colander.String(), missing=None, validator=colander.All( validators.Length(max=250), validate_url), title=_('Link'))
class EditProfileSchema(CSRFSchema): display_name = colander.SchemaNode( colander.String(), missing=None, validator=validators.Length(max=DISPLAY_NAME_MAX_LENGTH), title=_('Display name')) description = colander.SchemaNode(colander.String(), missing=None, validator=validators.Length(max=250), widget=deform.widget.TextAreaWidget( max_length=250, rows=4, ), title=_('Description')) location = colander.SchemaNode(colander.String(), missing=None, validator=validators.Length(max=100), title=_('Location')) link = colander.SchemaNode(colander.String(), missing=None, validator=colander.All( validators.Length(max=250), validate_url), title=_('Link')) orcid = colander.SchemaNode( colander.String(), missing=None, validator=validate_orcid, title=_('ORCID'), hint= _('ORCID provides a persistent identifier for researchers (see orcid.org).' ))
class GroupSchema(CSRFSchema): """The schema for the create-a-new-group form.""" name = colander.SchemaNode( colander.String(), title=_("Name"), validator=colander.All( validators.Length(min=GROUP_NAME_MIN_LENGTH, max=GROUP_NAME_MAX_LENGTH), unblacklisted_group_name_slug), widget=deform.widget.TextInputWidget( autofocus=True, css_class="group-form__name-input js-group-name-input", disable_autocomplete=True, label_css_class="group-form__name-label", max_length=GROUP_NAME_MAX_LENGTH)) description = colander.SchemaNode( colander.String(), title=_("Description"), validator=validators.Length(max=GROUP_DESCRIPTION_MAX_LENGTH), missing=None, widget=deform.widget.TextAreaWidget( css_class="group-form__description-input", label_css_class="group-form__description-label", min_length=0, max_length=GROUP_DESCRIPTION_MAX_LENGTH))
class RegisterSchema(CSRFSchema): username = colander.SchemaNode( colander.String(), validator=colander.All( validators.Length(min=USERNAME_MIN_LENGTH, max=USERNAME_MAX_LENGTH), colander.Regex(USERNAME_PATTERN, msg=_( "Must have only letters, numbers, periods, and " "underscores.")), unique_username, unblacklisted_username, ), title=_('Username'), hint=_('Must be between {min} and {max} characters, containing only ' 'letters, numbers, periods, and underscores.').format( min=USERNAME_MIN_LENGTH, max=USERNAME_MAX_LENGTH), widget=deform.widget.TextInputWidget(autofocus=True), ) email = email_node(title=_('Email address')) password = new_password_node(title=_('Password')) privacy_accepted = colander.SchemaNode( colander.Boolean(), description=Markup(_privacy_accepted_message()), validator=privacy_acceptance_validator, widget=deform.widget.CheckboxWidget(omit_label=True, css_class='form-checkbox--inline'), )
def new_password_node(**kwargs): """Return a Colander schema node for a new user password.""" kwargs.setdefault('widget', deform.widget.PasswordWidget()) return colander.SchemaNode( colander.String(), validator=validators.Length(min=PASSWORD_MIN_LENGTH), **kwargs)
def email_node(**kwargs): """Return a Colander schema node for a new user email.""" return colander.SchemaNode( colander.String(), validator=colander.All( validators.Length(max=EMAIL_MAX_LENGTH), validators.Email(), unique_email, ), widget=deform.widget.TextInputWidget(template='emailinput'), **kwargs)
class CreateAdminGroupSchema(CSRFSchema): group_type = colander.SchemaNode( colander.String(), title=_('Group Type'), widget=SelectWidget(values=(('', _('Select')), ) + VALID_GROUP_TYPES), validator=group_type_validator, ) name = colander.SchemaNode( colander.String(), title=_('Group Name'), validator=validators.Length(min=GROUP_NAME_MIN_LENGTH, max=GROUP_NAME_MAX_LENGTH), ) authority = colander.SchemaNode( colander.String(), title=_('Authority'), description=_("The group's authority"), hint=_('The authority within which this group should be created.' ' Note that only users within the designated authority' ' will be able to be associated with this group (as' ' creator or member).')) creator = colander.SchemaNode( colander.String(), title=_('Creator'), description=_("Username for this group's creator"), hint=_( 'This user will be set as the "creator" of the group. Note that' ' the user must be on the same authority as the group authority'), ) description = colander.SchemaNode( colander.String(), title=_('Description'), description=_('Optional group description'), validator=colander.Length(max=GROUP_DESCRIPTION_MAX_LENGTH), widget=TextAreaWidget(rows=3), missing=None) origins = colander.SequenceSchema( colander.Sequence(), colander.SchemaNode(colander.String(), name='origin', validator=colander.url), title=_('Scope Origins'), hint=_( 'Origins where this group appears (e.g. "https://example.com")'), widget=SequenceWidget(add_subitem_text_template=_('Add origin'), min_len=1), validator=colander.Length( min=1, min_err=_('At least one origin must be specified')))
class CreateAdminGroupSchema(CSRFSchema): group_type = colander.SchemaNode( colander.String(), title=_('Group Type'), widget=SelectWidget(values=(('', _('Select')), ) + VALID_GROUP_TYPES), validator=colander.OneOf([key for key, title in VALID_GROUP_TYPES])) name = colander.SchemaNode( colander.String(), title=_('Group Name'), validator=validators.Length(min=GROUP_NAME_MIN_LENGTH, max=GROUP_NAME_MAX_LENGTH), ) authority = colander.SchemaNode( colander.String(), title=_('Authority'), description=_("The group's authority"), hint=_('The authority within which this group should be created.' ' Note that only users within the designated authority' ' will be able to be associated with this group (as' ' creator or member).')) creator = colander.SchemaNode( colander.String(), title=_('Creator'), description=_("Username for this group's creator"), hint=_( 'This user will be set as the "creator" of the group. Note that' ' the user must be on the same authority as the group authority'), ) description = colander.SchemaNode( colander.String(), title=_('Description'), description=_('Optional group description'), validator=colander.Length(max=GROUP_DESCRIPTION_MAX_LENGTH), widget=TextAreaWidget(rows=3), missing=None) origins = colander.SchemaNode( colander.String(), title=_('Scope Origins'), widget=TextAreaWidget(rows=5), hint=_( 'Enter scope origins (e.g. "http://www.foo.com"), one per line'), preparer=_split_origins, missing=None)
class LegacyGroupSchema(CSRFSchema): """The legacy schema for the create-a-new-group form.""" name = colander.SchemaNode( colander.String(), title=_("What do you want to call the group?"), validator=validators.Length(min=GROUP_NAME_MIN_LENGTH, max=GROUP_NAME_MAX_LENGTH), widget=deform.widget.TextInputWidget( autofocus=True, css_class="group-form__name-input js-group-name-input", disable_autocomplete=True, label_css_class="group-form__name-label", max_length=GROUP_NAME_MAX_LENGTH, placeholder=_("Group Name")))
def group_schema(autofocus_name=False): """Return a schema for the form for creating or editing a group.""" schema = CSRFSchema() name = colander.SchemaNode( colander.String(), name='name', title=_("Name"), validator=colander.All( validators.Length(min=GROUP_NAME_MIN_LENGTH, max=GROUP_NAME_MAX_LENGTH), unblacklisted_group_name_slug), widget=deform.widget.TextInputWidget( autofocus=autofocus_name, show_required=True, css_class="group-form__name-input js-group-name-input", disable_autocomplete=True, label_css_class="group-form__name-label", max_length=GROUP_NAME_MAX_LENGTH)) description = colander.SchemaNode( colander.String(), name='description', title=_("Description"), validator=validators.Length(max=GROUP_DESCRIPTION_MAX_LENGTH), missing=None, widget=deform.widget.TextAreaWidget( css_class="group-form__description-input", label_css_class="group-form__description-label", min_length=0, max_length=GROUP_DESCRIPTION_MAX_LENGTH)) schema.add(name) schema.add(description) return schema
class RegisterSchema(CSRFSchema): username = colander.SchemaNode( colander.String(), validator=colander.All( validators.Length(min=USERNAME_MIN_LENGTH, max=USERNAME_MAX_LENGTH), colander.Regex(USERNAME_PATTERN, msg=_( "Must have only letters, numbers, periods, and " "underscores.")), unique_username, unblacklisted_username, ), title=_('Username'), hint=_('Must be between {min} and {max} characters, containing only ' 'letters, numbers, periods, and underscores.').format( min=USERNAME_MIN_LENGTH, max=USERNAME_MAX_LENGTH), widget=deform.widget.TextInputWidget(autofocus=True), ) email = email_node(title=_('Email address')) password = new_password_node(title=_('Password'))
class CreateAdminGroupSchema(CSRFSchema): group_type = colander.SchemaNode( colander.String(), title=_('Group Type'), widget=SelectWidget(values=(('', _('Select')), ) + VALID_GROUP_TYPES)) name = colander.SchemaNode( colander.String(), title=_('Group Name'), validator=validators.Length(min=GROUP_NAME_MIN_LENGTH, max=GROUP_NAME_MAX_LENGTH), ) authority = colander.SchemaNode( colander.String(), title=_('Authority'), description=_("The group's authority"), hint=_('The authority within which this group should be created.' ' Note that only users within the designated authority' ' will be able to be associated with this group (as' ' creator or member).')) creator = colander.SchemaNode( colander.String(), title=_('Creator'), description=_("Username for this group's creator"), hint=_( 'This user will be set as the "creator" of the group. Note that' ' the user must be on the same authority as the group authority'), ) description = colander.SchemaNode( colander.String(), title=_('Description'), description=_('Optional group description'), validator=colander.Length(max=GROUP_DESCRIPTION_MAX_LENGTH), widget=TextInputWidget(rows=3), missing=None)
class OrganizationSchema(CSRFSchema): authority = colander.SchemaNode( colander.String(), title=_('Authority'), ) name = colander.SchemaNode( colander.String(), title=_('Name'), validator=validators.Length(ORGANIZATION_NAME_MIN_CHARS, ORGANIZATION_NAME_MAX_CHARS), widget=TextInputWidget(max_length=ORGANIZATION_NAME_MAX_CHARS), ) logo = colander.SchemaNode( colander.String(), title=_('Logo'), hint=_('SVG markup for logo. You can get this from a .svg file by' ' opening it in a text editor and copying the contents.'), widget=TextAreaWidget(rows=5), validator=validate_logo, missing=None, )
class CreateAdminGroupSchema(CSRFSchema): def __init__(self, *args): super(CreateAdminGroupSchema, self).__init__(validator=group_creator_validator, *args) group_type = colander.SchemaNode( colander.String(), title=_('Group Type'), widget=SelectWidget( values=(('', _('Select')),) + VALID_GROUP_TYPES ), validator=group_type_validator, ) name = colander.SchemaNode( colander.String(), title=_('Group Name'), validator=validators.Length(min=GROUP_NAME_MIN_LENGTH, max=GROUP_NAME_MAX_LENGTH), widget=TextInputWidget(max_length=GROUP_NAME_MAX_LENGTH), ) organization = colander.SchemaNode( colander.String(), title=_('Organization'), description=_('Organization which this group belongs to'), widget=group_organization_select_widget, ) creator = colander.SchemaNode( colander.String(), title=_('Creator'), description=_("Username for this group's creator"), hint=_('This user will be set as the "creator" of the group. Note that' ' the user must be on the same authority as the group authority'), ) description = colander.SchemaNode( colander.String(), title=_('Description'), description=_('Optional group description'), validator=colander.Length(max=GROUP_DESCRIPTION_MAX_LENGTH), widget=TextAreaWidget(rows=3, max_length=GROUP_DESCRIPTION_MAX_LENGTH), missing=None ) origins = colander.SequenceSchema( colander.Sequence(), colander.SchemaNode(colander.String(), name='origin', validator=colander.url), title=_('Scope Origins'), hint=_('Origins where this group appears (e.g. "https://example.com")'), widget=SequenceWidget(add_subitem_text_template=_('Add origin'), min_len=1), validator=colander.Length(min=1, min_err=_('At least one origin must be specified')) ) members = colander.SequenceSchema( colander.Sequence(), colander.SchemaNode(colander.String(), name='member', validator=member_exists_validator), title=_('Members'), hint=_('Add more members by their username to this group'), widget=SequenceWidget(add_subitem_text_template=_('Add member')), missing=None )