SlideShare ist ein Scribd-Unternehmen logo
1 von 9
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Andere mochten auch

Andere mochten auch (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 mobileDon'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
 
Extending Python - EuroPython 2014
Extending Python - EuroPython 2014Extending Python - EuroPython 2014
Extending Python - EuroPython 2014
 
Graph databases - EuroPython 2014
Graph databases - EuroPython 2014Graph databases - EuroPython 2014
Graph databases - EuroPython 2014
 
Message-passing concurrency in Python
Message-passing concurrency in PythonMessage-passing concurrency in Python
Message-passing concurrency in Python
 
EuroPython 2014 - How we switched our 800+ projects from Apache to uWSGI
EuroPython 2014 - How we switched our 800+ projects from Apache to uWSGIEuroPython 2014 - How we switched our 800+ projects from Apache to uWSGI
EuroPython 2014 - How we switched our 800+ projects from Apache to uWSGI
 
Python, the next Brazilian generation
Python, the next Brazilian generationPython, the next Brazilian generation
Python, the next Brazilian generation
 
Developing RESTful Web APIs with Python, Flask and MongoDB
Developing RESTful Web APIs with Python, Flask and MongoDBDeveloping RESTful Web APIs with Python, Flask and MongoDB
Developing RESTful Web APIs with Python, Flask and MongoDB
 

Ähnlich wie Iktomi forms

HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
Dmitry Soshnikov
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
rajivmordani
 
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
philogb
 
JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de DatosJavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datos
philogb
 
Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)
Leonardo Soto
 
Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)
Leonardo Soto
 

Ähnlich wie Iktomi forms (20)

Building an api using golang and postgre sql v1.0
Building an api using golang and postgre sql v1.0Building an api using golang and postgre sql v1.0
Building an api using golang and postgre sql v1.0
 
Computational Social Science, Lecture 09: Data Wrangling
Computational Social Science, Lecture 09: Data WranglingComputational Social Science, Lecture 09: Data Wrangling
Computational Social Science, Lecture 09: Data Wrangling
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
Writing testable js [by Ted Piotrowski]
Writing testable js [by Ted Piotrowski]Writing testable js [by Ted Piotrowski]
Writing testable js [by Ted Piotrowski]
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
Rapid Prototyping with PEAR
Rapid Prototyping with PEARRapid Prototyping with PEAR
Rapid Prototyping with PEAR
 
Bubbles – Virtual Data Objects
Bubbles – Virtual Data ObjectsBubbles – Virtual Data Objects
Bubbles – Virtual Data Objects
 
IntroToCSharpcode.ppt
IntroToCSharpcode.pptIntroToCSharpcode.ppt
IntroToCSharpcode.ppt
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
 
JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de DatosJavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datos
 
GraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learnedGraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learned
 
Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)
 
Http4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackHttp4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web Stack
 
Day 1
Day 1Day 1
Day 1
 
Ajax for dummies, and not only.
Ajax for dummies, and not only.Ajax for dummies, and not only.
Ajax for dummies, and not only.
 
Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)
 
IN4308 Lecture 3
IN4308 Lecture 3IN4308 Lecture 3
IN4308 Lecture 3
 

Kürzlich hochgeladen

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Kürzlich hochgeladen (20)

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 

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