{"id":15818508,"url":"https://github.com/avanov/pyramid_webforms","last_synced_at":"2025-05-08T01:24:07.618Z","repository":{"id":6389089,"uuid":"7626817","full_name":"avanov/pyramid_webforms","owner":"avanov","description":"Simple declarative web forms using FormEncode and WebHelpers","archived":false,"fork":false,"pushed_at":"2013-08-10T10:31:48.000Z","size":188,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-23T23:06:50.498Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/avanov.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-15T14:58:58.000Z","updated_at":"2021-11-05T23:50:10.000Z","dependencies_parsed_at":"2022-07-08T03:07:48.646Z","dependency_job_id":null,"html_url":"https://github.com/avanov/pyramid_webforms","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avanov%2Fpyramid_webforms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avanov%2Fpyramid_webforms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avanov%2Fpyramid_webforms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avanov%2Fpyramid_webforms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avanov","download_url":"https://codeload.github.com/avanov/pyramid_webforms/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252979747,"owners_count":21835115,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-05T06:02:28.105Z","updated_at":"2025-05-08T01:24:07.598Z","avatar_url":"https://github.com/avanov.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Simple declarative web forms using FormEncode and WebHelpers\n==============================================\n\nStatus: **Early Development, Unstable, Unpublished**.\n\nPython Version: **2.7** (please contribute to `FormEncode Project`_ in order to make it 3.x compatible).\n\nInstallation\n--------------\n\n.. code-block:: bash\n\n   pip install pyramid_webforms\n\n\nExample\n-------------\n\nConsider the following pyramid project structure:\n\n.. code-block:: plain\n\n    my_pyramid_app/\n        modules/\n            signin/\n                __init__.py\n                forms.py\n                validators.py\n                views.py\n            __init__.py\n        templates/\n            signin.mako\n        __init__.py\n\nLet's define a sign-in form, its fields, and validators.\n\n.. code-block:: python\n\n    # my_pyramid_app/modules/signin/forms.py\n    from pyramid_webforms import Form\n    from my_pyramid_app.i18n import _\n    from . import validators\n\n\n    login_or_email = {\n        'type': 'text',\n        'title': _('Login or Email'),\n        'tip': _('Please enter your login or email that was used during your registration.'),\n        'size': 30,\n        'maxlength': 50,\n        'validator': validators.UserLoginOrEmail\n    }\n\n    password = {\n        'type': 'password',\n        'title': _('Password'),\n        'tip': _('A password can contain any character of any alphabet (minimum is 1, maximum is 64 characters). '\n                 'For reliability we recommend using non-trivial and long passwords. Note that the case of '\n                 'the letters matters.'),\n        'size': 30,\n        'maxlength': 64,\n        'validator': validators.UserPassword,\n        'value': '',\n    }\n\n    remember_me = {\n        'type': 'checkbox',\n        'title': _('Remember me'),\n        'tip': _('Set this checkbox if you want your current browser to keep '\n                 'your session for further visits.'),\n        'selected': False,\n        'validator': validators.RememberUserSession\n    }\n\n    class SignInForm(Form):\n        # form attributes and metadata\n        _id_ = 'signin-form'\n        _submit_text_ = _('Sign in')\n        _alternate_url_ = {'name': 'support.account_access'}\n        _alternate_text_ = _(\"I cannot access my account\")\n        _fieldsets_ = [\n            [['login_email', 'password', 'remember_me']]\n        ]\n        # form fields\n        login_email = login_or_email\n        password = password\n        remember_me = remember_me\n\n\n.. code-block:: python\n\n    # my_pyramid_app/modules/signin/validators.py\n    import re\n    import formencode\n\n    # logins are 3-16 characters long\n    USERLOGINS = re.compile('[A-Za-z0-9][-A-Za-z0-9]{1,14}[A-Za-z0-9]', re.IGNORECASE)\n\n    RememberUserSession = formencode.validators.Bool\n\n    class UserLogin(formencode.validators.Regex):\n        not_empty = True\n        strip = True\n        regex = USERLOGINS\n\n    class UserEmail(formencode.validators.Email):\n        not_empty = True\n        strip = True\n        max = 50\n        def _to_python(self, email, state):\n            email = super(UserEmail, self)._to_python(email, state)\n            return email.lower()\n\n    class UserLoginOrEmail(UserLogin):\n        def _to_python(self, value, state):\n            if '@' in value:\n                validator = UserEmail\n            else:\n                validator = UserLogin\n            value = validator.to_python(value, state)\n            return value\n\n        def validate_python(self, value, state):\n            pass\n\n\n    class UserPassword(formencode.validators.UnicodeString):\n        not_empty = True\n        max = 64\n\n\nNow we can use our form in pyramid view callables.\n\n.. code-block:: python\n\n    # my_pyramid_app/modules/signin/views.py\n    from pyramid.view import view_config\n    from .forms import SignInForm\n\n\n    class SignInView(object):\n\n        @view_config(route_name='session.signin', renderer='templates/signin.mako')\n        def signin_form(self):\n            request = self.request\n            if request.POST:\n                try:\n                    form = SignInForm.validate(request)\n                except SignInForm.Invalid as error:\n                    # redirect or error handling\n                    pass\n                else:\n                    # sign in user using form data\n                    pass\n\n            return {'signin_form': forms.SignInForm()}\n\n\n.. code-block:: mako\n\n    ## my_pyramid_app/templates/signin.mako\n    ${signin_form(request)}\n\n\n\nHere are the key conceptual points:\n\n- form fields are defined with plain dictionaries;\n- the fields can be reused by any other module;\n- each field record contains an assigned FormEncode-based validator;\n- a form is defined with the simple declarative interface.\n\n\nConfiguration options\n-----------------------\n\n+---------------------------------------+------------+----------------------------------------------------------+\n| Key                                   | Type       | Default                                                  |\n+=======================================+============+==========================================================+\n| pyramid_webforms.submit_tpl           | str        | pyramid_webforms:templates/submit_alternate.p_wf_mako    |\n+---------------------------------------+------------+----------------------------------------------------------+\n| pyramid_webforms.submit_alternate_tpl | str        | pyramid_webforms:templates/submit_alternate.p_wf_mako    |\n+---------------------------------------+------------+----------------------------------------------------------+\n| pyramid_webforms.form_tpl             | str        | pyramid_webforms:templates/form.p_wf_mako                |\n+---------------------------------------+------------+----------------------------------------------------------+\n| pyramid_webforms.fieldset_tpl         | str        | pyramid_webforms:templates/fieldset.p_wf_mako            |\n+---------------------------------------+------------+----------------------------------------------------------+\n| pyramid_webforms.field_tpl            | str        | pyramid_webforms:templates/field.p_wf_mako               |\n+---------------------------------------+------------+----------------------------------------------------------+\n| pyramid_webforms.tooltip_tpl          | str        | pyramid_webforms:templates/tooltip.p_wf_mako             |\n+---------------------------------------+------------+----------------------------------------------------------+\n| pyramid_webforms.form_error_tpl       | str        | pyramid_webforms:templates/form_error.p_wf_mako          |\n+---------------------------------------+------------+----------------------------------------------------------+\n| pyramid_webforms.field_error_tpl      | str        | pyramid_webforms:templates/field_error.p_wf_mako         |\n+---------------------------------------+------------+----------------------------------------------------------+\n\n\nSee also\n============\n\n- `FormEncode Project`_\n- `WebHelpers Project`_\n\n\n.. _FormEncode Project: https://github.com/formencode/formencode\n.. _WebHelpers Project: http://sluggo.scrapping.cc/python/WebHelpers/index.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favanov%2Fpyramid_webforms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favanov%2Fpyramid_webforms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favanov%2Fpyramid_webforms/lists"}