當前位置: 首頁>>代碼示例>>Python>>正文


Python validators.required方法代碼示例

本文整理匯總了Python中wtforms.validators.required方法的典型用法代碼示例。如果您正苦於以下問題:Python validators.required方法的具體用法?Python validators.required怎麽用?Python validators.required使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在wtforms.validators的用法示例。


在下文中一共展示了validators.required方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: List_table_rules

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import required [as 別名]
def List_table_rules():
    class TheForm(Form): 
        rule = TextField('id:', validators=[validators.required(), validators.Length(min=1, max=32)])

        class Meta:
            csrf = True
            csrf_class = tokenform.Ice_CSRF

    form = TheForm(
      request.form,
      meta={'csrf_context': request.remote_addr }
    )

    if user_controller.check_auth() == False:
        return redirect("front/auth")

    obj=rule_rest_api
    obj=obj.rest_call("","")
    obj.token=session['userkey']
    obj.List_rules()
    rules=[]
    for rows in obj.json_output:
        rules.append(rows)
    return render_template('rule_forms/rule_list.html',form=form, rules=rules, title="Table of rules") 
開發者ID:CoolerVoid,項目名稱:codecat,代碼行數:26,代碼來源:rule_controller.py

示例2: List_table_users

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import required [as 別名]
def List_table_users():
    
    if check_auth() == False:
        return redirect("front/auth")

    class TheForm(Form): 
        name = TextField('id:', validators=[validators.required(), validators.Length(min=1, max=9)])

        class Meta:
            csrf = True
            csrf_class = tokenform.Ice_CSRF

    form = TheForm(
      request.form,
      meta={'csrf_context': request.remote_addr }
    )

    obj=user_rest_api
    obj=obj.rest_call("","")
    obj.token=session['userkey']
    obj.List_Users()
    users=[]
    for rows in obj.json_output:
        users.append({"id": rows[0],"name": rows[1],"email": rows[2],"owner": rows[3],"date": rows[4]})
    return render_template('user_forms/user_list.html',form=form, users=users, title="Table of Users") 
開發者ID:CoolerVoid,項目名稱:codecat,代碼行數:27,代碼來源:user_controller.py

示例3: convert_ReferenceProperty

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import required [as 別名]
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs) 
開發者ID:jpush,項目名稱:jbox,代碼行數:7,代碼來源:db.py

示例4: convert

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import required [as 別名]
def convert(self, model, prop, field_args):
        """
        Returns a form field for a single model property.

        :param model:
            The ``db.Model`` class that contains the property.
        :param prop:
            The model property: a ``db.Property`` instance.
        :param field_args:
            Optional keyword arguments to construct the field.
        """
        prop_type_name = type(prop).__name__
        kwargs = {
            'label': prop.name.replace('_', ' ').title(),
            'default': prop.default_value(),
            'validators': [],
        }
        if field_args:
            kwargs.update(field_args)

        if prop.required and prop_type_name not in self.NO_AUTO_REQUIRED:
            kwargs['validators'].append(validators.required())

        if prop.choices:
            # Use choices in a select field if it was not provided in field_args
            if 'choices' not in kwargs:
                kwargs['choices'] = [(v, v) for v in prop.choices]
            return f.SelectField(**kwargs)
        else:
            converter = self.converters.get(prop_type_name, None)
            if converter is not None:
                return converter(model, prop, kwargs) 
開發者ID:jpush,項目名稱:jbox,代碼行數:34,代碼來源:db.py

示例5: getsinks

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import required [as 別名]
def getsinks(request):
    if user_controller.check_auth() == False:
        return redirect("front/auth")
    class TheForm(Form):
        sink = TextField('sink:', validators=[validators.required(), validators.Length(min=1, max=1024)])
        path = TextField('path:', validators=[validators.required(), validators.Length(min=1, max=2048)])
        class Meta:
            csrf = True
            csrf_class = tokenform.Ice_CSRF

    form = TheForm(
      request.form,
      meta={'csrf_context': request.remote_addr }
    )

    if request.method == 'POST':
        token=request.form['csrf_token']
        if form.validate():
            if form.csrf_token.errors: 
                flash('Error: form token invalid try to post again')
            else:
                try:
                 d={}
                 d['lang']=request.form['lang']
                 d['sink']=request.form['sink']
                 d['path']=request.form['path']
                 obj=engine_rest_api
                 obj=obj.rest_call("","")
                 obj.token=session['userkey']
                 codes_lines=obj.getsinks(**d) 
                 flash("Wait five seconds and look the code cache")     
                except Exception as e:
                 flash('Fail: '+ str(e))
        else:
            flash('Error: All the form fields are required. ')
    return render_template('engine_forms/getsinks.html', form=form, title="Search sink") 
開發者ID:CoolerVoid,項目名稱:codecat,代碼行數:38,代碼來源:engine_controller.py

示例6: allsinks

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import required [as 別名]
def allsinks(request):
    if user_controller.check_auth() == False:
        return redirect("front/auth")
    class TheForm(Form):
        path = TextField('path:', validators=[validators.required(), validators.Length(min=1, max=2048)])
        lang = TextField('lang:', validators=[validators.required(), validators.Length(min=1, max=32)])
        class Meta:
            csrf = True
            csrf_class = tokenform.Ice_CSRF

    form = TheForm(
      request.form,
      meta={'csrf_context': request.remote_addr }
    )

    if request.method == 'POST':
        token=request.form['csrf_token']
        if form.validate():
            if form.csrf_token.errors: 
                flash('Error: form token invalid try to post again')
            else:
                try:
                 d={}
                 d['lang']=request.form['lang']
                 d['path']=request.form['path']
                 obj=engine_rest_api
                 obj=obj.rest_call("","")
                 obj.token=session['userkey']
                 codes_lines=obj.allsinks(**d)
                 flash("Wait five seconds and look the code cache")
                except Exception as e:
                 flash('Fail: '+ str(e))
        else:
            flash('Error: All the form fields are required. ')
    return render_template('engine_forms/allsinks.html', form=form, title="Search using all rules") 
開發者ID:CoolerVoid,項目名稱:codecat,代碼行數:37,代碼來源:engine_controller.py

示例7: insert_rule

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import required [as 別名]
def insert_rule(request):
    if user_controller.check_auth() == False:
        return redirect("front/auth")

    class TheForm(Form): 
        title = TextField('title:', validators=[validators.required(), validators.Length(min=3, max=1024)])
        class Meta:
            csrf = True
            csrf_class = tokenform.Ice_CSRF

    form = TheForm(
      request.form,
      meta={'csrf_context': request.remote_addr }
    )

    if request.method == 'POST':
        token=request.form['csrf_token']
        if form.validate():
            if form.csrf_token.errors: 
                flash('Error: form token invalid try to post again')
            else:
                try:
                 d={}
                 d['title']=request.form['title']
                 d['lang']=request.form['lang']
                 d['description']=request.form['description']
                 d['level']=request.form['level']
                 d['match1']=request.form['match1']
                 d['match2']=request.form['match2']
                 obj=rule_rest_api
                 obj=obj.rest_call("","")
                 obj.token=session['userkey']
                 handler=obj.Insert_rule(**d)
                 flash(str(handler))
                except Exception as e:
                 flash('Fail: '+ str(e))
        else:
            flash('Error: All the form fields are required. ')
    return render_template('rule_forms/rule_insert.html', form=form, title="Insert rule") 
開發者ID:CoolerVoid,項目名稱:codecat,代碼行數:41,代碼來源:rule_controller.py

示例8: delete_rule

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import required [as 別名]
def delete_rule(request):
    if user_controller.check_auth() == False:
        return redirect("front/auth")

    class TheForm(Form): 
        id = TextField('id:', validators=[validators.required(), validators.Length(min=1, max=64)])

        class Meta:
            csrf = True
            csrf_class = tokenform.Ice_CSRF

    form = TheForm(
      request.form,
      meta={'csrf_context': request.remote_addr }
    )

    if request.method == 'POST':
        token=request.form['csrf_token']
 
        if form.validate():
            if form.csrf_token.errors: 
                flash('Error: form token invalid try to post again')
            else:
                id=request.form['id']
                obj=rule_rest_api
                obj=obj.rest_call("","")
                obj.token=session['userkey']
                handler=obj.Delete_rule(id)
                flash(str(handler))
        else:
            flash('Error: All the form fields are required. ')
    return render_template('rule_forms/rule_delete.html', form=form, title="Delete rule by ID") 
開發者ID:CoolerVoid,項目名稱:codecat,代碼行數:34,代碼來源:rule_controller.py

