際際滷

際際滷Share a Scribd company logo
iktomi forms
a part of iktomi lib
http://iktomi.readthedocs.org/
Basics
 Validate user input
 Convert to internal representation
 Render forms, display validation error
 Work with nested data structures
Abstraction layers
 Form
 Field (+ FieldSet, FieldList, FieldBlock)
 Converter
 Widget
 permissions (rw)
 raw and clean values
Forms
class UncleForm(Form):
fields = [
Field('name'),
FieldList('nephews', field=FieldSet(None, fields=[
Field('name'),
])),
]
def process_form(env):
form = UncleForm(env, initial=init)
if form.accept(env.request.POST):
data = form.python_data
else:
errors = form.errors
{"name": "Scrooge",
"nephews": [{"name": "Huey"},
{"name": "Dewey"},
{"name": "Louie"}]}
{"name": "Required field"}
webob.Request.GET or any
MultiDict/dict
Nested data structure
Form subclass with defined fields
Converters and validators
class Int(Converter):
def to_python(self, val):
if val == '':
return None
try:
return int(val)
except ValueError:
raise ValidationError(error_msg)
def from_python(self, val):
return unicode(val) if val is not None else ''
def validate(conv, value):
if not check(value):
raise ValidationError(error_msg)
return value.strip()
function for extra
validation and cleaning
can do additional one-way convertation
errors are written into form.errors
converts value to a string which is
included to raw_data MultiDict
Converts string (dict for FieldSet, list for FieldList) to python
object of target type
Converters usage
field1 = Field('id', conv=Int(num_limit(0,10), positive, require=True))
field2 = Field('ids', conv=ListOf(Int()))
field3 = Field('name', conv=ListOf(EnumChoice(choices=[(val, label), ..])))
field4 = field3(conv=field3.conv(required=True))
model_f = FieldSet('user',
conv=convs.ModelChoice(model=User),
fields=[Field('id', conv=Int()),
Field('name')])
Converts a dict
result of FieldSet
to sqlalchemy object
validators
Fields, converters, widgets are easy
to copy and tweak
is included to raw_data MultiDict
Converter
ids=1&ids=2 => {"ids" [1, 2]}
check if value is not empty
after convertation
multiple select
Widgets
Responsible for visual representation of an item
field1 = Field('id',
conv=Int(),
widget=TextInput(),
label='Id')
field3 = Field('options',
conv=ListOf(EnumChoice(choices=[(val, label), ..])),
widget=Select(template='widgets/custom-select.html'),
label='Options')
{{ form.render() }}
{{ form.get_field('id').widget.render() }}
 batteries
 converter and widget set, including HTML cleaner
 I18n for error message
iktomi-cms
Where do we use our forms?
iktomi-cms: #sqlalchemy #single-page #streams-for-models
#loners-for-single-objects #edit-log #autosave
#item-locks #preview #inboxes #two-state-publishing #multilingual-
models
https://github.com/SmartTeleMax/iktomi-cms
https://github.com/SmartTeleMax/iktomi-cms-demo
Ad

Recommended

Asp.net MVC DI
Asp.net MVC DI
LearningTech
sanest: sane nested dictionary and lists for python
sanest: sane nested dictionary and lists for python
wouter bolsterlee
Core dev summit
Core dev summit
Jeff Miccolis
Web Components changes Web Development
Web Components changes Web Development
Shogo Sensui
Presentation on structure,functions and classes
Presentation on structure,functions and classes
Alisha Korpal
PageObject
PageObject
MitinPavel
Introducing jQuery
Introducing jQuery
Wildan Maulana
Neo4j introduction
Neo4j introduction
Chakrit Phain
Don't fear our new robot overlords A new way to test on mobile
Don't fear our new robot overlords A new way to test on mobile
Philip Brechler
Extending Python - EuroPython 2014
Extending Python - EuroPython 2014
fcofdezc
Graph databases - EuroPython 2014
Graph databases - EuroPython 2014
fcofdezc
Message-passing concurrency in Python
Message-passing concurrency in Python
Sarah Mount
EuroPython 2014 - How we switched our 800+ projects from Apache to uWSGI
EuroPython 2014 - How we switched our 800+ projects from Apache to uWSGI
Max Tepkeev
Python, the next Brazilian generation
Python, the next Brazilian generation
FATEC S達o Jos辿 dos Campos
Developing RESTful Web APIs with Python, Flask and MongoDB
Developing RESTful Web APIs with Python, Flask and MongoDB
Nicola Iarocci
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
SAP Datasphere Catalog L2 (2024-02-07).pptx
SAP Datasphere Catalog L2 (2024-02-07).pptx
HimanshuSachdeva46
Transmission Media. (Computer Networks)
Transmission Media. (Computer Networks)
S Pranav (Deepu)
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
Insurance Underwriting Software Enhancing Accuracy and Efficiency
Insurance Underwriting Software Enhancing Accuracy and Efficiency
Insurance Tech Services
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
Zonerankers Digital marketing solutions
Zonerankers Digital marketing solutions
reenashriee
How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2

More Related Content

Viewers also liked (7)

