{"id":16544751,"url":"https://github.com/sinisaos/wtforms-piccolo","last_synced_at":"2025-10-28T15:31:15.754Z","repository":{"id":62591655,"uuid":"496111632","full_name":"sinisaos/wtforms-piccolo","owner":"sinisaos","description":"Server-side form generation utilities for Piccolo ORM Table class","archived":false,"fork":false,"pushed_at":"2022-06-02T04:31:55.000Z","size":25,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-04T02:16:30.577Z","etag":null,"topics":["form-generator","piccolo","wtforms"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/wtforms-piccolo/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sinisaos.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2022-05-25T06:37:01.000Z","updated_at":"2024-07-12T08:19:50.000Z","dependencies_parsed_at":"2022-11-03T22:56:40.837Z","dependency_job_id":null,"html_url":"https://github.com/sinisaos/wtforms-piccolo","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinisaos%2Fwtforms-piccolo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinisaos%2Fwtforms-piccolo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinisaos%2Fwtforms-piccolo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinisaos%2Fwtforms-piccolo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sinisaos","download_url":"https://codeload.github.com/sinisaos/wtforms-piccolo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219859270,"owners_count":16556036,"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":["form-generator","piccolo","wtforms"],"created_at":"2024-10-11T19:04:30.841Z","updated_at":"2025-10-28T15:31:15.387Z","avatar_url":"https://github.com/sinisaos.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Server-side form generation utilities for Piccolo ORM Table class.\nBased on the code found in [wtforms.ext](https://wtforms.readthedocs.io/en/2.3.x/ext/) and provides a bridge between Piccolo ORM tables and WTForms. \n\n# Installation \n\n```bash\npip install wtforms-piccolo\n```\n# Usage\n\nExample usage:\n\n```python\n# table.py\nfrom piccolo.apps.user.tables import BaseUser\nfrom piccolo.columns import Boolean, ForeignKey, Integer, Text, Varchar\nfrom piccolo.table import Table\n\n\nclass Task(Table):\n    \"\"\"\n    An example table.\n    \"\"\"\n\n    name = Varchar(required=True, null=False)\n    description = Text(required=True, null=False)\n    views = Integer(required=True, null=False, default=0)\n    completed = Boolean(default=False)\n    task_user = ForeignKey(references=BaseUser)\n```\n\nGenerate a form based on the table.\n\n```shell\nTaskForm = table_form(Task)\n```\n\nGenerate a form based on the table, excluding 'id' and 'views'.\n\n```shell\nTaskForm = table_form(Task, exclude=['id', 'views'])\n```\nGenerate a form based on the table, only including 'name' and 'description'.\n\n```shell\nTaskForm = table_form(Task, only=['name', 'description'])\n```\nThe form can be generated setting field arguments:\n\n```python\nTaskForm = table_form(Task, only=['name', 'description'], field_args={\n    'name': {\n        'label': 'Your new label',\n    },\n    'description': {\n        'label': 'Your new label',\n    }\n})\n```\nExample implementation for an edit view using Starlette web app:\n\n```python\n# app.py\n# other imports\nfrom wtforms_piccolo.orm import table_form\n\n@app.route(\"/{id:int}/\", methods=[\"GET\", \"POST\"])\nasync def edit(request):\n    path_id = request.path_params[\"id\"]\n    item = await Task.objects().get(Task.id == path_id).run()\n    users = await BaseUser.select().run()\n    data = await request.form()\n    TaskForm = table_form(Task, exclude=[\"id\"])\n    form = TaskForm(obj=item, formdata=data)\n    # FK select field\n    form.task_user.choices = [(i[\"id\"], i[\"username\"]) for i in users]\n    if request.method == \"POST\" and form.validate():\n        form.populate_obj(item)\n        await item.save().run()\n        return RedirectResponse(url=\"/\", status_code=302)\n    return templates.TemplateResponse(\n        \"edit.html\",\n        {\n            \"request\": request,\n            \"form\": form,\n            \"table_name\": Task._meta.tablename,\n        },\n    )\n```\n\nExample template for above view using Jinja and Bootstrap:\n\n```html\n{% extends \"base.html\" %}\n{% block content %}\n\u003cmain role=\"main\"\u003e\n    \u003cbr\u003e\u003cbr\u003e\n    \u003cdiv class=\"container\"\u003e\n        \u003ch2\u003eEdit Task\u003c/h2\u003e\n        \u003cbr\u003e\n        \u003cform method=\"POST\"\u003e\n            {% for field in form %}\n            \u003cdiv class=\"form-group\"\u003e\n                {{ field.label }}:\n                {{ field(class=\"form-control\") }}\n                {% for error in field.errors %}\n                \u003cspan style=\"color: red;\"\u003e*{{ error }}\u003c/span\u003e\n                {% endfor %}\n            \u003c/div\u003e\n            {% endfor %}\n            \u003cp\u003e\u003cinput class=\"btn btn-primary\" type=\"submit\" value=\"Submit\"\u003e\u003c/p\u003e\n        \u003c/form\u003e\n    \u003c/div\u003e \u003c!-- /container --\u003e\n    \u003chr\u003e\n\u003c/main\u003e\n{% endblock %}\n```\n\nThe full example of the Starlette web application is in example folder.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinisaos%2Fwtforms-piccolo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsinisaos%2Fwtforms-piccolo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinisaos%2Fwtforms-piccolo/lists"}