NDjango: Getting cozy with ASP.MVC
Monday, August 2nd, 2010Almost there. Just a few more touches, tests, spelling corrections... No, really, the new NDjango editor I was working on for some time now is almost ready. The major improvements over the existing one are in the overall usability as well as ASP.NET MVC compatibility. Here is a brief rundown on what's coming:
Code Completion for strongly typed models
Currently NDjango editor supports code completion for tag and filter names as well as for a few other syntax elements. With the new version two more elements are added to the list: block names and variables.
Code completion for variables works everywhere a variable reference can exist and shows a list of all variables available in the context. The code completion dropdown includes global (for the template) variables provided by the view engine as well as context based variables introduced by the django tags, i.e. forloop variable inside the for tag. A new tag <% model [Name:Type]... %> can be to used introduce additional global variables. The specified name will be shown on the code completion list.
Typing '.' after the name of a variable triggers another code completion dialog with a list of members/properties as defined by the variable type. This feature combined with the ability to provide the model type in the model tag provides great support for strongly typed models.
The list of predefined global variables depends on the project type. For Bistro projects the list will include all resources provided by the Bistro controllers. For ASP.NET MVC integration the context will only include the "Session" variable and the "Model" variable for strongly typed views (see below ASP.NET MVC integration)
Block names code completion dialog in the block tag shows a list of blocks available for overriding. The list includes names of the blocks defined in parent templates.
Add New Django View wizard
Add new view wizard simplifies creating new templates by providing dialogs to select base template, model type, and blocks to override
ASP.NET MVC integration
There are quiet a few changes in the ASP.NET MVC integration. The overriding goal is to make integration as seamless as possible. Specfically:
- Django Views can be mixed and matched with WebForm views or any other types of views
- Full support for Areas
- HtmlHelpers can be used from inside of Django views
- Views with strongly typed models provide full blown code completion support
- New DjangoViewEngine constructor simplifies working with custom tag libraries
- Session global variable provides direct access to the session object from the views
- Extensive samples provide a good starting point for writing your own views/tags/filters
Sample Code
A new ASP.NET MVC sample project will be included in the shipment. The project is an extension of the stock ASP.NET MVC sample project created by the "Create a New ASP.NET MVC2 Web Application" wizard. In this project a new tab called "Django" is added to the menu. Also for the register new user view the aspx file is superceded by a django template.
This project can be used as guidance in respect to a few aspects of using NDjango view engine:
- Using Django inheritance in lieu of master pages
- Accessing context values with Django variables
- Setting up NDjango to use custom tag libraries
- Using HtmlHelpers from within Django templates
- Using ascx controls from Django templates
Also included in the shipment is a Sample Library project. This project is a tag library with several tags providing access to various HtmlHelpers. These tags were written for the ASP.NET MVC sample project. They also can be used as starting point for developing your own custom tags.
I hope I did not miss anything. I hope I will be able to wrap it all up over the next week or so. I am also looking into the ASP.NET MVC3 and will include MVC3 integration as well if it will not get in the way too much.
See you soon.