Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.3 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67a
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Libraries

    pyforms 0.1

    Download button

    No screenshots available
    Downloads: 76  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Jamie Sun | More programs
    Public Domain / FREE
    September 12th, 2012, 11:23 GMT
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    pyforms description

    Web app forms tools

    pyforms is a Python module that provides tools for web app forms. Its code was extracted from web.py.

    Example of flask:

        #!/usr/bin/env python
        #coding:utf-8

        from flask import Flask
        from flask import request
        import pyforms as form
        app = Flask(__name__)


        is_email = form.regexp('[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$',"Invalid email format")
        is_chars = form.regexp("^[A-Za-z]+$","Must be in English string")
        is_alphanum = lambda x:form.regexp("^[A-Za-z0-9]{%s}$"%x,"Alphanumeric combinations must be length %s"%x)
        is_alphanum2 = lambda x,y:form.regexp("^[A-Za-z0-9]{%s,%s}$"%(x,y),"Must be a length of %s to %s alphanumeric combinations"%(x,y))
        is_number = form.regexp("^[0-9]*$","Must be numeric")
        is_cn = form.regexp("^[\u4e00-\u9fa5],{0,}$","Must be Chinese characters")
        is_url = form.regexp('[a-zA-z]+://[^\s]*',"Invalid url")
        is_phone = form.regexp('^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$',"Invalid phone numbers")
        is_idcard = form.regexp('^\d{15}$|^\d{18}$|^\d{17}[Xx]$',"Invalid ID card number")
        is_ip = form.regexp("\d+\.\d+\.\d+\.\d+","无效ip")
        is_rmb = form.regexp('^(([1-9]\d*)|0)(\.\d{2})?$',"Invalid amount of RMB")
        len_of = lambda x,y:form.regexp(".{%s,%s}$"%(x,y),"Length must be %s to %s"%(x,y))

        form1 = form.Form(
            form.Textbox("name",is_alphanum2(6,32),description=""),
            form.Password("passwd",is_alphanum2(6,32),description=""),
            form.Textarea("desc",len_of(1,128),description="",rows="5",),
            form.Button("submit", type="submit",html="提交"),
        )

        def render_form(frm):
            return "%s"%frm.render()

        @app.route('/', methods=['POST', 'GET'])
        def hello_world():
            iform = form1()
            if request.method == 'GET':
                return render_form(iform)
            elif request.method == 'POST':
                if not iform.validates(source=request.form):
                    return render_form(iform)
                else:
                    return "ok"

        if __name__ == '__main__':
            app.run()



    Product's homepage

    Requirements:

    · Python

      


    TAGS:

    web forms | web app | Python library | Python | web | app

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM