SlideShare a Scribd company logo
1 of 31
Django a modo mio: makosafare + Alessandro Dentella
Avviso ai naviganti ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Perchè sostituire i template? Una questione di pigrizia...
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
python nei template ,[object Object],[object Object],Per il resto django è splendido...
definizione di una form #- general data user  email first_name last_name  #- bith data birth_date T=time city  state  -- s=Add
Django in gran sintesi ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Cenni su: Tralascio :
schema sintetico (Jacob)
schema essenziale GET o POST: /ticket/ticket/ (r'^ticket/ticket?$', 'ticket.views.my_view') HttpResponse urls.py views.py ,[object Object],[object Object],[object Object]
urls.py from django.conf.urls.defaults import * urlpatterns = patterns('', (r'^admin/', include('django.contrib.admin.urls.admin')), (r'^jobs/', include('djproject.jobs.urls')), ) Nel progetto: Nella application
La view ,[object Object],[object Object],[object Object],[object Object],[object Object],NOTA: tutta la manipolazione dei dati avviene nella view.
Il modello
modello ,[object Object],[object Object],[object Object],[object Object]
queryset ,[object Object],[object Object],[object Object],[object Object]
filter() ,[object Object],[object Object],[object Object],[object Object],[object Object]
dati, validazione, html ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Pensiamo ad un campo 'date' del db:
fields/widget ,[object Object],[object Object],[object Object],Ovvero:
Ancora field - widgets Impariamo dai doctests >>> w = TextInput() >>> w.render('email', '') u'<input type=&quot;text&quot; name=&quot;email&quot;> >>> import datetime >>> f = DateField() >>> f.clean(datetime.date(2006, 10, 25)) datetime.date(2006, 10, 25) >>> f.clean('10/25/2006') datetime.date(2006, 10, 25)
Form ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Creare la form: via Form e metaclassi >>> class Person(Form): ...  first_name = CharField() ...  last_name = CharField() ...  birthday = DateField() Pass a dictionary to a Form's __init__(). >>> p = Person({'first_name': u'John', 'last_name': u'Lennon', 'birthday': u'1940-10-9'}) >>> p.is_bound True >>> p.errors {} >>> p.is_valid() True >>> p.errors.as_ul() u'' >>> p.errors.as_text() u'' >>> p.clean_data {'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} >>> print p['first_name'] <input type=&quot;text&quot; name=&quot;first_name&quot; value=&quot;John&quot; id=&quot;id_first_name&quot; />
Form
template <%!  from  jungle.templatetags.jungle_tags  import  offset_txt %> L'utente  ${ticket.submitter}  ha aperto il ticket # ${ticket.id} per il tuo progetto ' ${ticket.project.name} ':  ID: ${ticket.id}  Titolo: ${ticket.title}   Descrizione: ${offset_txt(ticket.description)} Priorita': ${ticket.get_priority_display()} Il mail ti è inviato in qualità di  ${title} ---------------------------------------------------------------- Puoi vedere questo ticket qui: ${&quot;%s/ticket/ticket/%s/&quot; % (jun.host_url(), ticket.id)}
sintesi del percorso con form aggiunta dati GET: /ticket/ticket/add/ urls.py view creazione form  per generare html template response POST: /ticket/ticket/add/ + {'a':'b'} urls.py view creazione form  per usare dati redirect response
Al lavoro! prepara il template! ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],<tr><td> <label for=&quot;id_city&quot;>City:</label> {{ form.city }} {% if form.city.errors %}*** {{ form.city.errors|join:&quot;, &quot; }}{% endif %} </td><td> <label for=&quot;id_state&quot;>State:</label> {{ form.state }} {% if form.state.errors %}*** {{ form.state.errors|join:&quot;, &quot; }}{% endif %} </td></tr> o cosi: o alla jungle way...: city  state
concretamente <%def name=&quot;layout()&quot;> city state <%/def> ${forms.mako_table_data(context, layout, obj, ) }
basta chiacchiere! Ora vai al serverino di sviluppo e  mostra qualcosa dal vivo. Per chi segue da casa: http://jungle.thundersystems.it Non dimenticare i manager del modello!
object_list from jungle.views.fast_search import search2 filter_cnd, order_by, form =  search2( request, model, order_by=order_by, **kw) if filter_cnd: queryset = queryset.filter(**filter_cnd) if order_by: queryset = queryset.order_by(order_by) hai dimenticato i manager, vero?
debug: pdb ieri abbiamo visto come WSGI permetta di entrare a debuggare  ciò che succede ed intervenire. Usando il server di sviluppo  di django possiamo usare pdb.set_trace() in qualunque punto ed  otteniamo una sessione interattiva!!!
test ,[object Object],[object Object],[object Object]
considerazioni sullo sviluppo ,[object Object],[object Object],[object Object],[object Object],[object Object]
Ringraziamenti ,[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

Pycrashcourse
PycrashcoursePycrashcourse
Pycrashcourserik0
 
Ajax Primi Passi Per Iniziare
Ajax Primi Passi Per IniziareAjax Primi Passi Per Iniziare
Ajax Primi Passi Per Iniziareastanco
 
Introduzione al linguaggio PHP
Introduzione al linguaggio PHPIntroduzione al linguaggio PHP
Introduzione al linguaggio PHPextrategy
 
Consigli per iniziare tdd
Consigli per iniziare tddConsigli per iniziare tdd
Consigli per iniziare tddTassoman ☺
 
PHP:funzioni e interazione con MySQL
PHP:funzioni e interazione con MySQLPHP:funzioni e interazione con MySQL
PHP:funzioni e interazione con MySQLextrategy
 
Javascript - 7 | WebMaster & WebDesigner
Javascript - 7 | WebMaster & WebDesignerJavascript - 7 | WebMaster & WebDesigner
Javascript - 7 | WebMaster & WebDesignerMatteo Magni
 
JavaScript Object Oriented
JavaScript Object OrientedJavaScript Object Oriented
JavaScript Object OrientedManuel Scapolan
 
JAMP DAY 2010 - ROMA (4)
JAMP DAY 2010 - ROMA (4)JAMP DAY 2010 - ROMA (4)
JAMP DAY 2010 - ROMA (4)jampslide
 

What's hot (10)

PHP 7 - benvenuto al futuro
PHP 7 - benvenuto al futuroPHP 7 - benvenuto al futuro
PHP 7 - benvenuto al futuro
 
Pycrashcourse
PycrashcoursePycrashcourse
Pycrashcourse
 
Ajax Primi Passi Per Iniziare
Ajax Primi Passi Per IniziareAjax Primi Passi Per Iniziare
Ajax Primi Passi Per Iniziare
 
Introduzione al linguaggio PHP
Introduzione al linguaggio PHPIntroduzione al linguaggio PHP
Introduzione al linguaggio PHP
 
Perl Template Toolkit
Perl Template ToolkitPerl Template Toolkit
Perl Template Toolkit
 
Consigli per iniziare tdd
Consigli per iniziare tddConsigli per iniziare tdd
Consigli per iniziare tdd
 
PHP:funzioni e interazione con MySQL
PHP:funzioni e interazione con MySQLPHP:funzioni e interazione con MySQL
PHP:funzioni e interazione con MySQL
 
Javascript - 7 | WebMaster & WebDesigner
Javascript - 7 | WebMaster & WebDesignerJavascript - 7 | WebMaster & WebDesigner
Javascript - 7 | WebMaster & WebDesigner
 
JavaScript Object Oriented
JavaScript Object OrientedJavaScript Object Oriented
JavaScript Object Oriented
 
JAMP DAY 2010 - ROMA (4)
JAMP DAY 2010 - ROMA (4)JAMP DAY 2010 - ROMA (4)
JAMP DAY 2010 - ROMA (4)
 

Viewers also liked

A manual for Ph.D dissertation
A manual for Ph.D dissertationA manual for Ph.D dissertation
A manual for Ph.D dissertationYONG ZHENG
 
Proposal Defense Power Point
Proposal Defense Power PointProposal Defense Power Point
Proposal Defense Power Pointjamathompson
 
My Thesis Defense Presentation
My Thesis Defense PresentationMy Thesis Defense Presentation
My Thesis Defense PresentationDavid Onoue
 
Powerpoint presentation M.A. Thesis Defence
Powerpoint presentation M.A. Thesis DefencePowerpoint presentation M.A. Thesis Defence
Powerpoint presentation M.A. Thesis DefenceCatie Chase
 
Dissertation oral defense presentation
Dissertation   oral defense presentationDissertation   oral defense presentation
Dissertation oral defense presentationDr. Naomi Mangatu
 
How to Defend your Thesis Proposal like a Professional
How to Defend your Thesis Proposal like a ProfessionalHow to Defend your Thesis Proposal like a Professional
How to Defend your Thesis Proposal like a ProfessionalMiriam College
 
La5 Programming688
La5 Programming688La5 Programming688
La5 Programming688Cma Mohd
 
June 2007 Seed Sampler
June 2007 Seed SamplerJune 2007 Seed Sampler
June 2007 Seed Samplermsainfo
 
об альтернативах коллокациям
об альтернативах коллокациямоб альтернативах коллокациям
об альтернативах коллокациямLidia Pivovarova
 
One backend multiple Screens
One backend multiple ScreensOne backend multiple Screens
One backend multiple ScreensMichael Chaize
 
04 извлечение информации
04 извлечение информации04 извлечение информации
04 извлечение информацииLidia Pivovarova
 
Funny Photo of kids
Funny Photo of kidsFunny Photo of kids
Funny Photo of kidsnonnon
 
Ooliinnguaq And Knud Peter
Ooliinnguaq And Knud PeterOoliinnguaq And Knud Peter
Ooliinnguaq And Knud Petereka
 
La3 Intranet
La3 IntranetLa3 Intranet
La3 IntranetCma Mohd
 
Михаил Александров. Индуктивное моделирование.
Михаил Александров. Индуктивное моделирование.Михаил Александров. Индуктивное моделирование.
Михаил Александров. Индуктивное моделирование.Lidia Pivovarova
 

Viewers also liked (20)

A manual for Ph.D dissertation
A manual for Ph.D dissertationA manual for Ph.D dissertation
A manual for Ph.D dissertation
 
Proposal Defense Power Point
Proposal Defense Power PointProposal Defense Power Point
Proposal Defense Power Point
 
My Thesis Defense Presentation
My Thesis Defense PresentationMy Thesis Defense Presentation
My Thesis Defense Presentation
 
Powerpoint presentation M.A. Thesis Defence
Powerpoint presentation M.A. Thesis DefencePowerpoint presentation M.A. Thesis Defence
Powerpoint presentation M.A. Thesis Defence
 
Dissertation oral defense presentation
Dissertation   oral defense presentationDissertation   oral defense presentation
Dissertation oral defense presentation
 
How to Defend your Thesis Proposal like a Professional
How to Defend your Thesis Proposal like a ProfessionalHow to Defend your Thesis Proposal like a Professional
How to Defend your Thesis Proposal like a Professional
 
La5 Programming688
La5 Programming688La5 Programming688
La5 Programming688
 
PLC-2007_Intro
PLC-2007_IntroPLC-2007_Intro
PLC-2007_Intro
 
June 2007 Seed Sampler
June 2007 Seed SamplerJune 2007 Seed Sampler
June 2007 Seed Sampler
 
Assignment 2
Assignment 2Assignment 2
Assignment 2
 
大家行04
大家行04大家行04
大家行04
 
Multumire603
Multumire603Multumire603
Multumire603
 
Milieu
MilieuMilieu
Milieu
 
об альтернативах коллокациям
об альтернативах коллокациямоб альтернативах коллокациям
об альтернативах коллокациям
 
One backend multiple Screens
One backend multiple ScreensOne backend multiple Screens
One backend multiple Screens
 
04 извлечение информации
04 извлечение информации04 извлечение информации
04 извлечение информации
 
Funny Photo of kids
Funny Photo of kidsFunny Photo of kids
Funny Photo of kids
 
Ooliinnguaq And Knud Peter
Ooliinnguaq And Knud PeterOoliinnguaq And Knud Peter
Ooliinnguaq And Knud Peter
 
La3 Intranet
La3 IntranetLa3 Intranet
La3 Intranet
 
Михаил Александров. Индуктивное моделирование.
Михаил Александров. Индуктивное моделирование.Михаил Александров. Индуктивное моделирование.
Михаил Александров. Индуктивное моделирование.
 

Similar to Pycon Jungle

Web Performance Optimization
Web Performance OptimizationWeb Performance Optimization
Web Performance OptimizationAlessandro Martin
 
Non Conventional Android Programming (Italiano)
Non Conventional Android Programming (Italiano)Non Conventional Android Programming (Italiano)
Non Conventional Android Programming (Italiano)Davide Cerbo
 
JSP Tag Library
JSP Tag LibraryJSP Tag Library
JSP Tag Libraryjgiudici
 
JSP Tag Library
JSP Tag LibraryJSP Tag Library
JSP Tag Libraryjgiudici
 
JSP Tag Library
JSP Tag LibraryJSP Tag Library
JSP Tag Libraryjgiudici
 
Primo Incontro Con Scala
Primo Incontro Con ScalaPrimo Incontro Con Scala
Primo Incontro Con ScalaFranco Lombardo
 
Introduzione a..django
Introduzione a..djangoIntroduzione a..django
Introduzione a..djangoLuca Forzutti
 
Introduzione a jQuery
Introduzione a jQueryIntroduzione a jQuery
Introduzione a jQuerySandro Marcon
 
jQuery e i suoi plugin
jQuery e i suoi pluginjQuery e i suoi plugin
jQuery e i suoi pluginPasquale Puzio
 
04 Tapestry5 In Action Pratica
04   Tapestry5 In Action   Pratica04   Tapestry5 In Action   Pratica
04 Tapestry5 In Action Praticabobpuley
 
Effective Code Transformations in C++
Effective Code Transformations in C++Effective Code Transformations in C++
Effective Code Transformations in C++Marco Arena
 
Sviluppare estensioni per google chrome
Sviluppare estensioni per google chromeSviluppare estensioni per google chrome
Sviluppare estensioni per google chromeMarco Vito Moscaritolo
 

Similar to Pycon Jungle (20)

Web Performance Optimization
Web Performance OptimizationWeb Performance Optimization
Web Performance Optimization
 
Lezione JSP database Crud
Lezione JSP database CrudLezione JSP database Crud
Lezione JSP database Crud
 
Non Conventional Android Programming (Italiano)
Non Conventional Android Programming (Italiano)Non Conventional Android Programming (Italiano)
Non Conventional Android Programming (Italiano)
 
Lezione js pdatabasecrudterzaparte
Lezione js pdatabasecrudterzaparteLezione js pdatabasecrudterzaparte
Lezione js pdatabasecrudterzaparte
 
JSP Tag Library
JSP Tag LibraryJSP Tag Library
JSP Tag Library
 
JSP Tag Library
JSP Tag LibraryJSP Tag Library
JSP Tag Library
 
JSP Tag Library
JSP Tag LibraryJSP Tag Library
JSP Tag Library
 
iContract
iContractiContract
iContract
 
Dojo nuovo look alle vostre applicazioni web Domino
Dojo nuovo look alle vostre applicazioni web DominoDojo nuovo look alle vostre applicazioni web Domino
Dojo nuovo look alle vostre applicazioni web Domino
 
Riepilogo Java C/C++
Riepilogo Java C/C++Riepilogo Java C/C++
Riepilogo Java C/C++
 
eZ publish - Extension
eZ publish - ExtensioneZ publish - Extension
eZ publish - Extension
 
Primo Incontro Con Scala
Primo Incontro Con ScalaPrimo Incontro Con Scala
Primo Incontro Con Scala
 
Introduzione a..django
Introduzione a..djangoIntroduzione a..django
Introduzione a..django
 
Introduzione a jQuery
Introduzione a jQueryIntroduzione a jQuery
Introduzione a jQuery
 
Sinfonia in Domino RE - Integrazione Symphony e Lotus Notes 8.x
Sinfonia in Domino RE - Integrazione Symphony e Lotus Notes 8.xSinfonia in Domino RE - Integrazione Symphony e Lotus Notes 8.x
Sinfonia in Domino RE - Integrazione Symphony e Lotus Notes 8.x
 
jQuery e i suoi plugin
jQuery e i suoi pluginjQuery e i suoi plugin
jQuery e i suoi plugin
 
Rubynetto
RubynettoRubynetto
Rubynetto
 
04 Tapestry5 In Action Pratica
04   Tapestry5 In Action   Pratica04   Tapestry5 In Action   Pratica
04 Tapestry5 In Action Pratica
 
Effective Code Transformations in C++
Effective Code Transformations in C++Effective Code Transformations in C++
Effective Code Transformations in C++
 
Sviluppare estensioni per google chrome
Sviluppare estensioni per google chromeSviluppare estensioni per google chrome
Sviluppare estensioni per google chrome
 

Pycon Jungle

  • 1. Django a modo mio: makosafare + Alessandro Dentella
  • 2.
  • 3. Perchè sostituire i template? Una questione di pigrizia...
  • 4.
  • 5.
  • 6. definizione di una form #- general data user email first_name last_name #- bith data birth_date T=time city state -- s=Add
  • 7.
  • 9.
  • 10. urls.py from django.conf.urls.defaults import * urlpatterns = patterns('', (r'^admin/', include('django.contrib.admin.urls.admin')), (r'^jobs/', include('djproject.jobs.urls')), ) Nel progetto: Nella application
  • 11.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18. Ancora field - widgets Impariamo dai doctests >>> w = TextInput() >>> w.render('email', '') u'<input type=&quot;text&quot; name=&quot;email&quot;> >>> import datetime >>> f = DateField() >>> f.clean(datetime.date(2006, 10, 25)) datetime.date(2006, 10, 25) >>> f.clean('10/25/2006') datetime.date(2006, 10, 25)
  • 19.
  • 20. Creare la form: via Form e metaclassi >>> class Person(Form): ... first_name = CharField() ... last_name = CharField() ... birthday = DateField() Pass a dictionary to a Form's __init__(). >>> p = Person({'first_name': u'John', 'last_name': u'Lennon', 'birthday': u'1940-10-9'}) >>> p.is_bound True >>> p.errors {} >>> p.is_valid() True >>> p.errors.as_ul() u'' >>> p.errors.as_text() u'' >>> p.clean_data {'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} >>> print p['first_name'] <input type=&quot;text&quot; name=&quot;first_name&quot; value=&quot;John&quot; id=&quot;id_first_name&quot; />
  • 21. Form
  • 22. template <%! from jungle.templatetags.jungle_tags import offset_txt %> L'utente ${ticket.submitter} ha aperto il ticket # ${ticket.id} per il tuo progetto ' ${ticket.project.name} ': ID: ${ticket.id} Titolo: ${ticket.title} Descrizione: ${offset_txt(ticket.description)} Priorita': ${ticket.get_priority_display()} Il mail ti è inviato in qualità di ${title} ---------------------------------------------------------------- Puoi vedere questo ticket qui: ${&quot;%s/ticket/ticket/%s/&quot; % (jun.host_url(), ticket.id)}
  • 23. sintesi del percorso con form aggiunta dati GET: /ticket/ticket/add/ urls.py view creazione form per generare html template response POST: /ticket/ticket/add/ + {'a':'b'} urls.py view creazione form per usare dati redirect response
  • 24.
  • 25. concretamente <%def name=&quot;layout()&quot;> city state <%/def> ${forms.mako_table_data(context, layout, obj, ) }
  • 26. basta chiacchiere! Ora vai al serverino di sviluppo e mostra qualcosa dal vivo. Per chi segue da casa: http://jungle.thundersystems.it Non dimenticare i manager del modello!
  • 27. object_list from jungle.views.fast_search import search2 filter_cnd, order_by, form = search2( request, model, order_by=order_by, **kw) if filter_cnd: queryset = queryset.filter(**filter_cnd) if order_by: queryset = queryset.order_by(order_by) hai dimenticato i manager, vero?
  • 28. debug: pdb ieri abbiamo visto come WSGI permetta di entrare a debuggare ciò che succede ed intervenire. Usando il server di sviluppo di django possiamo usare pdb.set_trace() in qualunque punto ed otteniamo una sessione interattiva!!!
  • 29.
  • 30.
  • 31.