Don't fear our new robot overlords A new way to test on mobile
Don't fear our new robot overlords A new way to test on mobile
Philip Brechler
Extending Python - EuroPython 2014
Extending Python - EuroPython 2014
fcofdezc
Graph databases - EuroPython 2014
Graph databases - EuroPython 2014
fcofdezc
Message-passing concurrency in Python
Message-passing concurrency in Python
Sarah Mount
EuroPython 2014 - How we switched our 800+ projects from Apache to uWSGI
EuroPython 2014 - How we switched our 800+ projects from Apache to uWSGI
Max Tepkeev
Python, the next Brazilian generation
Python, the next Brazilian generation
FATEC S達o Jos辿 dos Campos
Developing RESTful Web APIs with Python, Flask and MongoDB
Developing RESTful Web APIs with Python, Flask and MongoDB
Nicola Iarocci
Don't fear our new robot overlords A new way to test on mobile
Don't fear our new robot overlords A new way to test on mobile
Philip Brechler
Extending Python - EuroPython 2014
Extending Python - EuroPython 2014
fcofdezc
Graph databases - EuroPython 2014
Graph databases - EuroPython 2014
fcofdezc
Message-passing concurrency in Python
Message-passing concurrency in Python
Sarah Mount
EuroPython 2014 - How we switched our 800+ projects from Apache to uWSGI
EuroPython 2014 - How we switched our 800+ projects from Apache to uWSGI
Max Tepkeev
Developing RESTful Web APIs with Python, Flask and MongoDB
Developing RESTful Web APIs with Python, Flask and MongoDB
Nicola Iarocci

Recently uploaded (20)

Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
SAP Datasphere Catalog L2 (2024-02-07).pptx
SAP Datasphere Catalog L2 (2024-02-07).pptx
HimanshuSachdeva46
Transmission Media. (Computer Networks)
Transmission Media. (Computer Networks)
S Pranav (Deepu)
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
Insurance Underwriting Software Enhancing Accuracy and Efficiency
Insurance Underwriting Software Enhancing Accuracy and Efficiency
Insurance Tech Services
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
Zonerankers Digital marketing solutions
Zonerankers Digital marketing solutions
reenashriee
How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
Porting Qt 5 QML Modules to Qt 6 Webinar
Porting Qt 5 QML Modules to Qt 6 Webinar
ICS
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Technologies
What is data visualization and how data visualization tool can help.pptx
What is data visualization and how data visualization tool can help.pptx
Varsha Nayak
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
SAP Datasphere Catalog L2 (2024-02-07).pptx
SAP Datasphere Catalog L2 (2024-02-07).pptx
HimanshuSachdeva46
Transmission Media. (Computer Networks)
Transmission Media. (Computer Networks)
S Pranav (Deepu)
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
Insurance Underwriting Software Enhancing Accuracy and Efficiency
Insurance Underwriting Software Enhancing Accuracy and Efficiency
Insurance Tech Services
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
Zonerankers Digital marketing solutions
Zonerankers Digital marketing solutions
reenashriee
How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
Porting Qt 5 QML Modules to Qt 6 Webinar
Porting Qt 5 QML Modules to Qt 6 Webinar
ICS
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Technologies
What is data visualization and how data visualization tool can help.pptx
What is data visualization and how data visualization tool can help.pptx
Varsha Nayak
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
Ad

Iktomi forms

  • 1. iktomi forms a part of iktomi lib http://iktomi.readthedocs.org/
  • 2. Basics Validate user input Convert to internal representation Render forms, display validation error Work with nested data structures
  • 3. Abstraction layers Form Field (+ FieldSet, FieldList, FieldBlock) Converter Widget permissions (rw) raw and clean values
  • 4. Forms class UncleForm(Form): fields = [ Field('name'), FieldList('nephews', field=FieldSet(None, fields=[ Field('name'), ])), ] def process_form(env): form = UncleForm(env, initial=init) if form.accept(env.request.POST): data = form.python_data else: errors = form.errors {"name": "Scrooge", "nephews": [{"name": "Huey"}, {"name": "Dewey"}, {"name": "Louie"}]} {"name": "Required field"} webob.Request.GET or any MultiDict/dict Nested data structure Form subclass with defined fields
  • 5. Converters and validators class Int(Converter): def to_python(self, val): if val == '': return None try: return int(val) except ValueError: raise ValidationError(error_msg) def from_python(self, val): return unicode(val) if val is not None else '' def validate(conv, value): if not check(value): raise ValidationError(error_msg) return value.strip() function for extra validation and cleaning can do additional one-way convertation errors are written into form.errors converts value to a string which is included to raw_data MultiDict Converts string (dict for FieldSet, list for FieldList) to python object of target type
  • 6. Converters usage field1 = Field('id', conv=Int(num_limit(0,10), positive, require=True)) field2 = Field('ids', conv=ListOf(Int())) field3 = Field('name', conv=ListOf(EnumChoice(choices=[(val, label), ..]))) field4 = field3(conv=field3.conv(required=True)) model_f = FieldSet('user', conv=convs.ModelChoice(model=User), fields=[Field('id', conv=Int()), Field('name')]) Converts a dict result of FieldSet to sqlalchemy object validators Fields, converters, widgets are easy to copy and tweak is included to raw_data MultiDict Converter ids=1&ids=2 => {"ids" [1, 2]} check if value is not empty after convertation multiple select
  • 7. Widgets Responsible for visual representation of an item field1 = Field('id', conv=Int(), widget=TextInput(), label='Id') field3 = Field('options', conv=ListOf(EnumChoice(choices=[(val, label), ..])), widget=Select(template='widgets/custom-select.html'), label='Options') {{ form.render() }} {{ form.get_field('id').widget.render() }}
  • 8. batteries converter and widget set, including HTML cleaner I18n for error message
  • 9. iktomi-cms Where do we use our forms? iktomi-cms: #sqlalchemy #single-page #streams-for-models #loners-for-single-objects #edit-log #autosave #item-locks #preview #inboxes #two-state-publishing #multilingual- models https://github.com/SmartTeleMax/iktomi-cms https://github.com/SmartTeleMax/iktomi-cms-demo