<s> from django import template <EOL> from classytags . core import Tag , Options <EOL> from classytags . arguments import Argument , MultiKeywordArgument <EOL> register = template . Library ( ) <EOL> class VariationsTag ( Tag ) : <EOL> name = '<STR_LIT>' <EOL> options = Options ( <EOL> Argument ( '<STR_LIT>' ) , <EOL> MultiKeywordArgument ( <EOL> '<STR_LIT>' , <EOL> required = False <EOL> ) , <EOL> blocks = [ ( '<STR_LIT>' , '<STR_LIT>' ) ] , <EOL> ) <EOL> def render_tag ( self , context , product , kwargs , nodelist ) : <EOL> variations = None <EOL> grouped = kwargs . pop ( '<STR_LIT>' , None ) <EOL> if variations is None : <EOL> variations = product . get_variations ( ) <EOL> if grouped : <EOL> variations = variations . group ( ) <EOL> elif grouped is None : <EOL> grouped_variations = variations . group ( ) <EOL> if grouped_variations : <EOL> grouped = True <EOL> variations = grouped_variations <EOL> context . push ( ) <EOL> context [ '<STR_LIT>' ] = variations <EOL> context [ '<STR_LIT>' ] = grouped <EOL> output = nodelist . render ( context ) <EOL> context . pop ( ) <EOL> return output <EOL> register . tag ( VariationsTag ) </s>