示例9: show_auth

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import required [as 別名]
def show_auth(request):
    if session.get('userkey') == True:
        if test_token(session['userkey'])==True:
            img='<img src="/static/codecat1.png" height="400" width="400" >'
            return render_template('AuthAdmin.html',title="Welcome to Codecat",content=img)

    class TheForm(Form):
        email = TextField('email:', validators=[validators.required(), validators.Length(min=4, max=35)])
        password = TextField('password:', validators=[validators.required(), validators.Length(min=4, max=35)])

        class Meta:
            csrf = True
            csrf_class = tokenform.Ice_CSRF

    form = TheForm(
      request.form,
      meta={'csrf_context': request.remote_addr }
    )
    if request.method == 'POST':
        token=request.form['csrf_token']
 
        if form.validate():
            if form.csrf_token.errors: 
                flash('Error: form token invalid try to post again')
                return render_template('login.html',form=form)
            if test_auth(request) == True:
                img='<img src="/static/codecat1.png" height="400" width="400" >'
                return render_template('AuthAdmin.html',title="Welcome to Codecat",content=img)
            flash('Error user or password not found !')
        else:
            flash('Error: All the form fields are required. ')
# token in  form.csrf_token 
    return render_template('login.html',form=form) 
開發者ID:CoolerVoid,項目名稱:codecat,代碼行數:35,代碼來源:user_controller.py

示例10: insert_user

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import required [as 別名]
def insert_user(request):
    if check_auth() == False:
        return redirect("front/auth")

    class TheForm(Form): 
        name = TextField('name:', validators=[validators.required(), validators.Length(min=4, max=35)])
        email = TextField('email:', validators=[validators.required(), validators.Length(min=4, max=35)])
        password = TextField('password:', validators=[validators.required(), validators.Length(min=4, max=35)]) 
        # owner = TextField('owner:', validators=[validators.required(), validators.Length(min=4, max=12)])
        class Meta:
            csrf = True
            csrf_class = tokenform.Ice_CSRF

    form = TheForm(
      request.form,
      meta={'csrf_context': request.remote_addr }
    )

    if request.method == 'POST':
        token=request.form['csrf_token']
 
        if form.validate():
            if form.csrf_token.errors: 
                flash('Error: form token invalid try to post again')
            else:
                name=request.form['name']
                email=request.form['email']
                owner=request.form['owner']
                password=request.form['password']
                obj=user_rest_api
                obj=obj.rest_call("","")
                obj.token=session['userkey']
                handler=obj.Insert_User(email,name,password,owner)
                flash(str(handler))
        else:
            flash('Error: All the form fields are required. ')
    return render_template('user_forms/user_insert.html', form=form, title="Insert User") 
開發者ID:CoolerVoid,項目名稱:codecat,代碼行數:39,代碼來源:user_controller.py

示例11: delete_user

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import required [as 別名]
def delete_user(request):
    if check_auth() == False:
        return redirect("front/auth")
    class TheForm(Form): 
        id = TextField('id:', validators=[validators.required(), validators.Length(min=1, max=64)])

        class Meta:
            csrf = True
            csrf_class = tokenform.Ice_CSRF

    form = TheForm(
      request.form,
      meta={'csrf_context': request.remote_addr }
    )

    if request.method == 'POST':
        token=request.form['csrf_token']
 
        if form.validate():
            if form.csrf_token.errors: 
                flash('Error: form token invalid try to post again')
            else:
                id=request.form['id']
                obj=user_rest_api
                obj=obj.rest_call("","")
                obj.token=session['userkey']
                handler=obj.Delete_User(id)
                flash(str(handler))
        else:
            flash('Error: All the form fields are required. ')
    return render_template('user_forms/user_delete.html', form=form, title="Delete User by ID") 
開發者ID:CoolerVoid,項目名稱:codecat,代碼行數:33,代碼來源:user_controller.py

示例12: convert

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import required [as 別名]
def convert(self, model, prop, field_args):
        """
        Returns a form field for a single model property.

        :param model:
            The ``db.Model`` class that contains the property.
        :param prop:
            The model property: a ``db.Property`` instance.
        :param field_args:
            Optional keyword arguments to construct the field.
        """

        prop_type_name = type(prop).__name__

        # Check for generic property
        if(prop_type_name == "GenericProperty"):
            # Try to get type from field args
            generic_type = field_args.get("type")
            if generic_type:
                prop_type_name = field_args.get("type")

            # If no type is found, the generic property uses string set in convert_GenericProperty

        kwargs = {
            'label': prop._code_name.replace('_', ' ').title(),
            'default': prop._default,
            'validators': [],
        }
        if field_args:
            kwargs.update(field_args)

        if prop._required and prop_type_name not in self.NO_AUTO_REQUIRED:
            kwargs['validators'].append(validators.required())

        if kwargs.get('choices', None):
            # Use choices in a select field.
            kwargs['choices'] = [(v, v) for v in kwargs.get('choices')]
            return f.SelectField(**kwargs)

        if prop._choices:
            # Use choices in a select field.
            kwargs['choices'] = [(v, v) for v in prop._choices]
            return f.SelectField(**kwargs)

        else:
            converter = self.converters.get(prop_type_name, None)
            if converter is not None:
                return converter(model, prop, kwargs)
            else:
                return self.fallback_converter(model, prop, kwargs) 
