Exemplo n.º 1
0
class LoginForm(Form):
    def __init__(self, *args, ** kwargs):
        Form.__init__(self, *args, ** kwargs)
        self.user = None

    login = TextField(u'Login', validators=[validators.required(), ])
    password = PasswordField(u'Password', validators=[validators.required(), ])
    remember = BooleanField(u'Remember me')
    submit = SubmitField(u'Validate')

    def validate(self):
        rv = Form.validate(self)
        if not rv:
            return False

        pseudo = self.login.data
        password = self.password.data

        try:
            user_exists(self, self.login)
            user = check_password(pseudo, password)
            if user is None:
                self.password.errors.append('Wrong password.')
                return False
        except ValidationError:
            self.login.errors.append('Unknow user.')
            return False

        self.user = user

        return True
Exemplo n.º 2
0
class BookmarkForm(AjaxForm):
    id = HiddenField(u'Id')
    link = URLField(u'Link', validators=[validators.required(),
        validators.url(), ])
    title = TextField(u'Title', validators=[validators.required(), ])
    description = TextAreaField(u'Description')
    tags = TextField(u'Tags')
    submit = SubmitField(u'Add')

    def __init__(self, formdata=None, *args, **kwargs):
        self.create = kwargs.get('create', False)
        super(BookmarkForm, self).__init__(formdata, *args, **kwargs)

    def validate(self):
        rv = Form.validate(self)
        if not rv:
            return False

        link = self.link.data
        title = self.title.data
        description = self.description.data
        tags = map(lambda x: {'name': x.strip()}, self.tags.data.split(','))

        # TODO : add id control if create is False (modification mode need a
        # valid bookmark id)
        self.bookmark = ItemBookmark(ptags=tags, plink=link, ptitle=title,
            pdescription=description, json=True)
        return True
Exemplo n.º 3
0
class CreateUserForm(Form):
    username = TextField(u'ユーザ名', [validators.required()])
    password = PasswordField(u'パスワード', [validators.required()])
    repassword = PasswordField(u'パスワード(確認)', [
        validators.required(),
        validators.EqualTo('password', message=u"パスワードが一致しません")
    ])
Exemplo n.º 4
0
class RegisterForm(Form):
    login = TextField(u'Login', validators=[validators.required(),
        unique_user, ])
    password = PasswordField(u'Password', validators=[validators.required(),
        validators.length(min=settings.MIN_PASSWORD_LENGTH), ])
    password_confirmation = PasswordField(u'Password confirmation',
        validators=[validators.required(),
        validators.length(min=settings.MIN_PASSWORD_LENGTH), ])
    submit = SubmitField(u'Register')

    def __init__(self, *args, ** kwargs):
        Form.__init__(self, *args, ** kwargs)
        self.user = None

    def validate(self):
        rv = Form.validate(self)
        if not rv:
            return False

        pseudo = self.login.data
        password = self.password.data
        password_confirmation = self.password_confirmation.data

        if password != password_confirmation:
            self.password.errors.append('Passwords mismatch')
            self.password_confirmation.errors.append('Passwords mismatch')
            return False

        self.user = User(pseudo, password)

        return True
Exemplo n.º 5
0
class ReplyMessageForm(Form):
    subject = TextField(u'标题',
                        validators=[
                            validators.required(message=u"标题不能为空"),
                            validators.Length(min=4, max=100)
                        ])
    content = TextAreaField(u'内容',
                            validators=[
                                validators.required(message=u"内容不能为空"),
                                validators.Length(min=6, max=2000)
                            ])
    submit = SubmitField(u'发送')
Exemplo n.º 6
0
class StreamForm(wtf.Form):
    """Stream Form"""
    stream_name = wtf.TextField('Name', validators=[validators.Required()])
    stream_type = wtf.SelectField('Type',
                                  choices=[('sc2', 'Shoutcast 2'),
                                           ('ic2', 'Icecast 2')])
    stream_hostname = wtf.TextField('Hostname',
                                    validators=[validators.Required()])
    stream_port = wtf.IntegerField('Port', [validators.required()])
    stream_sid = wtf.IntegerField('SID', [validators.Optional()])
    stream_mount = wtf.TextField('Mount', [validators.Optional()])
Exemplo n.º 7
0
class PostForm(Form):
	title = TextField('Titulo:', [
		validators.Length(min=5, max=60, message="O Titulo deve ter entre 5 a 60 caracteres.")
	])
	text =  TextAreaField('Texto:', [
		validators.Length(min=5, message="O Texto deve ter no minimo 5 caracteres.")
	])
	tags = TextField('Tags:',[
		validators.required(message="Informe uma tag.")
	])
		
	def __init__(self, model_instance = None, *args, **kwargs):
		"""Método construtor da classe, preenche model ao criar form."""
		kwargs['csrf_enabled'] = False
		super(PostForm, self).__init__(*args, **kwargs)
		self.model = None
		if model_instance:
			self.title.data = model_instance.title
			self.text.data = model_instance.text
			self.tags.data = self.get_tags( model_instance.tags )
			self.model = model_instance
			 
	def save(self):
		"""Método responsável em salvar post no bigtable."""
		if self.model:
			self.model.title = self.title.data
			self.model.text = self.text.data
			self.model.tags = self.set_tags(self.tags.data)
		else:	
			self.model = Post(
							title = self.title.data,
							text = self.text.data,
							tags = self.set_tags(self.tags.data)
						)
		self.model.put()
		return self.model

	def get_tags(self, tags):
		"""Metodo que recupera valor do atributo tags."""
		tstr = ""
		for tag in tags:
			tstr += "%s," % tag
		return tstr[:-1]

	def set_tags(self, tags):
		"""Método que define valor para o atributo tags."""
		tag = TagCategory()
		return tag.string_to_category( tags )	
Exemplo n.º 8
0
class EntryForm(Form):
    title = TextField(u'タイトル',
                      [validators.required(),
                       validators.Length(max=255)])
    text = TextAreaField(u'内容', [validators.required()])
Exemplo n.º 9
0
class LoginForm(Form):
    username = TextField(u'ユーザ名', [validators.required()])
    password = PasswordField(u'パスワード', [validators.required()])
Exemplo n.º 10
0
class PostForm(Form):
    title = TextField("title", [validators.required()])
    text = TextAreaField("text")
    delete = BooleanField("delete post")
    post_id = HiddenField("post id")
Exemplo n.º 11
0
class ImageForm(Form):
    ragetext = TextField("Enter rage text:", [validators.required()])