User Tools

Site Tools


devel:blueprints:refactor-mod-python-to-django

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
devel:blueprints:refactor-mod-python-to-django [2011/03/09 08:59]
morten
devel:blueprints:refactor-mod-python-to-django [2012/10/03 08:29] (current)
morten old revision restored
Line 26: Line 26:
   * Deconstruct the URI dispatcher into a Django urlconfig.   * Deconstruct the URI dispatcher into a Django urlconfig.
   * Refactor each of the newly created view functions:   * Refactor each of the newly created view functions:
-    * Usage of mod_python'​s ''​FieldStorage''​ class to extract GET/POST parameters must be refactored to use the GET, POST or REQUEST attributes of the incoming Django request structure.+    * Usage of mod_python'​s ''​FieldStorage''​ class, or NAV's ''​nav.web.URI.URI''​ class, ​to extract GET/POST parameters must be refactored to use the GET, POST or REQUEST attributes of the incoming Django request structure.
     * Create a ''​HttpResponse''​ object, feeding it the output of the template'​s ''​respond()''​ method, and return this response object instead of an ''​apache.OK''​.     * Create a ''​HttpResponse''​ object, feeding it the output of the template'​s ''​respond()''​ method, and return this response object instead of an ''​apache.OK''​.
  
Line 42: Line 42:
 </​code>​ </​code>​
 The ''​HttpResponse''​ can also adjust the response code and the content-type of the output (which defaults to ''​text/​html''​). Django also has other ''​HttpResponse''​ subclasses for returning specific response codes, such as ''​Http404''​. The ''​HttpResponse''​ can also adjust the response code and the content-type of the output (which defaults to ''​text/​html''​). Django also has other ''​HttpResponse''​ subclasses for returning specific response codes, such as ''​Http404''​.
 +
 +==== Gotchas ====
 +  * A legacy handler'​s URLs may already have been configured with view names in the ''​nav.django.urls.urlbuilder''​ module, in order for Django apps and templates to easily create reverse links to these systems. ​ These config items must be moved in to your new urlconfig.
 +
 +===== Example =====
 +
 +Examine these changesets:
 +  * [[http://​nav.uninett.no/​hg/​default/​rev/​61a95ac14564|Refactoring the Netmap backend handler]]
 +  * [[http://​nav.uninett.no/​hg/​default/​rev/​1409829b73bc|Refactoring the sortedStats handler]]
 +
 +:!: It's probably better to portion out your refactoring in multiple changesets which make your changes easier to follow. That's one of the things DVCS'​es are for.
 +
devel/blueprints/refactor-mod-python-to-django.1299661160.txt.gz ยท Last modified: 2011/03/09 08:59 by morten