#2 World of USO – Code Refactoring

Hello again,

Over the past two weeks I’ve been working on the first objective of the project (refactoring views from games module). Last night I was able to accomplish it and I also started working on the second milestone, which consists of refactoring views from the interface module.

I gained some experience with class-based views and I can proudly say that I’m pretty confident using ListView, DetailView and View. The thing I like most at the Django project is that it’s very well documented. Therefore, I was able to find the method flowchart for each of those classes. It’s very important to know which method gets called and when.

Yesterday I stumbled upon a tricky view. After refactoring it, some features stopped working, such as displaying a message after a spell is bought. It crossed my mind to ask for help on the #django freenode channel. I was surprised that a bunch of people were willing to share their knowledge with me. They gave me some valuable suggestions. Eventually, I managed to fix the message displaying issue with django messages framework. They did exactly what I needed: store a message and pass it to the next view.

Another problem was paginating the view’s results. It had a back end implementation for it, but it lacked the front end part. I created a template for paginating those results and I rewrote the back end using the much simpler class-based view. It was as easy as assigning a number to the the class’ attribute paginate_by.

See you next post!

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>