class ProfileForm(wtf.Form): nickname = wtf.TextField('nickname', validators=[wtf.Required(message=u'请填写昵称')]) slug = wtf.TextField( 'slug', validators=[ wtf.Regexp(regex=r'^([a-zA-Z][a-zA-Z0-9_-]{4,23})?$', message=u'长度应为5~24位,仅能包含数字、英文字母及下划线(_)和减号(-),并且需要以字母开头') ]) phone = wtf.TextField( 'phone', validators=[wtf.Regexp(regex=r'^(1\d{10})?$', message=u'请输入有效的手机号码')]) phone_status = wtf.RadioField('phone_status', choices=[('0', u'不公开'), ('1', u'公开'), ('2', u'仅向会员公开')], default='0') # photo = db.Column(db.String(255), nullable=True) # 存一张照片,既然有线下的聚会的,总得认得人才行 motoo = wtf.TextAreaField( 'motoo', validators=[wtf.Length(min=0, max=255, message=u'座右铭最多为255个字符')]) introduction = wtf.TextAreaField( 'introduction', validators=[wtf.Length(min=0, max=3000, message=u'个人介绍最多为3000个字')]) def __init__(self, *args, **kargs): wtf.Form.__init__(self, *args, **kargs) self.user = None
class ParticipantForm(Form): skill_levels = [('Beginner', 'Beginner'), ('Intermediate', 'Intermediate'), ('Advanced', 'Advanced')] reason_to_join = RichTextField( "Reason To Join", description="Why would you love to join Hacknight", validators=[wtf.Required()], content_css="/static/css/editor.css") phone_no = wtf.TextField( "Telephone No", description="Telephone No", validators=[wtf.Required(), wtf.validators.length(max=15)]) email = wtf.html5.EmailField( "Email", description="Email Address, We will never spam you .", validators=[wtf.Required(), wtf.validators.length(max=80)]) job_title = wtf.TextField( "Job Title", description="What is your job title? E.G: Senior Software " "Engineer at Awesome company", validators=[wtf.Required(), wtf.validators.length(max=120)]) company = wtf.TextField( "Company", description="Company Name", validators=[wtf.Optional(), wtf.validators.length(max=1200)]) skill_level = wtf.RadioField("Skill Level", description="What is your skill level?", choices=skill_levels)
class ProjectForm(Form): title = wtf.TextField("Title", description="Title of the project", validators=[wtf.Required("A title is required"), wtf.validators.length(max=250)]) blurb = wtf.TextField("Blurb", description="A single-line summary of the project", validators=[wtf.Required("A blurb is required"), wtf.validators.length(max=250)]) description = RichTextField(u"Description", description="Detailed description of your project", content_css="/static/css/editor.css") participating = wtf.RadioField("Will you be participating?", default=1, coerce=getbool, choices=[(1, u"I will be working on this project"), (0, u"I’m proposing an idea for others to take up")])
class ProposalForm(wtf.Form): email = wtf.html5.EmailField('Your email address', validators=[wtf.Required()], description="An email address we can contact you at. "\ "Not displayed anywhere") phone = wtf.TextField('Phone number', validators=[wtf.Required()], description="A phone number we can call you at to discuss your proposal, if required. " "Will not be displayed") speaking = wtf.RadioField("Are you speaking?", coerce=int, choices=[(1, u"I will be speaking"), (0, u"I’m proposing a topic for someone to speak on")]) title = wtf.TextField('Title', validators=[wtf.Required()], description="The title of your session") section = wtf.QuerySelectField('Section', get_label='title', validators=[wtf.Required()], widget=wtf.ListWidget(prefix_label=False), option_widget=wtf.RadioInput()) objective = wtf.TextAreaField('Objective', validators=[wtf.Required()], description="What is the expected benefit for someone attending this?") session_type = wtf.RadioField('Session type', validators=[wtf.Required()], choices=[ ('Lecture', 'Lecture'), ('Demo', 'Demo'), ('Tutorial', 'Tutorial'), ('Workshop', 'Workshop'), ('Discussion', 'Discussion'), ('Panel', 'Panel'), ]) technical_level = wtf.RadioField('Technical level', validators=[wtf.Required()], choices=[ ('Beginner', 'Beginner'), ('Intermediate', 'Intermediate'), ('Advanced', 'Advanced'), ]) description = wtf.TextAreaField('Description', validators=[wtf.Required()], description="A detailed description of the session") requirements = wtf.TextAreaField('Requirements', description="For workshops, what must participants bring to the session?") slides = wtf.html5.URLField('Slides', validators=[wtf.Optional(), wtf.URL()], description="Link to your slides. These can be just an outline initially. "\ "If you provide a Slideshare link, we'll embed slides in the page") links = wtf.TextAreaField('Links', description="Other links, one per line. Provide links to your profile and "\ "slides and videos from your previous sessions; anything that'll help "\ "folks decide if they want to attend your session") bio = wtf.TextAreaField('Speaker bio', validators=[wtf.Required()], description="Tell us why you are the best person to be taking this session")
class SendEmailForm(Form): subject = wtf.TextField( "Subject", description="Subject for the email", validators=[wtf.Required(), wtf.validators.length(max=250)]) message = RichTextField( "Message", description= "Email message, only `FULLNAME` will be replaced with participant fullname", validators=[wtf.Required()]) send_to = wtf.RadioField("Send email to", default=2, coerce=int)
class TeamPermissionAssignForm(Form): """ Assign permissions to a team """ team_id = wtf.RadioField( "Team", validators=[wtf.Required()], description='Select a team to assign permissions to') perms = wtf.SelectMultipleField("Permissions", validators=[wtf.Required()]) def validate_team_id(self, field): teams = [team for team in self.org.teams if team.userid == field.data] if len(teams) != 1: raise wtf.ValidationError("Unknown team") self.team = teams[0]
class RegisterClientForm(Form): """ Register a new OAuth client application """ title = wtf.TextField('Application title', validators=[wtf.Required()], description="The name of your application") description = wtf.TextAreaField( 'Description', validators=[wtf.Required()], description="A description to help users recognize your application") client_owner = wtf.RadioField( 'Owner', validators=[wtf.Required()], description= "User or organization that owns this application. Changing the owner " "will revoke all currently assigned permissions for this app") website = wtf.html5.URLField( 'Application website', validators=[wtf.Required(), wtf.URL()], description="Website where users may access this application") redirect_uri = wtf.html5.URLField('Redirect URI', validators=[wtf.Optional(), wtf.URL()], description="OAuth2 Redirect URI") notification_uri = wtf.html5.URLField( 'Notification URI', validators=[wtf.Optional(), wtf.URL()], description= "Lastuser resource provider Notification URI. When another application requests access to " "resources provided by this app, Lastuser will post a notice to this URI with a copy of the access " "token that was provided to the other application. Other notices may be posted too " "(not yet implemented)") iframe_uri = wtf.html5.URLField( 'IFrame URI', validators=[wtf.Optional(), wtf.URL()], description= "Front-end notifications URL. This is loaded in a hidden iframe to notify the app that the " "user updated their profile in some way (not yet implemented)") resource_uri = wtf.html5.URLField( 'Resource URI', validators=[wtf.Optional(), wtf.URL()], description= "URI at which this application provides resources as per the Lastuser Resource API " "(not yet implemented)") allow_any_login = wtf.BooleanField( 'Allow anyone to login', default=True, description= "If your application requires access to be restricted to specific users, uncheck this, " "and only users who have been assigned a permission to the app will be able to login" ) team_access = wtf.BooleanField( 'Requires access to teams', default=False, description= "If your application is capable of assigning access permissions to teams, check this. " "Organization owners will then able to grant access to teams in their organizations" ) def validate_client_owner(self, field): if field.data == g.user.userid: self.user = g.user self.org = None else: orgs = [ org for org in g.user.organizations_owned() if org.userid == field.data ] if len(orgs) != 1: raise wtf.ValidationError("Invalid owner") self.user = None self.org = orgs[0]
class PermissionForm(Form): """ Create or edit a permission """ name = wtf.TextField( 'Permission name', validators=[wtf.Required()], description='Name of the permission as a single word in lower case. ' 'This is passed to the application when a user logs in. ' 'Changing the name will not automatically update it everywhere. ' 'You must reassign the permission to users who had it with the old name' ) title = wtf.TextField( 'Title', validators=[wtf.Required()], description='Permission title that is displayed to users') description = wtf.TextAreaField( 'Description', description='An optional description of what the permission is for') context = wtf.RadioField( 'Context', validators=[wtf.Required()], description='Context where this permission is available') def validate(self): rv = super(PermissionForm, self).validate() if not rv: return False if not valid_username(self.name.data): raise wtf.ValidationError("Name contains invalid characters") existing = Permission.query.filter_by(name=self.name.data, allusers=True).first() if existing and existing.id != self.edit_id: self.name.errors.append( "A global permission with that name already exists") return False if self.context.data == g.user.userid: existing = Permission.query.filter_by(name=self.name.data, user=g.user).first() else: org = Organization.query.filter_by( userid=self.context.data).first() if org: existing = Permission.query.filter_by(name=self.name.data, org=org).first() else: existing = None if existing and existing.id != self.edit_id: self.name.errors.append( "You have another permission with the same name") return False return True def validate_context(self, field): if field.data == g.user.userid: self.user = g.user self.org = None else: orgs = [ org for org in g.user.organizations_owned() if org.userid == field.data ] if len(orgs) != 1: raise wtf.ValidationError("Invalid context") self.user = None self.org = orgs[0]