2015.03.10 – A Roundabout Way to the Answer

So the issue I’m having with Django is that I have to display some data in a template that is already rendered. I have macros in a template that do some of the processing and then my new template extends from this parent template. The problem is that when a user is not logged in, I need to send a request to the database to get the events and then display them in the page but the way it stands is the entire page would be re-rendered so things like the header and sidebar would be duplicated. Not good. Peter suggested I use Django includes as a last resort and everything I read also said that includes are not the best solution so I was trying to figure out a different way of solving this. I searched and searched and read through a bunch of Django books in Safari Books Online (thank you Mozilla!) but wasn’t getting anywhere.

Finally I asked Peter if he could help me out when he had time. He had time right then so we had a Vidyo conference. Peter decided to just live code through the issue and talk it over as he did so. He began with our assumption that we would try to avoid using includes so he made a helper function and pulled one of the macros out of the template. When he tested it he got various errors so fixed them as they came up. He had to add some attributes, decorators, and some imports. One of the imports was causing a circular import though so he had to put it inside of the helper function and that just didn’t seem right. He then gutted the helper function to it’s most basic needs by just passing the context but that was just an include so it was determined that an include was in fact the best way to go. Whew! The long way around to get there for sure but it was fantastic to watch his problem solving process. I’ll get there someday.

With that solved I had a path ahead so I got back to work on things until I had to head home. Alena was dropping the kids off early so she could teach a class and Dave could go to a job interview. On my way home I stopped in to a new yoga studio to ask if it was good for beginners and ended up signing up for a two week trial. Alice said she would go as well so now I’m committed! For two weeks anyway.

The kids showed up so we played and watched movies while Wayne made spaghetti, asparagus, and carrots. Alice made a salad and brought the first edible flowers of the season from our gardens. I love them.

Tonight for dinner night we had the six of us, Lauren, Sean, Jason, Alice, John, Spencer, Glenn, Dave, Alena, Tiberias, Rialla, and Anya.

Today I learned how to write a helper function even though I don’t need to use one at this point.