Last active
December 11, 2015 06:08
-
-
Save starsinmypockets/4556934 to your computer and use it in GitHub Desktop.
Pass context variables to template tags.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import template | |
import main.models # @@TODO this might be a reason to put frame components in a separate file some day | |
import logging | |
logger = logging.getLogger(__name__) | |
register = template.Library() | |
@register.tag(name="getradiomagic") | |
def getradiomagic(parser, token): | |
tag, category = token.split_contents() | |
return MagicNode(category) | |
class MagicNode(template.Node): | |
def __init__(self, category): | |
self.new_category = template.Variable(category) | |
def render(self, context): | |
return self.new_category.resolve(context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load getradiomagic %} | |
{% block magicradio %} | |
{% if not nolabel %} | |
<label for="{{ field.id }}" {% if field.required %}class="required"{% endif %}> {{ field.label }} </label> | |
{% endif %} | |
{% for option_value, option_label in field.field.choices %} | |
<input type="radio" name="{{ option_value }}" value=""{% if field.value == option_value|safe %}selected="selected"{% endif %}/> | |
<label>{{ option_label }}</label> | |
<span>{% getradiomagic field.name %}</span> | |
{% endfor %} | |
{{ field.help_text }} | |
{% endblock %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment