Skip to content

Instantly share code, notes, and snippets.

View drhoden's full-sized avatar

Daniel Rhoden drhoden

View GitHub Profile
@drhoden
drhoden / getContext.py
Last active December 7, 2023 16:18
Obtain context from within Django custom template filter
"""
What if you suddenly need to have access to the context object from within
certain filters, and it would be costly to alter its syntax? Well, that
just happend to me. Here is my solution.
"""
def get_context(max_depth=4):
"""A simple (and perhaps dangerous) way of obtaining a context. Keep
in mind these shortcomings:
1. There is no guarantee this returns the right 'context'.
@drhoden
drhoden / vi-global-search-replace
Created February 13, 2014 22:30
vi global search and replace
: 1,$s/old/new/g