開發者ID:jpush,項目名稱:jbox,代碼行數:52,代碼來源:ndb.py

示例13: convert

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import required [as 別名]
def convert(self, model, prop, field_args):
        """
        Returns a form field for a single model property.

        :param model:
            The ``db.Model`` class that contains the property.
        :param prop:
            The model property: a ``db.Property`` instance.
        :param field_args:
            Optional keyword arguments to construct the field.
        """

        prop_type_name = type(prop).__name__

        #check for generic property
        if(prop_type_name == "GenericProperty"):
            #try to get type from field args
            generic_type = field_args.get("type")
            if generic_type:
                prop_type_name = field_args.get("type")
            #if no type is found, the generic property uses string set in convert_GenericProperty

        kwargs = {
            'label': prop._code_name.replace('_', ' ').title(),
            'default': prop._default,
            'validators': [],
        }
        if field_args:
            kwargs.update(field_args)

        if prop._required and prop_type_name not in self.NO_AUTO_REQUIRED:
            kwargs['validators'].append(validators.required())

        if kwargs.get('choices', None):
            # Use choices in a select field.
            kwargs['choices'] = [(v, v) for v in kwargs.get('choices')]
            return f.SelectField(**kwargs)

        if prop._choices:
            # Use choices in a select field.
            kwargs['choices'] = [(v, v) for v in prop._choices]
            return f.SelectField(**kwargs)

        else:
            converter = self.converters.get(prop_type_name, None)
            if converter is not None:
                return converter(model, prop, kwargs)
            else:
                return self.fallback_converter(model, prop, kwargs) 
開發者ID:google,項目名稱:googleapps-message-recall,代碼行數:51,代碼來源:ndb.py

示例14: update_user

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import required [as 別名]
def update_user(user_id):
    if check_auth() == False:
        return redirect("front/auth")
    class TheForm(Form): 
        name = TextField('name:', validators=[validators.required(), validators.Length(min=4, max=35)])
        email = TextField('email:', validators=[validators.required(), validators.Length(min=4, max=35)])
        password = TextField('password:', validators=[validators.required(), validators.Length(min=4, max=35)]) 
        # owner = TextField('owner:', validators=[validators.required(), validators.Length(min=4, max=12)])
        class Meta:
            csrf = True
            csrf_class = tokenform.Ice_CSRF

    form = TheForm(
      request.form,
      meta={'csrf_context': request.remote_addr }
    )
    
    if request.method == 'POST': 
#"csrf_token" in request.form:
        if len(str(user_id)) >=1 and len(request.form['csrf_token']) > 1 :
            token=request.form['csrf_token']
 
            if form.validate():
                if form.csrf_token.errors: 
                    flash('Error: form token invalid try to post again')
                else:
                    name=request.form['name']
                    email=request.form['email']
                    owner=request.form['owner']
                    password=request.form['password']
                    obj=user_rest_api
                    obj=obj.rest_call("","")
                    obj.token=session['userkey']
                    handler=obj.Update_User(str(user_id),email,name,password,owner)
                    flash(str(handler))
            else:
                flash('Error: All the form fields are required. ')
    obj=user_rest_api
    obj=obj.rest_call("","")
    obj.token=session['userkey']
    obj.Return_User_by_ID(str(user_id))
    users={}
    rows=[]
    rows= obj.json_output
    users={"id": str(rows[0]),"name": str(rows[1]),"email": str(rows[2]),"owner": str(rows[3]),"date": str(rows[4]) }
    return render_template('user_forms/user_update.html', form=form, users=users, title="Update data of user") 
開發者ID:CoolerVoid,項目名稱:codecat,代碼行數:48,代碼來源:user_controller.py


注:本文中的wtforms.validators.required方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。