<s> from django import template <EOL> from physical . models import EngineType , Environment , Plan <EOL> register = template . Library ( ) <EOL> @ register . inclusion_tag ( '<STR_LIT>' ) <EOL> def render_menu ( ) : <EOL> data_engines = [ ] <EOL> for engine_type in EngineType . objects . all ( ) : <EOL> data_engine = { <EOL> '<STR_LIT:name>' : engine_type . name , <EOL> '<STR_LIT>' : [ ] , <EOL> } <EOL> for environment in Environment . objects . filter ( plan__in = Plan . objects . filter ( engine__engine_type = engine_type ) ) . distinct ( ) : <EOL> data_environment = { <EOL> '<STR_LIT:id>' : environment . id , <EOL> '<STR_LIT:name>' : environment . name , <EOL> } <EOL> data_engine [ '<STR_LIT>' ] . append ( data_environment ) <EOL> if data_engine [ '<STR_LIT>' ] : <EOL> data_engines . append ( data_engine ) <EOL> context = { <EOL> '<STR_LIT>' : data_engines <EOL> } <EOL> return context </s>
