class ApplicationForm(wtf.Form): title = wtf.TextField('Application title', validators=[wtf.Required(), wtf.Length(2, 100)]) url = wtf.html5.URLField('Application website', validators=[wtf.Required()]) description = wtf.TextAreaField('Description', validators=[wtf.Required()]) submit = wtf.SubmitField('Create application')
class SpawnForm(wtf.Form): image = wtf.SelectField( 'Image', [wtf.Required()], choices=IMAGE_CHOICES) flavor = wtf.SelectField( 'Flavor', [wtf.Required()], choices=FLAVOR_CHOICES) name = wtf.TextField('Name', [wtf.Required()]) password = wtf.PasswordField('Password') confirm_password = wtf.PasswordField( 'Confirm Password', [wtf.EqualTo('password')]) keypair = wtf.SelectField('Key Pair', choices=KEYPAIR_CHOICES) security_groups = wtf.SelectMultipleField( 'Security Groups', choices=SECURITY_GROUP)
class PostcardForm(wtf.Form): username = wtf.TextField('username', validators=[wtf.Length(max=20), wtf.Required()]) origin = wtf.TextField('origin', validators=[wtf.Required()]) date = wtf.DateField('date of postmark', format='%m/%d/%Y', default=datetime.date.today()) origin_country = wtf.HiddenField() origin_latitude = wtf.DecimalField() origin_longitude = wtf.DecimalField() front = wtf.TextField('front of card') back = wtf.TextField('back of card') tags = wtf.TextField('tags (comma-delimited)')
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") 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="A brief outline of who you are and how you are qualified to be "\ "taking this session")
def finish(invitation_hash): """Finish invitation process. Check everything, create user, redirect to logout (it wipes out session and redirects to login). """ try: invitation_id, email, hash_code, complete, role = \ row_mysql_queries.get_invitation_by_hash(invitation_hash) except TypeError: # hash code not found, None returned # TODO(apugachev) show form to typ e invitation token flask.flash('Invitation token not found.', 'error') return flask.redirect(flask.url_for('dashboard')) if complete == 1: flask.flash('Invitation token is already used.', 'error') return flask.redirect(flask.url_for('dashboard')) form = forms.InviteRegister() username = email.split("@")[0] form.email.data = email username_is_taken = False try: utils.neo4j_api_call('/users', {"email": email}, 'GET')[0] flask.flash( 'This username is already taken. Please, choose another one.', 'warning') # NOTE(apugachev) at the beginning 'username' is HiddenField # now we want to allow user to edit username # that's why bind() username_field = wtf.TextField('Username', [wtf.Required()]).bind( form, 'username') form.username = username_field form._fields['username'] = username_field username_is_taken = True except Exception: # NOTE(apugachev) user not found, success; # TODO(apugachev) find out what exceptions can occur and what to do if form.validate_on_submit(): new_odb_user = register_user(form.username.data, form.email.data, form.password.data, role) if new_odb_user is not None: row_mysql_queries.update_invitation(invitation_id, email, hash_code) # NOTE(apugachev)no flash, it gets deleted on logout return flask.redirect(flask.url_for('logout')) form.username.data = username return { 'form': form, 'email': email, 'username': username, 'username_is_taken': username_is_taken }
class CreateNotification(wtf.Form): name = wtf.SelectField('Name', [wtf.Required()], choices=[]) is_minimized = wtf.BooleanField('Is minimized') def __init__(self, *args, **kwargs): super(CreateNotification, self).__init__(*args, **kwargs) parameters = utils.notifications_api_call("/parameter") item_list = utils.notifications_api_call("/item") created_keys = set([par["key_"] for par in parameters]) choices_dict = dict(((item["key_"], item["name"]) for item in item_list if item["key_"] not in created_keys)) self.name.choices = sorted(choices_dict.iteritems(), key=lambda i: i[1])
class CreateNetwork(wtf.Form): cidr = wtf.TextField('CIDR', [wtf.Required()]) vlan = wtf.IntegerField('VLAN', [wtf.NumberRange(min=1, max=4096, message='Not in range %(min)s - %(max)s')]) def validate_cidr(form, field): try: network = netaddr.IPNetwork(field.data) except (UnboundLocalError, netaddr.AddrFormatError): raise wtf.ValidationError('Unrecognised format of CIDR') if network.size < 4: raise wtf.ValidationError('Network size is lower then 4; use something like 10.1.1.1/30.') if network.size > 65536: raise wtf.ValidationError('Network size is greater then 65536')
class BookForm(wtf.Form): document_class = Book title = wtf.TextField(validators=[wtf.Required()]) year = wtf.IntegerField(validators=[wtf.Required()]) instance = None def __init__(self, document=None, *args, **kwargs): super(BookForm, self).__init__(*args, **kwargs) if document is not None: self.instance = document self._copy_data_to_form() def _copy_data_to_form(self): self.title.data = self.instance.title self.year.data = self.instance.year def save(self): if self.instance is None: self.instance = self.document_class() self.instance.title = self.title.data self.instance.year = self.year.data self.instance.save() return self.instance
class SignUpForm(wtf.Form): username = wtf.TextField( validators=[wtf.Required(), wtf.Length(min=4, max=16)]) password = wtf.PasswordField( validators=[wtf.Required(), wtf.Length(min=6, max=16)]) email = wtf.TextField(validators=[wtf.Email()]) birth_month = wtf.SelectField(choices=months, validators=[wtf.Required()]) birth_day = wtf.SelectField(choices=days, validators=[wtf.Required()]) birth_year = wtf.SelectField(choices=years, validators=[wtf.Required()]) gender = wtf.SelectField(choices=genders, validators=[wtf.Required()]) zip_code = wtf.TextField(validators=[wtf.Required()]) agree_terms = wtf.BooleanField('I agree to terms of use', validators=[wtf.Required()]) recaptcha = wtf.RecaptchaField('Human Test') def validate_username(form, field): if field.data and User.get_user(field.data): raise wtf.ValidationError('Usename already exists.') def validate_zip_code(form, field): try: zip_code_db[field.data] except IndexError: raise wtf.ValidationError('Invalid zip code.')
class ProposalSpaceForm(wtf.Form): name = wtf.TextField('URL name', validators=[wtf.Required()]) title = wtf.TextField('Title', validators=[wtf.Required()]) datelocation = wtf.TextField('Date and Location', validators=[wtf.Required()]) date = wtf.DateField('Date (for sorting)', validators=[wtf.Required()]) tagline = wtf.TextField('Tagline', validators=[wtf.Required()]) description = wtf.TextAreaField('Description', validators=[wtf.Required()]) status = wtf.SelectField('Status', coerce=int, choices=[ (0, 'Draft'), (1, 'Open'), (2, 'Voting'), (3, 'Jury selection'), (4, 'Feedback'), (5, 'Closed'), (6, 'Rejected'), ])
class SectionForm(wtf.Form): name = wtf.TextField('URL name', validators=[wtf.Required()]) title = wtf.TextField('Title', validators=[wtf.Required()]) description = wtf.TextAreaField('Description', validators=[wtf.Required()]) public = wtf.BooleanField('Public?')
class RemoveUserFromProject(wtf.Form): remove_project = wtf.SelectField('Projects', [wtf.Required()], choices=[]) user = wtf.HiddenField('User', [wtf.Required()])
class DeleteCommentForm(wtf.Form): comment_id = wtf.HiddenField('Comment', validators=[wtf.Required()])
class PrivateMessageForm(wtf.Form): subject = wtf.TextField(validators=[wtf.Required()]) message = wtf.TextAreaField(validators=[wtf.Required()])
class FeedbackForm(wtf.Form): name = wtf.TextField(validators=[wtf.Required()]) email = wtf.TextField(validators=[wtf.Email()]) message = wtf.TextAreaField(validators=[wtf.Required()]) recaptcha = wtf.RecaptchaField('Human Test')
class ConfigureHostnameForm(wtf.Form): hostname = wtf.TextField( u'Focus URL', [wtf.Required(), validate_hostname], [filter_hostname], default=row_mysql_queries.get_configured_hostname)
class CommentForm(wtf.Form): comment = wtf.TextAreaField(validators=[wtf.Required()])
class PasswordRecoveryRequest(wtf.Form): email = wtf.html5.EmailField('Email', [wtf.Required()])
class CommentForm(wtf.Form): parent_id = wtf.HiddenField('Parent', default="", id="comment_parent_id") edit_id = wtf.HiddenField('Edit', default="", id="comment_edit_id") message = wtf.TextAreaField('Add comment', id="comment_message", validators=[wtf.Required()])
class DeleteUserForm(wtf.Form): user_id = wtf.HiddenField('user id', [wtf.Required()])
class NewProject(wtf.Form): name = wtf.TextField('Name', [wtf.Required()]) description = wtf.TextField('Description') network = wtf.SelectField( 'Network', [wtf.Required()], choices=[], description='Network label, CIDR, VLAN respectively')
class NewUserToProjectForm(wtf.Form): user = wtf.SelectField( 'User', [wtf.Required()], choices=USERS_CHOICES, coerce=int) roles = wtf.SelectMultipleField( 'Roles', [wtf.Required()], choices=ROLES_CHOICES, coerce=int)
class SecurityGroupCreate(wtf.Form): name = wtf.TextField('Name', [wtf.Required()]) description = wtf.TextField('Description', [wtf.Required()])
class LoginForm(wtf.Form): next = wtf.HiddenField(default=utils.get_next_url()) email = wtf.TextField('Email', [wtf.Required(), wtf.Email()]) password = wtf.PasswordField('Password', [wtf.Required()])
class AddUserToProject(wtf.Form): add_project = wtf.SelectField('Projects', [wtf.Required()], choices=[]) user = wtf.HiddenField('User', [wtf.Required()])
class Invite(wtf.Form): email = html5.EmailField('Email', [wtf.Required()]) role = wtf.SelectField(u'Role', choices=ROLES)
class LoginForm(wtf.Form): username = wtf.TextField(validators=[wtf.Required()]) password = wtf.PasswordField(validators=[wtf.Required()]) remember_me = wtf.BooleanField()
class InviteRegister(wtf.Form): email = wtf.HiddenField() username = wtf.HiddenField() password = wtf.PasswordField('Password', [wtf.Required()])
class CreateSSHKey(wtf.Form): # TODO(apugachev) look in nova for boundaries name = wtf.TextField('Name of keypair', [wtf.Required()]) public_key = wtf.TextField( 'Public Key', [wtf.Optional()], description='Can be omitted. New keypair will be generated')
class CreateEmailMask(wtf.Form): email_mask = wtf.TextField( 'Domain', [wtf.Required()], description='Domain part of allowed emails for invitations')