-
Notifications
You must be signed in to change notification settings - Fork 0
/
flatland_talk.html
1109 lines (1049 loc) · 91.7 KB
/
flatland_talk.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.6: http://docutils.sourceforge.net/" />
<meta name="version" content="S5 1.1" />
<title>Form Processing with Flatland</title>
<meta name="author" content="Scott Wilson" />
<meta name="date" content="21.07.2010" />
<style type="text/css">
.highlight .hll { background-color: #333333 }
.highlight { background: #111111; color: #ffffff }
.highlight .c { color: #008800; font-style: italic; background-color: #0f140f } /* Comment */
.highlight .err { color: #ffffff } /* Error */
.highlight .g { color: #ffffff } /* Generic */
.highlight .k { color: #fb660a; font-weight: bold } /* Keyword */
.highlight .l { color: #ffffff } /* Literal */
.highlight .n { color: #ffffff } /* Name */
.highlight .o { color: #ffffff } /* Operator */
.highlight .x { color: #ffffff } /* Other */
.highlight .p { color: #ffffff } /* Punctuation */
.highlight .cm { color: #008800; font-style: italic; background-color: #0f140f } /* Comment.Multiline */
.highlight .cp { color: #ff0007; font-weight: bold; font-style: italic; background-color: #0f140f } /* Comment.Preproc */
.highlight .c1 { color: #008800; font-style: italic; background-color: #0f140f } /* Comment.Single */
.highlight .cs { color: #008800; font-style: italic; background-color: #0f140f } /* Comment.Special */
.highlight .gd { color: #ffffff } /* Generic.Deleted */
.highlight .ge { color: #ffffff } /* Generic.Emph */
.highlight .gr { color: #ffffff } /* Generic.Error */
.highlight .gh { color: #ffffff; font-weight: bold } /* Generic.Heading */
.highlight .gi { color: #ffffff } /* Generic.Inserted */
.highlight .go { color: #444444; background-color: #222222 } /* Generic.Output */
.highlight .gp { color: #ffffff } /* Generic.Prompt */
.highlight .gs { color: #ffffff } /* Generic.Strong */
.highlight .gu { color: #ffffff; font-weight: bold } /* Generic.Subheading */
.highlight .gt { color: #ffffff } /* Generic.Traceback */
.highlight .kc { color: #fb660a; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #fb660a; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #fb660a; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #fb660a } /* Keyword.Pseudo */
.highlight .kr { color: #fb660a; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #cdcaa9; font-weight: bold } /* Keyword.Type */
.highlight .ld { color: #ffffff } /* Literal.Date */
.highlight .m { color: #0086f7; font-weight: bold } /* Literal.Number */
.highlight .s { color: #0086d2 } /* Literal.String */
.highlight .na { color: #ff0086; font-weight: bold } /* Name.Attribute */
.highlight .nb { color: #ffffff } /* Name.Builtin */
.highlight .nc { color: #ffffff } /* Name.Class */
.highlight .no { color: #0086d2 } /* Name.Constant */
.highlight .nd { color: #ffffff } /* Name.Decorator */
.highlight .ni { color: #ffffff } /* Name.Entity */
.highlight .ne { color: #ffffff } /* Name.Exception */
.highlight .nf { color: #ff0086; font-weight: bold } /* Name.Function */
.highlight .nl { color: #ffffff } /* Name.Label */
.highlight .nn { color: #ffffff } /* Name.Namespace */
.highlight .nx { color: #ffffff } /* Name.Other */
.highlight .py { color: #ffffff } /* Name.Property */
.highlight .nt { color: #fb660a; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #fb660a } /* Name.Variable */
.highlight .ow { color: #ffffff } /* Operator.Word */
.highlight .w { color: #888888 } /* Text.Whitespace */
.highlight .mf { color: #0086f7; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0086f7; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0086f7; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0086f7; font-weight: bold } /* Literal.Number.Oct */
.highlight .sb { color: #0086d2 } /* Literal.String.Backtick */
.highlight .sc { color: #0086d2 } /* Literal.String.Char */
.highlight .sd { color: #0086d2 } /* Literal.String.Doc */
.highlight .s2 { color: #0086d2 } /* Literal.String.Double */
.highlight .se { color: #0086d2 } /* Literal.String.Escape */
.highlight .sh { color: #0086d2 } /* Literal.String.Heredoc */
.highlight .si { color: #0086d2 } /* Literal.String.Interpol */
.highlight .sx { color: #0086d2 } /* Literal.String.Other */
.highlight .sr { color: #0086d2 } /* Literal.String.Regex */
.highlight .s1 { color: #0086d2 } /* Literal.String.Single */
.highlight .ss { color: #0086d2 } /* Literal.String.Symbol */
.highlight .bp { color: #ffffff } /* Name.Builtin.Pseudo */
.highlight .vc { color: #fb660a } /* Name.Variable.Class */
.highlight .vg { color: #fb660a } /* Name.Variable.Global */
.highlight .vi { color: #fb660a } /* Name.Variable.Instance */
.highlight .il { color: #0086f7; font-weight: bold } /* Literal.Number.Integer.Long */
</style>
<!-- configuration parameters -->
<meta name="defaultView" content="slideshow" />
<meta name="controlVis" content="hidden" />
<!-- style sheet links -->
<script src="ui/small-black/slides.js" type="text/javascript"></script>
<link rel="stylesheet" href="ui/small-black/slides.css"
type="text/css" media="projection" id="slideProj" />
<link rel="stylesheet" href="ui/small-black/outline.css"
type="text/css" media="screen" id="outlineStyle" />
<link rel="stylesheet" href="ui/small-black/print.css"
type="text/css" media="print" id="slidePrint" />
<link rel="stylesheet" href="ui/small-black/opera.css"
type="text/css" media="projection" id="operaFix" />
<style type="text/css">
#currentSlide {display: none;}
</style>
</head>
<body>
<div class="layout">
<div id="controls"></div>
<div id="currentSlide"></div>
<div id="header">
</div>
<div id="footer">
<h1>Form Processing with <em>Flatland</em></h1>
<h2>Europython 2010, Birmingham - <a class="reference external" href="http://discorporate.us/projects/flatland/">http://discorporate.us/projects/flatland/</a></h2>
</div>
</div>
<div class="presentation">
<div class="slide" id="slide0">
<h1 class="title">Form Processing with <em>Flatland</em></h1>
<table class="docinfo" frame="void" rules="none">
<col class="docinfo-name" />
<col class="docinfo-content" />
<tbody valign="top">
<tr><th class="docinfo-name">Author:</th>
<td><strong class="first last">Scott Wilson</strong></td></tr>
<tr class="field"><th class="docinfo-name">email:</th><td class="field-body"><a class="reference external" href="mailto:scott@idealist.org">scott@idealist.org</a></td>
</tr>
<tr><th class="docinfo-name">Date:</th>
<td>21.07.2010</td></tr>
</tbody>
</table>
<!-- Definitions of interpreted text roles (classes) for S5/HTML data. -->
<!-- This data file has been placed in the public domain. -->
<!-- Colours
======= -->
<!-- Text Sizes
========== -->
<!-- Display in Slides (Presentation Mode) Only
========================================== -->
<!-- Display in Outline Mode Only
============================ -->
<!-- Display in Print Only
===================== -->
<!-- Display in Handout Mode Only
============================ -->
<!-- Incremental Display
=================== -->
<img alt="images/idealist.gif" class="center" src="images/idealist.gif" />
</div>
<div class="slide" id="the-plan">
<h1>The Plan</h1>
<ul class="simple">
<li>Quick statement of the problem</li>
<li>The gory details on using flatland</li>
<li>Some interesting applications and future directions</li>
</ul>
</div>
<div class="slide" id="forms">
<h1>Forms?</h1>
<div class="line-block">
<div class="line"><br /></div>
</div>
<img alt="images/github.jpg" class="center" src="images/github.jpg" />
<div class="line-block">
<div class="line"><br /></div>
</div>
<img alt="images/guardian.jpg" src="images/guardian.jpg" />
</div>
<div class="slide" id="webkit-inspector-very-useful">
<h1>WebKit Inspector - Very Useful!</h1>
<img alt="images/headers.jpg" src="images/headers.jpg" />
</div>
<div class="slide" id="form-processing">
<h1>Form Processing?</h1>
<p><span class="incremental">1. Type Conversion</span></p>
<p><span class="incremental">2. Validation</span></p>
<p><span class="incremental">3. Processing / Storage</span></p>
<p><span class="incremental">4. Redisplay</span></p>
</div>
<div class="slide" id="type-conversion">
<h1>1. Type Conversion</h1>
<div class="highlight"><pre><span class="s">'1'</span> <span class="o">=></span> <span class="mi">1</span>
<span class="s">'1999-12-31'</span> <span class="o">=></span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="p">(</span><span class="mi">1999</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">31</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="s">'yes'</span> <span class="o">=></span> <span class="bp">True</span>
</pre></div>
</div>
<div class="slide" id="validation">
<h1>2. Validation</h1>
<ul class="simple">
<li><span class="incremental">Was value type-converted successfully?</span></li>
<li><span class="incremental">Is date valid?</span></li>
<li><span class="incremental">Is page number > 0 ?</span></li>
<li><span class="incremental">Is email address in a valid format?</span></li>
<li><span class="incremental">Does a confirmation field match its pair?</span></li>
</ul>
</div>
<div class="slide" id="processing-storage">
<h1>3. Processing / Storage</h1>
<ul class="simple">
<li><span class="incremental">Trigger an API call</span></li>
<li><span class="incremental">Populate a model object and store it in a database</span></li>
<li><span class="incremental">Kick off some asynchronous processing.</span></li>
<li><span class="incremental">Generate a search result</span></li>
<li><span class="incremental">...</span></li>
</ul>
</div>
<div class="slide" id="redisplay">
<h1>4. Redisplay</h1>
<ul class="simple">
<li><span class="incremental">Populate a form from model object or other data source</span></li>
<li><span class="incremental">Redisplay the submitted form data with validation feedback</span></li>
</ul>
</div>
<div class="slide" id="other-related-tools">
<h1>Other Related Tools</h1>
<ul class="simple">
<li>WTForms</li>
<li>Django</li>
<li>FormEncode</li>
<li>FormBuilder</li>
<li>Lots of others</li>
</ul>
</div>
<div class="slide" id="what-is-flatland">
<h1>What is Flatland?</h1>
<p>A schema-driven mapping toolkit providing:</p>
<ul class="simple">
<li><span class="incremental">Transformation of data between flat key-value representations and rich python data structures.</span></li>
<li><span class="incremental">Optional validation of the state of the form regardless of where the data originated.</span></li>
<li><span class="incremental">Declarative schema decription language</span></li>
<li><span class="incremental">Support for arbitrily complex structures</span></li>
</ul>
</div>
<div class="slide" id="simple-example">
<h1>Simple example</h1>
<div class="highlight"><pre><span class="kn">from</span> <span class="nn">flatland</span> <span class="kn">import</span> <span class="n">Dict</span><span class="p">,</span> <span class="n">Float</span>
<span class="n">MySpot</span> <span class="o">=</span> <span class="n">Dict</span><span class="o">.</span><span class="n">of</span><span class="p">(</span>
<span class="n">Float</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">'latitude'</span><span class="p">),</span>
<span class="n">Float</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">'longitude'</span><span class="p">)</span>
<span class="p">)</span>
</pre></div>
</div>
<div class="slide" id="simple-example-declarative">
<h1>Simple example - Declarative</h1>
<div class="highlight"><pre><span class="kn">from</span> <span class="nn">flatland</span> <span class="kn">import</span> <span class="n">Float</span><span class="p">,</span> <span class="n">Form</span>
<span class="k">class</span> <span class="nc">MySpot</span><span class="p">(</span><span class="n">Form</span><span class="p">):</span>
<span class="n">latitude</span> <span class="o">=</span> <span class="n">Float</span>
<span class="n">longitude</span> <span class="o">=</span> <span class="n">Float</span>
</pre></div>
<div class="line-block">
<div class="line"><br /></div>
</div>
<p><strong>Form</strong> is a sublcass of <strong>Dict</strong> that adds the declarative syntax.</p>
<p><em>Note that the latitude and longitude properties of MySpot are ultimately removed.</em></p>
</div>
<div class="slide" id="setting-values">
<h1>Setting values</h1>
<div class="highlight"><pre><span class="c"># By passing a dictionary to the constructor</span>
<span class="o">>>></span> <span class="n">el</span> <span class="o">=</span> <span class="n">MySpot</span><span class="p">({</span><span class="s">'latitude'</span><span class="p">:</span> <span class="mf">52.48</span><span class="p">,</span> <span class="s">'longitude'</span><span class="p">:</span> <span class="o">-</span><span class="mf">1.89</span><span class="p">})</span>
<span class="o">>>></span> <span class="n">el</span>
<span class="p">{</span><span class="s">u'latitude'</span><span class="p">:</span> <span class="o"><</span><span class="n">Float</span> <span class="s">u'latitude'</span><span class="p">;</span> <span class="n">value</span><span class="o">=</span><span class="mf">52.48</span><span class="o">></span><span class="p">,</span>
<span class="s">u'longitude'</span><span class="p">:</span> <span class="o"><</span><span class="n">Float</span> <span class="s">u'longitude'</span><span class="p">;</span> <span class="n">value</span><span class="o">=-</span><span class="mf">1.89</span><span class="o">></span><span class="p">}</span>
<span class="c"># Check the native python value</span>
<span class="o">>>></span> <span class="n">el</span><span class="o">.</span><span class="n">value</span>
<span class="p">{</span><span class="s">u'latitude'</span><span class="p">:</span> <span class="mf">52.48</span><span class="p">,</span> <span class="s">u'longitude'</span><span class="p">:</span> <span class="o">-</span><span class="mf">1.89</span><span class="p">}</span>
<span class="c"># Set values on an existing instance using .set</span>
<span class="o">>>></span> <span class="n">el</span><span class="o">.</span><span class="n">set</span><span class="p">({</span><span class="s">'latitude'</span><span class="p">:</span> <span class="mf">1.0</span><span class="p">,</span> <span class="s">'longitude'</span><span class="p">:</span> <span class="o">-</span><span class="mf">1.0</span><span class="p">})</span>
<span class="o">>>></span> <span class="n">el</span><span class="o">.</span><span class="n">value</span>
<span class="p">{</span><span class="s">u'latitude'</span><span class="p">:</span> <span class="mf">1.0</span><span class="p">,</span> <span class="s">u'longitude'</span><span class="p">:</span> <span class="o">-</span><span class="mf">1.0</span><span class="p">}</span>
</pre></div>
</div>
<div class="slide" id="flattening-values">
<h1>Flattening values</h1>
<div class="highlight"><pre><span class="o">>>></span> <span class="n">el</span> <span class="o">=</span> <span class="n">MySpot</span><span class="p">({</span><span class="s">'latitude'</span><span class="p">:</span> <span class="mf">52.48</span><span class="p">,</span> <span class="s">'longitude'</span><span class="p">:</span> <span class="o">-</span><span class="mf">1.89</span><span class="p">})</span>
<span class="o">>>></span> <span class="n">el</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span>
<span class="p">[(</span><span class="s">u'latitude'</span><span class="p">,</span> <span class="s">u'52.480000'</span><span class="p">),</span>
<span class="p">(</span><span class="s">u'longitude'</span><span class="p">,</span> <span class="s">u'-1.890000'</span><span class="p">)]</span>
</pre></div>
</div>
<div class="slide" id="setting-values-from-objects">
<h1>Setting values from objects</h1>
<div class="highlight"><pre><span class="c"># Simple point object</span>
<span class="o">>>></span> <span class="n">Point</span> <span class="o">=</span> <span class="n">namedtuple</span><span class="p">(</span><span class="s">'Point'</span><span class="p">,</span> <span class="s">'latitude'</span><span class="p">,</span> <span class="s">'longitude'</span><span class="p">)</span>
<span class="o">>>></span> <span class="n">pt</span> <span class="o">=</span> <span class="n">Point</span><span class="p">(</span><span class="mf">52.48</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.89</span><span class="p">)</span>
<span class="c"># Construct using from_object factory method</span>
<span class="o">>>></span> <span class="n">el</span> <span class="o">=</span> <span class="n">MySpot</span><span class="o">.</span><span class="n">from_object</span><span class="p">(</span><span class="n">pt</span><span class="p">)</span>
<span class="c"># python value</span>
<span class="o">>>></span> <span class="n">el</span><span class="o">.</span><span class="n">value</span>
<span class="p">{</span><span class="s">u'latitude'</span><span class="p">:</span> <span class="mf">52.48</span><span class="p">,</span> <span class="s">u'longitude'</span><span class="p">:</span> <span class="o">-</span><span class="mf">1.89</span><span class="p">}</span>
</pre></div>
</div>
<div class="slide" id="default-values">
<h1>Default Values</h1>
<div class="highlight"><pre><span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span>
<span class="kn">from</span> <span class="nn">flatland</span> <span class="kn">import</span> <span class="n">Form</span><span class="p">,</span> <span class="n">DateTime</span><span class="p">,</span> <span class="n">Integer</span>
<span class="k">class</span> <span class="nc">GroceryList</span><span class="p">(</span><span class="n">Form</span><span class="p">):</span>
<span class="n">eggs</span> <span class="o">=</span> <span class="n">Integer</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">default</span><span class="o">=</span><span class="mi">12</span><span class="p">)</span>
<span class="n">due</span> <span class="o">=</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">default</span><span class="o">=</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">())</span>
<span class="c"># Construct using the from_defaults factory method</span>
<span class="o">>>></span> <span class="n">GroceryList</span><span class="o">.</span><span class="n">from_defaults</span><span class="p">()</span><span class="o">.</span><span class="n">value</span>
<span class="p">{</span><span class="s">u'eggs'</span><span class="p">:</span> <span class="mi">12</span><span class="p">,</span>
<span class="s">u'due'</span><span class="p">:</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="p">(</span><span class="mi">2010</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">23</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">812918</span><span class="p">)}</span>
</pre></div>
</div>
<div class="slide" id="to-and-from-flat">
<h1>To and From Flat</h1>
<div class="highlight"><pre><span class="c"># Construct using the from_flat factory method</span>
<span class="o">>>></span> <span class="n">gl</span> <span class="o">=</span> <span class="n">GroceryList</span><span class="o">.</span><span class="n">from_flat</span><span class="p">(</span>
<span class="p">[(</span><span class="s">'eggs'</span><span class="p">,</span> <span class="mi">9</span><span class="p">),</span> <span class="p">(</span><span class="s">'due'</span><span class="p">,</span> <span class="s">'2010-07-20 23:04:00'</span><span class="p">)]</span>
<span class="p">)</span>
<span class="c"># Native python value</span>
<span class="o">>>></span> <span class="n">gl</span><span class="o">.</span><span class="n">value</span>
<span class="p">{</span><span class="s">u'eggs'</span><span class="p">:</span> <span class="mi">9</span><span class="p">,</span> <span class="s">u'due'</span><span class="p">:</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="p">(</span><span class="mi">2010</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">23</span><span class="p">,</span> <span class="mi">4</span><span class="p">)}</span>
<span class="c"># Flat value</span>
<span class="o">>>></span> <span class="n">gl</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span>
<span class="p">[(</span><span class="s">u'eggs'</span><span class="p">,</span> <span class="s">u'9'</span><span class="p">),</span> <span class="p">(</span><span class="s">u'due'</span><span class="p">,</span> <span class="s">u'2010-07-20 23:04:00'</span><span class="p">)]</span>
</pre></div>
</div>
<div class="slide" id="slice">
<h1>Slice</h1>
<div class="highlight"><pre><span class="o">>>></span> <span class="n">gl</span> <span class="o">=</span> <span class="n">GroceryList</span><span class="p">({</span><span class="s">'eggs'</span><span class="p">:</span> <span class="mi">8</span><span class="p">,</span> <span class="s">'due'</span><span class="p">:</span> <span class="s">'1997-01-01'</span><span class="p">})</span>
<span class="c"># Only pull out eggs</span>
<span class="o">>>></span> <span class="n">gl</span><span class="o">.</span><span class="n">slice</span><span class="p">([</span><span class="s">'eggs'</span><span class="p">])</span>
<span class="p">{</span><span class="s">u'eggs'</span><span class="p">:</span> <span class="mi">8</span><span class="p">}</span>
<span class="c"># Omit due and rename eggs as huevos</span>
<span class="o">>>></span> <span class="n">gl</span><span class="o">.</span><span class="n">slice</span><span class="p">(</span><span class="n">omit</span><span class="o">=</span><span class="p">[</span><span class="s">'due'</span><span class="p">],</span> <span class="n">rename</span><span class="o">=</span><span class="p">[(</span><span class="s">'eggs'</span><span class="p">,</span> <span class="s">'huevos'</span><span class="p">)])</span>
<span class="p">{</span><span class="s">'huevos'</span><span class="p">:</span> <span class="mi">8</span><span class="p">}</span>
</pre></div>
</div>
<div class="slide" id="elements">
<h1>Elements</h1>
<div class="highlight"><pre><span class="c"># Construct</span>
<span class="o">>>></span> <span class="n">Num</span> <span class="o">=</span> <span class="n">Integer</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">'anumber'</span><span class="p">)</span>
<span class="o">>>></span> <span class="n">Num</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="o"><</span><span class="n">Integer</span> <span class="s">u'anumber'</span><span class="p">;</span> <span class="n">value</span><span class="o">=</span><span class="mi">4</span><span class="o">></span>
<span class="c"># Get native python value</span>
<span class="o">>>></span> <span class="n">Num</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">value</span>
<span class="mi">4</span>
<span class="c"># Get unicode value</span>
<span class="o">>>></span> <span class="n">Num</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">u</span>
<span class="s">u'4'</span>
</pre></div>
</div>
<div class="slide" id="elements-work-just-like-forms">
<h1>Elements - Work just like Forms</h1>
<div class="highlight"><pre><span class="c"># Construct</span>
<span class="o">>>></span> <span class="n">Num</span><span class="o">.</span><span class="n">from_flat</span><span class="p">([(</span><span class="s">'anumber'</span><span class="p">,</span> <span class="s">'4'</span><span class="p">)])</span>
<span class="o"><</span><span class="n">Integer</span> <span class="s">u'anumber'</span><span class="p">;</span> <span class="n">value</span><span class="o">=</span><span class="mi">4</span><span class="o">></span>
<span class="c"># Flatten</span>
<span class="o">>>></span> <span class="n">Num</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span>
<span class="p">[(</span><span class="s">u'anumber'</span><span class="p">,</span> <span class="s">u'4'</span><span class="p">)]</span>
</pre></div>
</div>
<div class="slide" id="scalar-element-types">
<h1>Scalar Element Types</h1>
<ul class="simple">
<li>Boolean</li>
<li>Date</li>
<li>DateTime</li>
<li>Decimal</li>
<li>Enum</li>
<li>Float</li>
<li>Integer</li>
<li>Long</li>
<li>String</li>
<li>Time</li>
</ul>
</div>
<div class="slide" id="container-element-types">
<h1>Container Element Types</h1>
<ul class="simple">
<li>Array</li>
<li>Dict</li>
<li>List</li>
<li>MultiValue</li>
<li>SparseDict</li>
</ul>
</div>
<div class="slide" id="compound-element-types">
<h1>Compound Element Types</h1>
<ul class="simple">
<li>DateYYYYMMDD</li>
<li>JoinedString</li>
<li>... so far</li>
</ul>
</div>
<div class="slide" id="validation-converted">
<h1>Validation - Converted</h1>
<div class="highlight"><pre><span class="o">>>></span> <span class="kn">from</span> <span class="nn">flatland</span> <span class="kn">import</span> <span class="n">Integer</span>
<span class="o">>>></span> <span class="kn">from</span> <span class="nn">flatland.validation</span> <span class="kn">import</span> <span class="n">Converted</span>
<span class="c"># With an input that can be coerced to an integer</span>
<span class="o">>>></span> <span class="n">nn</span> <span class="o">=</span> <span class="n">Integer</span><span class="p">(</span><span class="s">'123'</span><span class="p">)</span>
<span class="o">>>></span> <span class="n">Converted</span><span class="p">()</span><span class="o">.</span><span class="n">validate</span><span class="p">(</span><span class="n">nn</span><span class="p">,</span> <span class="p">{})</span>
<span class="bp">True</span>
<span class="c"># With an input that *cannot* be coerced to an integer</span>
<span class="o">>>></span> <span class="n">nn</span> <span class="o">=</span> <span class="n">Integer</span><span class="p">(</span><span class="s">'abc'</span><span class="p">)</span>
<span class="o">>>></span> <span class="n">Converted</span><span class="p">()</span><span class="o">.</span><span class="n">validate</span><span class="p">(</span><span class="n">nn</span><span class="p">,</span> <span class="p">{})</span>
<span class="bp">False</span>
<span class="o">>>></span> <span class="n">nn</span><span class="o">.</span><span class="n">errors</span>
<span class="p">[</span><span class="s">u'None is not correct.'</span><span class="p">]</span>
</pre></div>
</div>
<div class="slide" id="validation-present">
<h1>Validation - Present</h1>
<div class="highlight"><pre><span class="o">>>></span> <span class="kn">from</span> <span class="nn">flatland</span> <span class="kn">import</span> <span class="n">Integer</span>
<span class="o">>>></span> <span class="kn">from</span> <span class="nn">flatland.validation</span> <span class="kn">import</span> <span class="n">Present</span>
<span class="c"># Present validates on any value (e.g. an invalid email address)</span>
<span class="o">>>></span> <span class="n">nn</span> <span class="o">=</span> <span class="n">Integer</span><span class="p">(</span><span class="s">'abc'</span><span class="p">)</span>
<span class="o">>>></span> <span class="n">Present</span><span class="p">()</span><span class="o">.</span><span class="n">validate</span><span class="p">(</span><span class="n">nn</span><span class="p">,</span> <span class="p">{})</span>
<span class="bp">True</span>
<span class="o">>>></span> <span class="n">nn</span> <span class="o">=</span> <span class="n">Integer</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">'quantity'</span><span class="p">)()</span>
<span class="o">>>></span> <span class="n">Present</span><span class="p">()</span><span class="o">.</span><span class="n">validate</span><span class="p">(</span><span class="n">nn</span><span class="p">,</span> <span class="p">{})</span>
<span class="bp">False</span>
<span class="o">>>></span> <span class="n">nn</span><span class="o">.</span><span class="n">errors</span>
<span class="p">[</span><span class="s">'quantity may not be blank.'</span><span class="p">]</span>
</pre></div>
</div>
<div class="slide" id="validation-optional-flag">
<h1>Validation - optional flag</h1>
<div class="highlight"><pre><span class="o">>>></span> <span class="kn">from</span> <span class="nn">flatland</span> <span class="kn">import</span> <span class="n">Integer</span>
<span class="o">>>></span> <span class="kn">from</span> <span class="nn">flatland.validation</span> <span class="kn">import</span> <span class="n">Present</span>
<span class="c"># With optional=False (default)</span>
<span class="o">>>></span> <span class="n">MyInt</span> <span class="o">=</span> <span class="n">Integer</span><span class="o">.</span><span class="n">validated_by</span><span class="p">(</span><span class="n">Present</span><span class="p">())</span>\
<span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">optional</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="o">>>></span> <span class="n">MyInt</span><span class="p">()</span><span class="o">.</span><span class="n">validate</span><span class="p">()</span>
<span class="bp">False</span>
<span class="c"># With optional=True</span>
<span class="c"># validators are not evaluated when value == None</span>
<span class="o">>>></span> <span class="n">MyInt</span> <span class="o">=</span> <span class="n">Integer</span><span class="o">.</span><span class="n">validated_by</span><span class="p">(</span><span class="n">Present</span><span class="p">())</span>\
<span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">optional</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="o">>>></span> <span class="n">MyInt</span><span class="p">()</span><span class="o">.</span><span class="n">validate</span><span class="p">()</span>
<span class="bp">True</span>
</pre></div>
</div>
<div class="slide" id="validation-error-messges">
<h1>Validation - Error Messges</h1>
<div class="highlight"><pre><span class="o">>>></span> <span class="n">nn</span> <span class="o">=</span> <span class="n">Integer</span><span class="p">()</span>
<span class="c"># Override the error message for the</span>
<span class="c"># *missing* failure mode in the constructor.</span>
<span class="c"># Some validators encapsulate multiple</span>
<span class="c"># failure modes.</span>
<span class="o">>>></span> <span class="n">Present</span><span class="p">(</span><span class="n">missing</span><span class="o">=</span><span class="s">'Where is it??'</span><span class="p">)</span><span class="o">.</span><span class="n">validate</span><span class="p">(</span><span class="n">nn</span><span class="p">,</span> <span class="p">{})</span>
<span class="bp">False</span>
<span class="o">>>></span> <span class="n">nn</span><span class="o">.</span><span class="n">errors</span>
<span class="p">[</span><span class="s">'Where is it??'</span><span class="p">]</span>
</pre></div>
</div>
<div class="slide" id="validators-scalars">
<h1>Validators - Scalars</h1>
<ul class="simple">
<li>ValueBetwen</li>
<li>LengthBetween</li>
<li>ValueGreaterThan</li>
<li>ValuesEqual</li>
<li>IsTrue</li>
<li>IsFalse</li>
<li>IsEmail</li>
<li>URLValidator</li>
<li>...</li>
</ul>
</div>
<div class="slide" id="validators-container">
<h1>Validators - Container</h1>
<ul class="simple">
<li>HasAtLeast</li>
<li>HasAtMost</li>
<li>NotDuplicated</li>
</ul>
</div>
<div class="slide" id="custom-validator">
<h1>Custom Validator</h1>
<div class="highlight"><pre><span class="k">class</span> <span class="nc">ValidWikiName</span><span class="p">(</span><span class="n">Validator</span><span class="p">):</span>
<span class="n">fail</span> <span class="o">=</span> <span class="n">N_</span><span class="p">(</span><span class="s">'A wiki name is only valid when the ...'</span><span class="p">)</span>
<span class="n">name_re</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s">'^[A-Z][a-z]\w*$'</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">validate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">element</span><span class="p">,</span> <span class="n">state</span><span class="p">):</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">name_re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">element</span><span class="o">.</span><span class="n">u</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">note_error</span><span class="p">(</span><span class="n">element</span><span class="p">,</span> <span class="n">state</span><span class="p">,</span> <span class="s">'fail'</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">True</span>
</pre></div>
</div>
<div class="slide" id="validation-example-on-form">
<h1>Validation Example - On Form</h1>
<iframe src="demo/passwords-form" width="350" height="400"style="float: right"></iframe><div class="highlight"><pre><span class="k">class</span> <span class="nc">PasswordCompareForm</span><span class="p">(</span><span class="n">Form</span><span class="p">):</span>
<span class="n">password</span> <span class="o">=</span> <span class="n">String</span><span class="o">.</span><span class="n">using</span><span class="p">(</span>
<span class="n">label</span><span class="o">=</span><span class="s">'New Password'</span><span class="p">,</span>
<span class="n">validators</span><span class="o">=</span><span class="p">[</span>
<span class="n">Present</span><span class="p">(),</span>
<span class="n">LengthBetween</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">25</span><span class="p">)</span>
<span class="p">])</span>
<span class="n">confirm</span> <span class="o">=</span> <span class="n">String</span><span class="o">.</span><span class="n">using</span><span class="p">(</span>
<span class="n">label</span><span class="o">=</span><span class="s">'Repeat Password'</span><span class="p">,</span>
<span class="n">validators</span><span class="o">=</span><span class="p">[</span><span class="n">Present</span><span class="p">()]</span>
<span class="p">)</span>
<span class="n">validators</span> <span class="o">=</span> <span class="p">[</span>
<span class="n">ValuesEqual</span><span class="p">(</span>
<span class="s">'password'</span><span class="p">,</span>
<span class="s">'confirm'</span>
<span class="p">)</span>
<span class="p">]</span>
</pre></div>
</div>
<div class="slide" id="validation-example-on-element">
<h1>Validation Example - On Element</h1>
<iframe src="demo/passwords-element" width="350" height="400"style="float: right"></iframe><div class="highlight"><pre><span class="k">class</span> <span class="nc">PasswordCompareElement</span><span class="p">(</span><span class="n">Form</span><span class="p">):</span>
<span class="n">password</span> <span class="o">=</span> <span class="n">String</span><span class="o">.</span><span class="n">using</span><span class="p">(</span>
<span class="n">label</span><span class="o">=</span><span class="s">'New Password'</span><span class="p">,</span>
<span class="n">validators</span><span class="o">=</span><span class="p">[</span>
<span class="n">Present</span><span class="p">(),</span>
<span class="n">LengthBetween</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">25</span><span class="p">)</span>
<span class="p">]</span>
<span class="p">)</span>
<span class="n">confirm</span> <span class="o">=</span> <span class="n">String</span><span class="o">.</span><span class="n">using</span><span class="p">(</span>
<span class="n">label</span><span class="o">=</span><span class="s">'Repeat Password'</span><span class="p">,</span>
<span class="n">validators</span><span class="o">=</span><span class="p">[</span>
<span class="n">Present</span><span class="p">(),</span>
<span class="n">ValuesEqual</span><span class="p">(</span>
<span class="s">'.'</span><span class="p">,</span>
<span class="s">'../password'</span>
<span class="p">)]</span>
<span class="p">)</span>
</pre></div>
</div>
<div class="slide" id="nested-structure">
<h1>Nested Structure</h1>
<div class="highlight"><pre><span class="k">class</span> <span class="nc">ContactForm</span><span class="p">(</span><span class="n">Form</span><span class="p">):</span>
<span class="n">name</span> <span class="o">=</span> <span class="n">String</span><span class="o">.</span><span class="n">validated_by</span><span class="p">(</span><span class="n">Present</span><span class="p">())</span>
<span class="n">addresses</span> <span class="o">=</span> <span class="n">List</span><span class="o">.</span><span class="n">of</span><span class="p">(</span>
<span class="n">Dict</span><span class="o">.</span><span class="n">of</span><span class="p">(</span>
<span class="n">String</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">'street'</span><span class="p">),</span>
<span class="n">String</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">'city'</span><span class="p">),</span>
<span class="n">String</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">'country'</span><span class="p">),</span>
<span class="n">List</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">'phone_numbers'</span><span class="p">)</span><span class="o">.</span><span class="n">of</span><span class="p">(</span>
<span class="n">Dict</span><span class="o">.</span><span class="n">of</span><span class="p">(</span>
<span class="n">String</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">'label'</span><span class="p">),</span>
<span class="n">String</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">'number'</span><span class="p">)</span>
<span class="p">)</span>
<span class="p">)</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">default</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="p">)</span>
<span class="p">)</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">default</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
</pre></div>
</div>
<div class="slide" id="nested-structure-nested-forms">
<h1>Nested Structure - Nested Forms</h1>
<div class="highlight"><pre><span class="k">class</span> <span class="nc">PhoneNumber</span><span class="p">(</span><span class="n">Form</span><span class="p">):</span>
<span class="n">label</span> <span class="o">=</span> <span class="n">String</span>
<span class="n">number</span> <span class="o">=</span> <span class="n">String</span>
<span class="k">class</span> <span class="nc">Address</span><span class="p">(</span><span class="n">Form</span><span class="p">):</span>
<span class="n">street</span> <span class="o">=</span> <span class="n">String</span>
<span class="n">city</span> <span class="o">=</span> <span class="n">String</span>
<span class="n">country</span> <span class="o">=</span> <span class="n">String</span>
<span class="n">phone_numbers</span> <span class="o">=</span> <span class="n">List</span><span class="o">.</span><span class="n">of</span><span class="p">(</span><span class="n">PhoneNumber</span>
<span class="p">)</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">default</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">ContactForm</span><span class="p">(</span><span class="n">Form</span><span class="p">):</span>
<span class="n">name</span> <span class="o">=</span> <span class="n">String</span><span class="o">.</span><span class="n">validated_by</span><span class="p">(</span><span class="n">Present</span><span class="p">())</span>
<span class="n">addresses</span> <span class="o">=</span> <span class="n">List</span><span class="o">.</span><span class="n">of</span><span class="p">(</span><span class="n">Address</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">default</span><span class="o">=</span><span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<div class="slide" id="path-lookup">
<h1>Path Lookup</h1>
<div class="highlight"><pre><span class="n">form</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s">'/name'</span><span class="p">)</span>
<span class="n">form</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s">'addresses[0]'</span><span class="p">)</span>
<span class="n">form</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s">'addresses[0]/phone_numbers[0]/number'</span><span class="p">)</span>
</pre></div>
</div>
<div class="slide" id="flattening-nested-structures">
<h1>Flattening Nested Structures</h1>
<div class="highlight"><pre><span class="o">>>></span> <span class="n">el</span> <span class="o">=</span> <span class="n">ContactForm</span><span class="p">(</span><span class="n">value</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'John'</span><span class="p">))</span>
<span class="o">>>></span> <span class="n">el</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span>
<span class="p">[(</span><span class="s">u'name'</span><span class="p">,</span> <span class="s">u'John'</span><span class="p">)]</span>
<span class="o">>>></span> <span class="n">el</span><span class="p">[</span><span class="s">'addresses'</span><span class="p">]</span> <span class="o">=</span> <span class="p">[{</span><span class="s">'street'</span><span class="p">:</span> <span class="s">'123 Bay St.'</span><span class="p">,</span>
<span class="s">'city'</span><span class="p">:</span> <span class="s">'Toronto'</span><span class="p">,</span>
<span class="s">'country'</span><span class="p">:</span> <span class="s">'CA'</span><span class="p">,</span>
<span class="s">'phone_numbers'</span><span class="p">:</span> <span class="p">[]}]</span>
<span class="o">>>></span> <span class="n">el</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span>
<span class="p">[(</span><span class="s">u'name'</span><span class="p">,</span> <span class="s">u'John'</span><span class="p">),</span>
<span class="p">(</span><span class="s">u'addresses_0_street'</span><span class="p">,</span> <span class="s">u'123 Bay St.'</span><span class="p">),</span>
<span class="p">(</span><span class="s">u'addresses_0_city'</span><span class="p">,</span> <span class="s">u'Toronto'</span><span class="p">),</span>
<span class="p">(</span><span class="s">u'addresses_0_country'</span><span class="p">,</span> <span class="s">u'CA'</span><span class="p">)]</span>
</pre></div>
</div>
<div class="slide" id="defaults-factory-for-nested-schema">
<h1>Defaults factory for Nested Schema</h1>
<ul class="simple">
<li>Useful when populating a template rendering context for a clean web form</li>
</ul>
<div class="highlight"><pre><span class="o">>>></span> <span class="n">el</span><span class="o">.</span><span class="n">ContactForm</span><span class="o">.</span><span class="n">from_defaults</span><span class="p">()</span>
<span class="o">>>></span> <span class="n">el</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span>
<span class="p">[(</span><span class="s">u'name'</span><span class="p">,</span> <span class="s">u''</span><span class="p">),</span> <span class="p">(</span><span class="s">u'addresses_0_city'</span><span class="p">,</span> <span class="s">u''</span><span class="p">),</span>
<span class="p">(</span><span class="s">u'addresses_0_street'</span><span class="p">,</span> <span class="s">u''</span><span class="p">),</span>
<span class="p">(</span><span class="s">u'addresses_0_country'</span><span class="p">,</span> <span class="s">u''</span><span class="p">),</span>
<span class="p">(</span><span class="s">u'addresses_0_phone_numbers_0_number'</span><span class="p">,</span> <span class="s">u''</span><span class="p">),</span>
<span class="p">(</span><span class="s">u'addresses_0_phone_numbers_0_label'</span><span class="p">,</span> <span class="s">u''</span><span class="p">)]</span>
</pre></div>
</div>
<div class="slide" id="output-generation">
<h1>Output Generation</h1>
<div class="highlight"><pre><span class="o">>>></span> <span class="kn">from</span> <span class="nn">flatland</span> <span class="kn">import</span> <span class="n">String</span>
<span class="o">>>></span> <span class="kn">from</span> <span class="nn">flatland.out.markup</span> <span class="kn">import</span> <span class="n">Generator</span>
<span class="o">>>></span> <span class="n">field</span> <span class="o">=</span> <span class="n">String</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">'eggs'</span><span class="p">)(</span><span class="s">'brown'</span><span class="p">)</span>
<span class="c"># Construct a markup generator</span>
<span class="o">>>></span> <span class="n">gen</span> <span class="o">=</span> <span class="n">Generator</span><span class="p">()</span>
<span class="c"># Render field as an input tag</span>
<span class="o">>>></span> <span class="n">gen</span><span class="o">.</span><span class="n">input</span><span class="p">(</span><span class="n">field</span><span class="p">)</span>
<span class="s">u'<input name="eggs" value="brown" />'</span>
<span class="c"># Generate dom ids when rendering</span>
<span class="o">>>></span> <span class="n">gen</span><span class="p">[</span><span class="s">'auto_domid'</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>
<span class="o">>>></span> <span class="n">gen</span><span class="o">.</span><span class="n">input</span><span class="p">(</span><span class="n">field</span><span class="p">)</span>
<span class="s">u'<input name="eggs" value="brown" id="f_eggs" />'</span>
</pre></div>
</div>
<div class="slide" id="output-generation-labels">
<h1>Output Generation - Labels</h1>
<div class="highlight"><pre><span class="o">>>></span> <span class="n">field</span> <span class="o">=</span> <span class="n">String</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">'eggs'</span><span class="p">)(</span><span class="s">'brown'</span><span class="p">)</span>
<span class="o">>>></span> <span class="n">gen</span> <span class="o">=</span> <span class="n">Generator</span><span class="p">(</span><span class="n">auto_for</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="c"># Render explicit open ...</span>
<span class="o">>>></span> <span class="n">gen</span><span class="o">.</span><span class="n">label</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">field</span><span class="p">)</span>
<span class="s">u'<label for="f_eggs">'</span>
<span class="o">>>></span> <span class="n">gen</span><span class="o">.</span><span class="n">input</span><span class="p">(</span><span class="n">field</span><span class="p">)</span>
<span class="s">u'<input name="eggs" value="brown" />'</span>
<span class="c"># ... and close tags for wrapping tags</span>
<span class="c"># (e.g. label, form, textarea)</span>
<span class="o">>>></span> <span class="n">gen</span><span class="o">.</span><span class="n">label</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="s">u'</label>'</span>
</pre></div>
</div>
<div class="slide" id="output-generation-tabindex">
<h1>Output Generation - tabindex</h1>
<div class="highlight"><pre><span class="o">>>></span> <span class="n">field</span> <span class="o">=</span> <span class="n">String</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">'eggs'</span><span class="p">)(</span><span class="s">'brown'</span><span class="p">)</span>
<span class="o">>>></span> <span class="n">gen</span> <span class="o">=</span> <span class="n">Generator</span><span class="p">(</span><span class="n">auto_tabindex</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">tabindex</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="o">>>></span> <span class="n">gen</span><span class="o">.</span><span class="n">input</span><span class="p">(</span><span class="n">field</span><span class="p">)</span>
<span class="s">u'<input name="eggs" value="brown" tabindex="1" />'</span>
<span class="o">>>></span> <span class="n">gen</span><span class="o">.</span><span class="n">input</span><span class="p">(</span><span class="n">field</span><span class="p">)</span>
<span class="s">u'<input name="eggs" value="brown" tabindex="2" />'</span>
</pre></div>
</div>
<div class="slide" id="output-generation-options">
<h1>Output Generation Options</h1>
<div class="highlight"><pre><span class="o">>>></span> <span class="n">Generator</span><span class="p">()</span>
<span class="n">Generator</span><span class="p">({</span>
<span class="s">u'auto_filter'</span><span class="p">:</span> <span class="bp">False</span><span class="p">,</span>
<span class="s">u'markup_wrapper'</span><span class="p">:</span> <span class="o"><</span><span class="k">class</span> <span class="err">'</span><span class="nc">flatland</span><span class="o">.</span><span class="n">out</span><span class="o">.</span><span class="n">generic</span><span class="o">.</span><span class="n">Markup</span><span class="s">'>,</span>
<span class="s">u'auto_domid'</span><span class="p">:</span> <span class="bp">False</span><span class="p">,</span>
<span class="s">u'ordered_attributes'</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span>
<span class="s">u'auto_name'</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span>
<span class="s">u'auto_tabindex'</span><span class="p">:</span> <span class="bp">False</span><span class="p">,</span>
<span class="s">u'auto_for'</span><span class="p">:</span> <span class="bp">False</span><span class="p">,</span>
<span class="s">u'filters'</span><span class="p">:</span> <span class="p">(),</span>
<span class="s">u'auto_value'</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span>
<span class="s">u'tabindex'</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
<span class="s">u'domid_format'</span><span class="p">:</span> <span class="s">u'f_</span><span class="si">%s</span><span class="s">'</span><span class="p">})</span>
</pre></div>
</div>
<div class="slide" id="output-filters">
<h1>Output filters</h1>
<div class="highlight"><pre><span class="kn">from</span> <span class="nn">flatland</span> <span class="kn">import</span> <span class="n">Integer</span>
<span class="kn">from</span> <span class="nn">flatland.out.markup</span> <span class="kn">import</span> <span class="n">Generator</span>
<span class="k">def</span> <span class="nf">error_filter</span><span class="p">(</span><span class="n">tagname</span><span class="p">,</span> <span class="n">attrs</span><span class="p">,</span> <span class="n">contents</span><span class="p">,</span>
<span class="n">context</span><span class="p">,</span> <span class="n">bind</span><span class="p">):</span>
<span class="sd">"""When we encounter a bind element</span>
<span class="sd"> having errors, set the rendered</span>
<span class="sd"> tag's class property to 'error'."""</span>
<span class="k">if</span> <span class="n">bind</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">bind</span><span class="o">.</span><span class="n">errors</span><span class="p">:</span>
<span class="n">attrs</span><span class="p">[</span><span class="s">'class'</span><span class="p">]</span> <span class="o">=</span> <span class="s">'error'</span>
<span class="k">return</span> <span class="n">contents</span>
<span class="c"># Bind error_filter to input tags generation</span>
<span class="n">error_filter</span><span class="o">.</span><span class="n">tags</span> <span class="o">=</span> <span class="p">(</span><span class="s">'input'</span><span class="p">,)</span>
</pre></div>
</div>
<div class="slide" id="output-filters-cont-d">
<h1>Output filters - cont'd</h1>
<div class="highlight"><pre><span class="n">gen</span> <span class="o">=</span> <span class="n">Generator</span><span class="p">(</span><span class="n">auto_filter</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
<span class="n">filters</span><span class="o">=</span><span class="p">[</span><span class="n">error_filter</span><span class="p">])</span>
<span class="o">>>></span> <span class="n">num</span> <span class="o">=</span> <span class="n">Integer</span><span class="o">.</span><span class="n">validated_by</span><span class="p">(</span><span class="n">Converted</span><span class="p">())(</span><span class="s">'abc'</span><span class="p">)</span>
<span class="o">>>></span> <span class="n">num</span><span class="o">.</span><span class="n">validate</span><span class="p">()</span>
<span class="bp">False</span>
<span class="o">>>></span> <span class="n">num</span><span class="o">.</span><span class="n">errors</span>
<span class="p">[</span><span class="s">u'None is not correct.'</span><span class="p">]</span>
<span class="o">>>></span> <span class="n">gen</span><span class="o">.</span><span class="n">input</span><span class="p">(</span><span class="n">num</span><span class="p">)</span>
<span class="s">u'<input value="abc" class="error" />'</span>
</pre></div>
</div>
<div class="slide" id="output-generation-jinja2">
<h1>Output Generation - Jinja2</h1>
<div class="highlight"><pre><span class="kn">from</span> <span class="nn">flatland.out.markup</span> <span class="kn">import</span> <span class="n">Generator</span>
<span class="kn">from</span> <span class="nn">jinja2</span> <span class="kn">import</span> <span class="n">Markup</span>
<span class="n">gen</span> <span class="o">=</span> <span class="n">Generator</span><span class="p">(</span><span class="n">markup_wrapper</span><span class="o">=</span><span class="n">Markup</span><span class="p">)</span>
<span class="k">return</span> <span class="n">render_template</span><span class="p">(</span><span class="s">'password.html'</span><span class="p">,</span>
<span class="n">form</span><span class="o">=</span><span class="n">form</span><span class="p">,</span> <span class="n">generator</span><span class="o">=</span><span class="n">gen</span><span class="p">)</span>
</pre></div>
<div class="highlight"><pre><span class="nt"><dt></span>
<span class="cp">{{</span> <span class="nv">gen.label.open</span><span class="o">(</span><span class="nv">field</span><span class="o">)</span> <span class="cp">}}</span>
<span class="cp">{{</span> <span class="nv">field.label</span> <span class="cp">}}</span>
<span class="cp">{{</span> <span class="nv">gen.label.close</span><span class="o">()</span> <span class="cp">}}</span>
<span class="nt"></dt></span>
<span class="nt"><dd></span>
<span class="cp">{{</span> <span class="nv">gen.input</span><span class="o">(</span><span class="nv">field</span><span class="o">)</span> <span class="cp">}}</span>
<span class="nt"></dd></span>
</pre></div>
</div>
<div class="slide" id="output-generation-jinja2-cont-d">
<h1>Output Generation - Jinja2 (cont'd)</h1>
<div class="highlight"><pre><span class="cp">{%</span> <span class="k">macro</span> <span class="nv">render_errors</span><span class="o">(</span><span class="nv">field</span><span class="o">)</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">if</span> <span class="nv">field.errors</span> <span class="cp">%}</span>
<span class="nt"><ul</span> <span class="na">class=</span><span class="s">"error"</span><span class="nt">></span>
<span class="cp">{%</span> <span class="k">for</span> <span class="nv">error</span> <span class="k">in</span> <span class="nv">field.errors</span> <span class="cp">%}</span>
<span class="nt"><li></span><span class="cp">{{</span> <span class="nv">error</span> <span class="cp">}}</span><span class="nt"></li></span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
<span class="nt"></ul></span>
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">endmacro</span> <span class="cp">%}</span>
</pre></div>
<hr class="docutils" />
<p>An Extension in progress to easy integration of flatland with flask.</p>
</div>
<div class="slide" id="genshi-output-template">
<h1>Genshi Output - Template</h1>
<div class="highlight"><pre><span class="nt"><form</span> <span class="na">xmlns=</span><span class="s">"http://www.w3.org/1999/xhtml"</span>
<span class="na">xmlns:py=</span><span class="s">"http://genshi.edgewall.org/"</span>
<span class="na">xmlns:form=</span><span class="s">"http://ns.discorporate.us/flatland/genshi"</span>
<span class="na">form:bind=</span><span class="s">"form"</span><span class="nt">></span>
<span class="nt"><form:with</span> <span class="na">auto_domid=</span><span class="s">"on"</span> <span class="na">auto_for=</span><span class="s">"on"</span><span class="nt">></span>
<span class="nt"><label</span> <span class="na">py:with=</span><span class="s">"</span><span class="n">el</span><span class="o">=</span><span class="n">form</span><span class="o">.</span><span class="n">password</span><span class="s">"</span> <span class="na">form:bind=</span><span class="s">"el"</span><span class="nt">></span>
<span class="cp">${</span><span class="n">el</span><span class="o">.</span><span class="n">label</span><span class="cp">}</span>: <span class="nt"><input</span> <span class="na">form:bind=</span><span class="s">"el"</span> <span class="nt">/></span>
<span class="nt"></label></span>
<span class="nt"><label</span> <span class="na">py:with=</span><span class="s">"</span><span class="n">el</span><span class="o">=</span><span class="n">form</span><span class="o">.</span><span class="n">confirm</span><span class="s">"</span> <span class="na">form:bind=</span><span class="s">"el"</span><span class="nt">></span>
<span class="cp">${</span><span class="n">el</span><span class="o">.</span><span class="n">label</span><span class="cp">}</span>: <span class="nt"><input</span> <span class="na">form:bind=</span><span class="s">"el"</span> <span class="nt">/></span>
<span class="nt"></label></span>
<span class="nt"><button</span> <span class="na">value=</span><span class="s">"Submit"</span> <span class="nt">/></span>
<span class="nt"></form:with></span>
<span class="nt"></form></span>
</pre></div>
</div>
<div class="slide" id="genshi-output-result">
<h1>Genshi Output - Result</h1>
<div class="highlight"><pre><span class="nt"><form</span> <span class="na">xmlns=</span><span class="s">"http://www.w3.org/1999/xhtml"</span><span class="nt">></span>
<span class="nt"><label</span> <span class="na">for=</span><span class="s">"f_password"</span><span class="nt">></span>
New Password:
<span class="nt"><input</span> <span class="na">name=</span><span class="s">"password"</span> <span class="na">value=</span><span class="s">""</span> <span class="na">id=</span><span class="s">"f_password"</span> <span class="nt">/></span>
<span class="nt"></label></span>
<span class="nt"><label</span> <span class="na">for=</span><span class="s">"f_confirm"</span><span class="nt">></span>
Repeat Password:
<span class="nt"><input</span> <span class="na">name=</span><span class="s">"confirm"</span> <span class="na">value=</span><span class="s">""</span> <span class="na">id=</span><span class="s">"f_confirm"</span> <span class="nt">/></span>
<span class="nt"></label></span>
<span class="nt"><button</span> <span class="na">value=</span><span class="s">"Submit"</span><span class="nt">></button></span>
<span class="nt"></form></span>
</pre></div>
</div>
<div class="slide" id="genshi-output-code">
<h1>Genshi Output - Code</h1>
<div class="highlight"><pre><span class="kn">from</span> <span class="nn">genshi.template</span> <span class="kn">import</span> <span class="n">MarkupTemplate</span>
<span class="kn">from</span> <span class="nn">flatland.out.genshi_06</span> <span class="kn">import</span> <span class="n">setup</span>
<span class="n">template</span> <span class="o">=</span> <span class="n">MarkupTemplate</span><span class="p">(</span><span class="n">markup</span><span class="p">)</span>
<span class="n">setup</span><span class="p">(</span><span class="n">template</span><span class="p">)</span>
<span class="n">kw</span> <span class="o">=</span> <span class="p">{</span><span class="s">'form'</span><span class="p">:</span> <span class="n">PasswordCompareForm</span><span class="p">()</span> <span class="p">}</span>
<span class="n">output</span> <span class="o">=</span> <span class="n">template</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="o">**</span><span class="n">kw</span><span class="p">)</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="s">'xhtml'</span><span class="p">)</span>
</pre></div>
</div>
<div class="slide" id="idealist-example">
<h1>Idealist example</h1>
<img alt="images/registration_form.jpg" src="images/registration_form.jpg" />
</div>
<div class="slide" id="compound-field-example">
<h1>Compound field example</h1>
<div class="highlight"><pre><span class="k">class</span> <span class="nc">Location</span><span class="p">(</span><span class="n">Compound</span><span class="p">):</span>
<span class="n">levels</span> <span class="o">=</span> <span class="p">[</span><span class="s">'country'</span><span class="p">,</span> <span class="s">'state'</span><span class="p">,</span> <span class="s">'city'</span><span class="p">,</span> <span class="s">'street_address'</span><span class="p">,</span> <span class="s">'postal_code'</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">__compound_init__</span><span class="p">(</span><span class="n">cls</span><span class="p">):</span>
<span class="n">cls</span><span class="o">.</span><span class="n">field_schema</span> <span class="o">=</span> <span class="p">[</span>
<span class="n">Country</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'country'</span><span class="p">,</span>
<span class="n">label</span><span class="o">=</span><span class="n">N_</span><span class="p">(</span><span class="s">'Country'</span><span class="p">),</span>
<span class="n">optional</span><span class="o">=</span><span class="n">optional</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
<span class="n">validators</span><span class="o">=</span><span class="p">[</span>
<span class="n">Present</span><span class="p">(),</span>
<span class="n">Converted</span><span class="p">()]),</span>
<span class="n">State</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'state'</span><span class="p">,</span>
<span class="n">label</span><span class="o">=</span><span class="n">N_</span><span class="p">(</span><span class="s">'Province, region, state, or territory'</span><span class="p">),</span>
<span class="n">optional</span><span class="o">=</span><span class="n">optional</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
<span class="n">validators</span><span class="o">=</span><span class="p">[</span>
<span class="n">ValidState</span><span class="p">()]),</span>
<span class="n">String</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'city'</span><span class="p">,</span>
<span class="n">label</span><span class="o">=</span><span class="n">N_</span><span class="p">(</span><span class="s">'City/Town'</span><span class="p">),</span>
<span class="n">optional</span><span class="o">=</span><span class="n">optional</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span>
<span class="n">validators</span><span class="o">=</span><span class="p">[</span>
<span class="n">Present</span><span class="p">(),</span>
<span class="n">NoLongerThan</span><span class="p">(</span><span class="mi">255</span><span class="p">)]),</span>
</pre></div>
</div>
<div class="slide" id="compound-field-cont-d">
<h1>Compound Field cont'd</h1>
<div class="highlight"><pre><span class="k">def</span> <span class="nf">compose</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">"""Emits an AssetAddress object."""</span>
<span class="n">aa</span> <span class="o">=</span> <span class="n">AssetAddress</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">update_object</span><span class="p">(</span><span class="n">aa</span><span class="p">,</span> <span class="n">omit</span><span class="o">=</span><span class="s">'autonomous'</span><span class="p">)</span>
<span class="k">return</span> <span class="s">""</span><span class="p">,</span> <span class="n">aa</span>
<span class="k">def</span> <span class="nf">explode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="sd">"""Consumes an AssetAddress object."""</span>
<span class="k">if</span> <span class="n">value</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="k">return</span>
<span class="k">for</span> <span class="n">field</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">levels</span><span class="p">:</span>
<span class="bp">self</span><span class="p">[</span><span class="n">field</span><span class="p">]</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">field</span><span class="p">)</span>
<span class="k">if</span> <span class="n">value</span><span class="o">.</span><span class="n">id</span><span class="p">:</span>
<span class="bp">self</span><span class="p">[</span><span class="s">'id'</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">id</span>
</pre></div>
</div>
<div class="slide" id="other-applications">
<h1>Other applications</h1>
<ul class="simple">
<li><span class="incremental">REST Service</span></li>
<li><span class="incremental">JSON</span></li>
<li><span class="incremental">Config validation</span></li>
<li><span class="incremental">argv</span></li>
<li><span class="incremental">Cookies</span></li>
<li><span class="incremental">noSQL</span></li>
</ul>
</div>
<div class="slide" id="api-with-multiple-inputs">
<h1>API with multiple inputs</h1>
<img alt="images/guardian.jpg" src="images/guardian.jpg" />
</div>
<div class="slide" id="idealist-postgresql-hstore">
<h1>Idealist Postgresql / HSTORE</h1>
<p>Custom SQLAlchemy column type</p>
<ul class="simple">
<li>Serializes data structures into queryable / indexable key-value store.</li>
<li>Allows non-critical aspects of the schema to evolve over time with
minimal obstacles and migration headaches.</li>
<li>Allows us to store a whole series of <em>mostly</em> identical object types
in a single table.</li>
<li>Primarily concerned with type conversion and marshalling, less so
with validation.</li>
<li>Duck typing</li>
<li>Sparse storage.</li>
</ul>
</div>
<div class="slide" id="idealist-skeleton-schema">
<h1>Idealist Skeleton Schema</h1>
<div class="highlight"><pre><span class="c"># Generated from a more PM friendly format</span>
<span class="n">ContentProperties</span> <span class="o">=</span> <span class="n">flatland</span><span class="o">.</span><span class="n">SparseDict</span><span class="o">.</span><span class="n">of</span><span class="p">(</span>
<span class="n">flatland</span><span class="o">.</span><span class="n">String</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">"access"</span>
<span class="p">)</span><span class="o">.</span><span class="n">validated_by</span><span class="p">(</span><span class="n">converted</span><span class="p">)</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">optional</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="n">flatland</span><span class="o">.</span><span class="n">String</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">"access_other"</span>
<span class="p">)</span><span class="o">.</span><span class="n">validated_by</span><span class="p">(</span><span class="n">converted</span><span class="p">)</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">optional</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="n">flatland</span><span class="o">.</span><span class="n">DateTime</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">"attendee_registration_end_date"</span>
<span class="p">)</span><span class="o">.</span><span class="n">validated_by</span><span class="p">(</span><span class="n">converted</span><span class="p">)</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">optional</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="n">flatland</span><span class="o">.</span><span class="n">DateTime</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">"attendee_registration_start_date"</span>
<span class="p">)</span><span class="o">.</span><span class="n">validated_by</span><span class="p">(</span><span class="n">converted</span><span class="p">)</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">optional</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="n">NullableBoolean</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">"can_bring_guests"</span>
<span class="p">)</span><span class="o">.</span><span class="n">validated_by</span><span class="p">(</span><span class="n">converted</span><span class="p">)</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">optional</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="n">flatland</span><span class="o">.</span><span class="n">Integer</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">"cost"</span>
<span class="p">)</span><span class="o">.</span><span class="n">validated_by</span><span class="p">(</span><span class="n">converted</span><span class="p">)</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">optional</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="p">)</span>
</pre></div>
</div>
<div class="slide" id="idealist-preference-schema">
<h1>Idealist Preference Schema</h1>
<div class="highlight"><pre><span class="k">class</span> <span class="nc">PreferenceSchema</span><span class="p">(</span><span class="n">Form</span><span class="p">):</span>
<span class="sd">"""Flatland schema describing preferences. """</span>
<span class="c"># Setting policy to 'duck' tells the form</span>
<span class="c"># to set values for any subset of input</span>
<span class="c"># keys that match the schema while ignoring</span>
<span class="c"># those that don't.</span>
<span class="n">policy</span> <span class="o">=</span> <span class="s">'duck'</span>
</pre></div>
</div>
<div class="slide" id="idealist-preferences-extract">
<h1>Idealist Preferences Extract</h1>
<div class="highlight"><pre><span class="k">class</span> <span class="nc">UserPreferenceSchema</span><span class="p">(</span><span class="n">PreferenceSchema</span><span class="p">):</span>
<span class="n">profile</span> <span class="o">=</span> <span class="n">Dict</span><span class="o">.</span><span class="n">of</span><span class="p">(</span>
<span class="n">Enum</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">'visibility'</span><span class="p">)</span><span class="o">.</span><span class="n">valued</span><span class="p">(</span>
<span class="s">'any'</span><span class="p">,</span> <span class="s">'connected'</span><span class="p">,</span> <span class="s">'member'</span><span class="p">,</span> <span class="s">'none'</span>
<span class="p">)</span><span class="o">.</span><span class="n">using</span><span class="p">(</span>
<span class="n">default</span><span class="o">=</span><span class="s">'member'</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">N_</span><span class="p">(</span><span class="s">'Who can see my profile'</span><span class="p">)</span>
<span class="p">))</span>
<span class="n">communication</span> <span class="o">=</span> <span class="n">Dict</span><span class="o">.</span><span class="n">of</span><span class="p">(</span>
<span class="n">Boolean</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">'html_email'</span><span class="p">)</span><span class="o">.</span><span class="n">using</span><span class="p">(</span>
<span class="n">default</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">true</span><span class="o">=</span><span class="s">u'on'</span><span class="p">,</span> <span class="n">false</span><span class="o">=</span><span class="s">u'off'</span><span class="p">,</span>
<span class="n">label</span><span class="o">=</span><span class="n">N_</span><span class="p">(</span><span class="s">'Receive email in HTML format.'</span><span class="p">)),</span>
<span class="n">Boolean</span><span class="o">.</span><span class="n">named</span><span class="p">(</span><span class="s">'do_not_mail'</span><span class="p">)</span><span class="o">.</span><span class="n">using</span><span class="p">(</span>
<span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">true</span><span class="o">=</span><span class="s">u'on'</span><span class="p">,</span> <span class="n">false</span><span class="o">=</span><span class="s">u'off'</span><span class="p">,</span>
<span class="n">label</span><span class="o">=</span><span class="n">N_</span><span class="p">(</span><span class="s">'Do not send any email.'</span><span class="p">)),</span>
<span class="p">)</span>
</pre></div>
</div>
<div class="slide" id="xodb">
<h1>xodb</h1>
<div class="line-block">
<div class="line"><br /></div>
</div>
<p>Xapian object database for Python.</p>
<p>Object schema and transformation rules defined using extended
flatland elements.</p>
<ul class="simple">
<li>Prefixed or unprefixed</li>
<li>To facet or not to facet?</li>
</ul>
</div>
<div class="slide" id="xodb-imagine-a-model-class">
<h1>xodb - Imagine a model class</h1>
<div class="line-block">
<div class="line"><br /></div>
</div>
<div class="highlight"><pre><span class="k">class</span> <span class="nc">Department</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">employees</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
<span class="bp">self</span><span class="o">.</span><span class="n">employees</span> <span class="o">=</span> <span class="n">employees</span>
</pre></div>
</div>
<div class="slide" id="xodb-create-a-schema">
<h1>xodb - Create a Schema</h1>
<div class="line-block">
<div class="line"><br /></div>
</div>
<div class="highlight"><pre><span class="kn">from</span> <span class="nn">xodb</span> <span class="kn">import</span> <span class="n">Schema</span><span class="p">,</span> <span class="n">String</span><span class="p">,</span> <span class="n">Array</span>
<span class="k">class</span> <span class="nc">DepartmentSchema</span><span class="p">(</span><span class="n">Schema</span><span class="p">):</span>
<span class="n">language</span> <span class="o">=</span> <span class="n">String</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">default</span><span class="o">=</span><span class="s">"en"</span><span class="p">)</span>
<span class="n">name</span> <span class="o">=</span> <span class="n">String</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">facet</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">employees</span> <span class="o">=</span> <span class="n">Array</span><span class="o">.</span><span class="n">of</span><span class="p">(</span>
<span class="n">String</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">facet</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="p">)</span>
</pre></div>
</div>
<div class="slide" id="xodb-associate">
<h1>xodb - Associate</h1>
<p>Create an index and associate schema to model class:</p>
<div class="highlight"><pre><span class="kn">import</span> <span class="nn">xodb</span>
<span class="n">db</span> <span class="o">=</span> <span class="n">xodb</span><span class="o">.</span><span class="n">temp</span><span class="p">()</span>
<span class="n">db</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="n">Department</span><span class="p">,</span> <span class="n">DepartmentSchema</span><span class="p">)</span>
</pre></div>
</div>
<div class="slide" id="xodb-flatten">
<h1>xodb - Flatten</h1>
<p>Now, create some departments:</p>
<div class="highlight"><pre><span class="n">housing</span> <span class="o">=</span> <span class="n">Department</span><span class="p">(</span><span class="s">"housing"</span><span class="p">,</span> <span class="p">[</span><span class="s">'bob'</span><span class="p">,</span> <span class="s">'jane'</span><span class="p">])</span>
<span class="n">monkeys</span> <span class="o">=</span> <span class="n">Department</span><span class="p">(</span><span class="s">"monkeys"</span><span class="p">,</span> <span class="p">[</span><span class="s">'bob'</span><span class="p">,</span> <span class="s">'rick'</span><span class="p">])</span>
</pre></div>
<p>and add them to the database:</p>
<div class="highlight"><pre><span class="n">db</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">housing</span><span class="p">,</span> <span class="n">monkeys</span><span class="p">)</span>
<span class="n">db</span><span class="o">.</span><span class="n">backend</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>
</pre></div>
</div>
<div class="slide" id="xodb-retrieve">
<h1>xodb - Retrieve</h1>
<div class="line-block">
<div class="line"><br /></div>
</div>
<div class="highlight"><pre><span class="k">assert</span> <span class="n">db</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="s">"name:monkeys"</span>
<span class="p">)</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="s">"monkeys"</span>
</pre></div>
<div class="highlight"><pre><span class="k">assert</span> <span class="n">db</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="s">"employees:jane"</span>
<span class="p">)</span><span class="o">.</span><span class="n">next</span><span class="p">()</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="s">"housing"</span>