views:

119

answers:

1

In my application, I am sending periodic cron and background task requests to refresh the cache of pages. While sending a force_refresh kwarg from the view is easy, there's no apparent way to send the force_refresh kwarg to methods being accessed from the template. There are plenty of these I'm using, and it would just make things more complex to start calling all these methods from the view.

So I've been trying to overwrite the template render method so that I pass in the force_refresh kwarg whenever a method is being accessed, if the given response is for a background task request.

I realize that it might simply lead to unexpected problems to add this kwarg to all methods being called, and a try/except ArgumentError block wouldn't exactly be a robust solution, if you have any recommendations about a better way to handle this (hopefully besides accessing each of these methods from the view!), it would be useful to hear them.

A: 

Sorry, but your use case is precisely what the view function is for.

In the view function you gather all the data. From this you create a dictionary of the latest data which will be used by the template.

All logic goes in the view. The template has minimal processing.

S.Lott
I've accepted this for now, although I'd like to see at least hypothetically how to override render. I've also refactored to call this method from the view, and it's gotten me to do some more refactorings I should have done a while ago.
jamtoday
@jamtoday: Don't override render. The person who has to maintain this will never figure out your non-standard approach.
S.Lott