{ "info": { "author": "Oliver Cope", "author_email": "oliver@redgecko.org", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6" ], "description": ".. Copyright 2013-2014 Oliver Cope\n..\n.. Licensed under the Apache License, Version 2.0 (the \"License\");\n.. you may not use this file except in compliance with the License.\n.. You may obtain a copy of the License at\n..\n.. http://www.apache.org/licenses/LICENSE-2.0\n..\n.. Unless required by applicable law or agreed to in writing, software\n.. distributed under the License is distributed on an \"AS IS\" BASIS,\n.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n.. See the License for the specific language governing permissions and\n.. limitations under the License.\n\n\nMorf - HTML form validation and rendering\n=========================================\n\nWhy use morf?\n-------------\n\nBecause you want to express simple forms concisely::\n\n from morf import HTMLForm, fields, validators\n\n class ContactForm(HTMLForm):\n name = fields.Str(message='Please fill in your name')\n email = fields.Str(validators=[validators.is_email])\n message = fields.Str(validators=[validators.minwords(10)])\n\nBecause you want to be able to express custom validation logic::\n\n class BookingForm(HTMLForm):\n name = fields.Str(message='Please fill in your name')\n arrival_date = fields.Date()\n leaving_date = fields.Date()\n\n @validates(arrival_date, leaving_date)\n def check_name(self, arrival_date, leaving_date):\n\n # No minimum booking duration at weekends\n if arrival_date.weekday() in (SAT, SUN):\n return\n\n if (leaving_date - arrival_date).days < 3:\n self.fail('Sorry, the minimum booking is for 3 days')\n\nBecause you want a simple API to work with::\n\n def my_view(request):\n form = BookingForm(request.POST)\n if form.isvalid:\n make_booking(form.data)\n ...\n else:\n show_error_page(errors=form.errors)\n\n\nDocumentation for morf is available at https://ollycope.com/software/morf/\n\nMorf's source code is available at https://bitbucket.org/ollyc/morf/\n\n\nRendering forms with widgets\n============================\n\nMorf separates form processing - taking user input and validating it, and\nhandling any ensuing application logic - from the business of rendering HTML\nforms and parsing HTML form encoded data.\n\nIf your form is always going to be rendered as an HTML form, just\nsubclass HTMLForm, and you can use the rendering methods directly::\n\n class BookingForm(HTMLForm):\n name = fields.Str(message='Please fill in your name')\n email = fields.Str(validators=[is_email])\n arrival_date = fields.Date()\n leaving_date = fields.Date()\n\n bookingform = BookingForm()\n bookingform.as_p().render()\n\nForms processing data coming from sources other than HTML form submissions\nshould subclass ``morf.Form``.\n\nIf you also want your form to be rendered or submitted in HTML,\nuse ``HTMLForm.adapt``::\n\n from morf import Form, HTMLForm\n\n class BookingForm(Form):\n name = fields.Str(message='Please fill in your name')\n email = fields.Str(validators=[is_email])\n arrival_date = fields.Date()\n leaving_date = fields.Date()\n\n HTMLBookingForm = HTMLForm.adapt(BookingForm)\n HTMLBookingForm().as_p().render()\n\nRendering field groups\n-----------------------\n\n\nSelect groups of fields for rendering\nusing the ``select\u2026`` methods on any\nFormRenderer object.\n\n**``select``** returns just the named fields, eg::\n\n
...
`` elements, ``