(An experience report from Yorie Nakayama)
If you are developing with python on Django, or on any frameworks that
employ the MVC (Model-View-Controller) paradigm, you might come across
whether there is a way to easily visualize all the models and their
dependency relationships in your application as a diagram. Models are
central to most applications using MVC, and being able to glance at the
structure of models and their relationships to each other greatly helps
any developer beginning to hack on the codebase.
When I worked with Reviewboard, a Django-based web app for doing code
reviews, for my UCOSP, one of the first things I did was to generate a
UML diagram of the models in the project using an extension package for
Django called django-extensions. The diagram would let the students, who
are new to the project, to see the overall picture of the models, and
also let the mentors easily explain how some models are related to each
This post will provide a step-by-step instruction on generating a UML
diagram of a Django application using django-extensions. Similar tools
also exist for other MVC frameworks, such as railroady gem for Ruby on
Rails, or phuml for PHP (not limited to CodeIgniter).
1. Install Dependencies.
For python, you need to install either pydot or pygraphviz as a python
interface of the graph visualization library called graphviz. Either
will be fine as far as django-extensions is concerned. I went with pydot
because I had a trouble installing pygraphviz. If you choose to go with
pygraphviz, you can ignore this step and resume from step 2 after
pip install pyparsing==1.5.7
pip install graphviz
pip install pydot
The version is specified on pyparsing installation because pydot is not
compatible with newer (>=2.x.x) versions of pyparsing. I recommend that
graphviz is installed before pydot to avoid an issue where pydot is not
able to find graphviz executable. A similar installation issue may also
occur with pygraphviz.
2. Install django-extensions.
Django-extensions provides various tools that could help development of
Django applications such as enhanced shell, or UML diagram generation.
pip install django-extensions
3. Enable django-extensions in your project.
Under your Django project directory, open the file setting.py with a
text editor. Within the settings, you should find a python list called
Append ‘django_extensions’ to the list and save. Then you can use the
functionalities that django-extensions provides.
4. Generate the UML diagram.
On a command shell, go to the Django project directory, and execute the
following command to generate your diagram of all models in the project.
python manage.py graph_models -a -o myapp_models.png
The -a flag specifies to include all apps listed in INSTALLED_APPS for
diagram generation. The output path is relative to the project root
If you decide that your project does not need django-extensions, you can
simply remove ‘django_extensions’ from INSTALLED_APPS in settings.py.
With a UML diagram for your models, you can easily see the overall
picture of the data organization in your application. Hopefully this
diagram could help a new member on a Django project to find where to
start with the development.
— Yorie Nakayama
As we prepare for the next group of students who will start in January, we are seeing some turnover in the project offerings for UCOSP, so I’d like to welcome the newcomers and thank the project mentors from the past term.
The project mentors for Waterbear, CodeIgniter, and Mylyn are all based in Vancouver which makes it more difficult to attend a code sprint in Toronto. It has been great working with Dethe, James and Sam, and I hope we will have a chance to work with you again in the future!
We are also saying goodbye a long-term project: Phonegap. Tim Windsor has moved to a different job and is not able to supervise students this term. Tim has been a terrific mentor over several years, and it would be a great pleasure to work with him again.
We are welcoming two new projects this term, both from Mozilla: Jupyter Notebooks for Data Analysis, and Code Coverage Explorer. I’m excited to see what students will do on both of these projects.
Xing Zeng from UToronto who has been working on the CodeIgniter project checks in on this term.
I am working on the CodeIgniter Project. More specifically, our team is spending most of our time in developing Netbeans plugin for CodeIgniter developers.
CodeIgniter is a light-weight PHP framework, loosely based on the popular Model-View-Controller development pattern. It is the 4th most widely-used PHP framework throughout the Internet. Despite this, there has been no IDE plugin for it on any major IDE, where lots of other PHP frameworks, including the famous Symphony and the not so famous Nette2, all have IDE plugins specifically designed to work with the features of their library. That’s the reason why our team decided to work on it.
The first platform we choose to implement our plugin was Netbeans. It is a fast and flexible IDE and it is among the preferred choice of many CodeIgniter developers as well as the IDE being taught in the CodeIgniter class at BCIT. It has tons of libraries and APIs for you to develop plugins conveniently to work with Netbeans. Since Netbeans was programmed in Java, our Plugin is also written in Java, created in Netbeans IDE as a Netbeans Module Project. Some other supplementary files were written in PHP.
This is the first time I have ever worked on an open source project as well as the first time I ever started working on an open source project from the ground up. We use Github as our major tool for issue tracking and source control, just like a lot of other open source libraries including CodeIgniter itself. So I really feel excited about this golden opportunity, and I do feel I learn something from it. The following are two examples of what I have learned from participating in this project.
The first target I set was to implement a view navigation functionality. It is a fairly easy task since Netbeans has already provided you the interface HyperlinkProviderExt for you to implement. So I approach this naively at first, directly go into the package of code navigation to do all my coding work. I did kind of realize that this is not the correct way at the beginning of implementing a somehow complicated software, as some of my functionality in parsing Hyperlink and retrieving files may also be required by other parts of the program. But I did not have a chance to think about it carefully until I have decided how am I supposed to integrate the interface in HyperlinkProviderExt with the functionality I want. This turn out to be a problem later, when one of my team members came to me and ask me how to tokenize the PHP file, which is a functionality I have implemented after I finished my code. The result of not having a consensus prior to working on the code is a minor refactoring required in my code to make the system work and a major one is still ongoing for both my package and the shared package to make the code more clear and robust.
Then I switched to working on the auto-completion functionality. For this part, I realized that learning from other open source projects on Netbeans IDE Plugin is extremely useful, which is also a major reason why people promote open source. This is even more essential in my case since, for some reason I don’t know, Netbeans APIs does not have javadoc with it and it takes so much time to manually go over its online documentation. So, I looked into some other open source projects, including the source code for the Yii Plugin, wojciech-holisz plugin, as well as the Sprint Autocompletion file and the structure of the Zend Plugin. They gave me lots of help on providing me a basic idea of how the structure of my CompletionProvider class could be and showing me what kind of API calls as well as pre-defined object would be convenient for me to use. This allowed me to finish the coding of this part early and understand how each part could work together.
In conclusion, I feel like working for CodeIgniter is a really great opportunity and I do feel I learned a lot from it.